| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import {act, fireEvent, render, screen, waitFor} from '@testing-library/react'; |
| b69ab31 | | | 9 | import App from '../App'; |
| b69ab31 | | | 10 | import {mostRecentSubscriptionIds} from '../serverAPIState'; |
| b69ab31 | | | 11 | import { |
| b69ab31 | | | 12 | closeCommitInfoSidebar, |
| b69ab31 | | | 13 | COMMIT, |
| b69ab31 | | | 14 | expectMessageSentToServer, |
| b69ab31 | | | 15 | getLastMessageOfTypeSentToServer, |
| b69ab31 | | | 16 | resetTestMessages, |
| b69ab31 | | | 17 | simulateCommits, |
| b69ab31 | | | 18 | simulateMessageFromServer, |
| b69ab31 | | | 19 | simulateUncommittedChangedFiles, |
| b69ab31 | | | 20 | } from '../testUtils'; |
| b69ab31 | | | 21 | import {ConflictType} from '../types'; |
| b69ab31 | | | 22 | |
| b69ab31 | | | 23 | describe('CommitTreeList', () => { |
| b69ab31 | | | 24 | beforeEach(() => { |
| b69ab31 | | | 25 | resetTestMessages(); |
| b69ab31 | | | 26 | render(<App />); |
| b69ab31 | | | 27 | act(() => { |
| b69ab31 | | | 28 | closeCommitInfoSidebar(); |
| b69ab31 | | | 29 | simulateCommits({ |
| b69ab31 | | | 30 | value: [ |
| b69ab31 | | | 31 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 32 | COMMIT('a', 'My Commit', '1'), |
| b69ab31 | | | 33 | COMMIT('b', 'Another Commit', 'a', {isDot: true}), |
| b69ab31 | | | 34 | ], |
| b69ab31 | | | 35 | }); |
| b69ab31 | | | 36 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 37 | value: [ |
| b69ab31 | | | 38 | {path: 'src/file1.js', status: 'M'}, |
| b69ab31 | | | 39 | {path: 'src/file2.js', status: 'M'}, |
| b69ab31 | | | 40 | {path: 'src/file3.js', status: 'M'}, |
| b69ab31 | | | 41 | ], |
| b69ab31 | | | 42 | }); |
| b69ab31 | | | 43 | }); |
| b69ab31 | | | 44 | |
| b69ab31 | | | 45 | act(() => { |
| b69ab31 | | | 46 | expectMessageSentToServer({ |
| b69ab31 | | | 47 | type: 'subscribe', |
| b69ab31 | | | 48 | kind: 'mergeConflicts', |
| b69ab31 | | | 49 | subscriptionID: expect.anything(), |
| b69ab31 | | | 50 | }); |
| b69ab31 | | | 51 | simulateMessageFromServer({ |
| b69ab31 | | | 52 | type: 'subscriptionResult', |
| b69ab31 | | | 53 | kind: 'mergeConflicts', |
| b69ab31 | | | 54 | subscriptionID: mostRecentSubscriptionIds.mergeConflicts, |
| b69ab31 | | | 55 | data: { |
| b69ab31 | | | 56 | state: 'loading', |
| b69ab31 | | | 57 | }, |
| b69ab31 | | | 58 | }); |
| b69ab31 | | | 59 | }); |
| b69ab31 | | | 60 | }); |
| b69ab31 | | | 61 | |
| b69ab31 | | | 62 | it('renders merge conflicts spinner while loading', () => { |
| b69ab31 | | | 63 | expect(screen.getByTestId('merge-conflicts-spinner')).toBeInTheDocument(); |
| b69ab31 | | | 64 | }); |
| b69ab31 | | | 65 | |
| b69ab31 | | | 66 | describe('after conflicts load', () => { |
| b69ab31 | | | 67 | beforeEach(() => { |
| b69ab31 | | | 68 | act(() => { |
| b69ab31 | | | 69 | simulateMessageFromServer({ |
| b69ab31 | | | 70 | type: 'subscriptionResult', |
| b69ab31 | | | 71 | kind: 'mergeConflicts', |
| b69ab31 | | | 72 | subscriptionID: mostRecentSubscriptionIds.mergeConflicts, |
| b69ab31 | | | 73 | data: { |
| b69ab31 | | | 74 | state: 'loaded', |
| b69ab31 | | | 75 | command: 'rebase', |
| b69ab31 | | | 76 | toContinue: 'rebase --continue', |
| b69ab31 | | | 77 | toAbort: 'rebase --abort', |
| b69ab31 | | | 78 | files: [ |
| b69ab31 | | | 79 | {path: 'src/file2.js', status: 'U', conflictType: ConflictType.BothChanged}, |
| b69ab31 | | | 80 | {path: 'src/file3.js', status: 'Resolved', conflictType: ConflictType.BothChanged}, |
| b69ab31 | | | 81 | ], |
| b69ab31 | | | 82 | fetchStartTimestamp: 1, |
| b69ab31 | | | 83 | fetchCompletedTimestamp: 2, |
| b69ab31 | | | 84 | }, |
| b69ab31 | | | 85 | }); |
| b69ab31 | | | 86 | }); |
| b69ab31 | | | 87 | }); |
| b69ab31 | | | 88 | |
| b69ab31 | | | 89 | it('renders merge conflicts changes', () => { |
| b69ab31 | | | 90 | expect(screen.getByText('file2.js', {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 91 | expect(screen.getByText('file3.js', {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 92 | |
| b69ab31 | | | 93 | // uncommitted changes are not there |
| b69ab31 | | | 94 | expect(screen.queryByText('file1.js', {exact: false})).not.toBeInTheDocument(); |
| b69ab31 | | | 95 | }); |
| b69ab31 | | | 96 | |
| b69ab31 | | | 97 | it("doesn't allow continue until conflicts resolved", () => { |
| b69ab31 | | | 98 | expect( |
| b69ab31 | | | 99 | screen.queryByText('All Merge Conflicts Resolved', {exact: false}), |
| b69ab31 | | | 100 | ).not.toBeInTheDocument(); |
| b69ab31 | | | 101 | expect( |
| b69ab31 | | | 102 | screen.queryByText('Resolve conflicts to continue rebase', {exact: false}), |
| b69ab31 | | | 103 | ).toBeInTheDocument(); |
| b69ab31 | | | 104 | |
| b69ab31 | | | 105 | expect( |
| b69ab31 | | | 106 | (screen.queryByTestId('conflict-continue-button') as HTMLButtonElement).disabled, |
| b69ab31 | | | 107 | ).toEqual(true); |
| b69ab31 | | | 108 | |
| b69ab31 | | | 109 | act(() => { |
| b69ab31 | | | 110 | simulateMessageFromServer({ |
| b69ab31 | | | 111 | type: 'subscriptionResult', |
| b69ab31 | | | 112 | kind: 'mergeConflicts', |
| b69ab31 | | | 113 | subscriptionID: mostRecentSubscriptionIds.mergeConflicts, |
| b69ab31 | | | 114 | data: { |
| b69ab31 | | | 115 | state: 'loaded', |
| b69ab31 | | | 116 | command: 'rebase', |
| b69ab31 | | | 117 | toContinue: 'rebase --continue', |
| b69ab31 | | | 118 | toAbort: 'rebase --abort', |
| b69ab31 | | | 119 | files: [ |
| b69ab31 | | | 120 | {path: 'src/file2.js', status: 'Resolved', conflictType: ConflictType.BothChanged}, |
| b69ab31 | | | 121 | {path: 'src/file3.js', status: 'Resolved', conflictType: ConflictType.BothChanged}, |
| b69ab31 | | | 122 | ], |
| b69ab31 | | | 123 | fetchStartTimestamp: 1, |
| b69ab31 | | | 124 | fetchCompletedTimestamp: 2, |
| b69ab31 | | | 125 | }, |
| b69ab31 | | | 126 | }); |
| b69ab31 | | | 127 | }); |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | expect( |
| b69ab31 | | | 130 | screen.queryByText('All Merge Conflicts Resolved', {exact: false}), |
| b69ab31 | | | 131 | ).toBeInTheDocument(); |
| b69ab31 | | | 132 | expect( |
| b69ab31 | | | 133 | screen.queryByText('Resolve conflicts to continue rebase', {exact: false}), |
| b69ab31 | | | 134 | ).not.toBeInTheDocument(); |
| b69ab31 | | | 135 | |
| b69ab31 | | | 136 | expect((screen.queryByTestId('conflict-continue-button') as HTMLButtonElement).disabled).toBe( |
| b69ab31 | | | 137 | false, |
| b69ab31 | | | 138 | ); |
| b69ab31 | | | 139 | }); |
| b69ab31 | | | 140 | |
| b69ab31 | | | 141 | it('uses optimistic state to render resolved files', () => { |
| b69ab31 | | | 142 | const resolveButton = screen.getByTestId('file-action-resolve'); |
| b69ab31 | | | 143 | act(() => { |
| b69ab31 | | | 144 | fireEvent.click(resolveButton); |
| b69ab31 | | | 145 | }); |
| b69ab31 | | | 146 | // resolve button is no longer there |
| b69ab31 | | | 147 | expect(screen.queryByTestId('file-action-resolve')).not.toBeInTheDocument(); |
| b69ab31 | | | 148 | }); |
| b69ab31 | | | 149 | |
| b69ab31 | | | 150 | it('lets you continue when conflicts are optimistically resolved', () => { |
| b69ab31 | | | 151 | const resolveButton = screen.getByTestId('file-action-resolve'); |
| b69ab31 | | | 152 | act(() => { |
| b69ab31 | | | 153 | fireEvent.click(resolveButton); |
| b69ab31 | | | 154 | }); |
| b69ab31 | | | 155 | |
| b69ab31 | | | 156 | // continue is no longer disabled |
| b69ab31 | | | 157 | expect( |
| b69ab31 | | | 158 | (screen.queryByTestId('conflict-continue-button') as HTMLButtonElement).disabled, |
| b69ab31 | | | 159 | ).toEqual(false); |
| b69ab31 | | | 160 | }); |
| b69ab31 | | | 161 | |
| b69ab31 | | | 162 | it('disables continue button while running', async () => { |
| b69ab31 | | | 163 | const resolveButton = screen.getByTestId('file-action-resolve'); |
| b69ab31 | | | 164 | act(() => { |
| b69ab31 | | | 165 | fireEvent.click(resolveButton); |
| b69ab31 | | | 166 | }); |
| b69ab31 | | | 167 | const continueButton = screen.getByTestId('conflict-continue-button'); |
| b69ab31 | | | 168 | act(() => { |
| b69ab31 | | | 169 | fireEvent.click(continueButton); |
| b69ab31 | | | 170 | }); |
| b69ab31 | | | 171 | |
| b69ab31 | | | 172 | await waitFor(() => { |
| b69ab31 | | | 173 | expectMessageSentToServer({ |
| b69ab31 | | | 174 | type: 'runOperation', |
| b69ab31 | | | 175 | operation: expect.objectContaining({args: ['continue']}), |
| b69ab31 | | | 176 | }); |
| b69ab31 | | | 177 | }); |
| b69ab31 | | | 178 | |
| b69ab31 | | | 179 | const message = getLastMessageOfTypeSentToServer('runOperation'); |
| b69ab31 | | | 180 | |
| b69ab31 | | | 181 | act(() => { |
| b69ab31 | | | 182 | simulateMessageFromServer({ |
| b69ab31 | | | 183 | type: 'operationProgress', |
| b69ab31 | | | 184 | id: message!.operation.id, |
| b69ab31 | | | 185 | kind: 'spawn', |
| b69ab31 | | | 186 | queue: [], |
| b69ab31 | | | 187 | }); |
| b69ab31 | | | 188 | }); |
| b69ab31 | | | 189 | |
| b69ab31 | | | 190 | expect( |
| b69ab31 | | | 191 | (screen.queryByTestId('conflict-continue-button') as HTMLButtonElement).disabled, |
| b69ab31 | | | 192 | ).toEqual(true); |
| b69ab31 | | | 193 | |
| b69ab31 | | | 194 | // simulate continue finishing |
| b69ab31 | | | 195 | act(() => { |
| b69ab31 | | | 196 | simulateMessageFromServer({ |
| b69ab31 | | | 197 | type: 'operationProgress', |
| b69ab31 | | | 198 | kind: 'exit', |
| b69ab31 | | | 199 | exitCode: 0, |
| b69ab31 | | | 200 | id: 'foo', |
| b69ab31 | | | 201 | timestamp: 1234, |
| b69ab31 | | | 202 | }); |
| b69ab31 | | | 203 | }); |
| b69ab31 | | | 204 | |
| b69ab31 | | | 205 | // We will soon get the next set of merge conflicts as null. |
| b69ab31 | | | 206 | // In the mean time, after `continue` has run, we still disable the button. |
| b69ab31 | | | 207 | expect( |
| b69ab31 | | | 208 | (screen.queryByTestId('conflict-continue-button') as HTMLButtonElement).disabled, |
| b69ab31 | | | 209 | ).toEqual(true); |
| b69ab31 | | | 210 | |
| b69ab31 | | | 211 | act(() => { |
| b69ab31 | | | 212 | simulateMessageFromServer({ |
| b69ab31 | | | 213 | type: 'subscriptionResult', |
| b69ab31 | | | 214 | kind: 'mergeConflicts', |
| b69ab31 | | | 215 | subscriptionID: mostRecentSubscriptionIds.mergeConflicts, |
| b69ab31 | | | 216 | data: undefined, |
| b69ab31 | | | 217 | }); |
| b69ab31 | | | 218 | }); |
| b69ab31 | | | 219 | expect(screen.queryByTestId('conflict-continue-button')).not.toBeInTheDocument(); |
| b69ab31 | | | 220 | }); |
| b69ab31 | | | 221 | }); |
| b69ab31 | | | 222 | }); |