| 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, render, waitFor} from '@testing-library/react'; |
| b69ab31 | | | 9 | import userEvent from '@testing-library/user-event'; |
| b69ab31 | | | 10 | import * as utils from 'shared/utils'; |
| b69ab31 | | | 11 | import App from '../../App'; |
| b69ab31 | | | 12 | import {CommitInfoTestUtils, CommitTreeListTestUtils} from '../../testQueries'; |
| b69ab31 | | | 13 | import { |
| b69ab31 | | | 14 | COMMIT, |
| b69ab31 | | | 15 | expectMessageSentToServer, |
| b69ab31 | | | 16 | getLastMessageOfTypeSentToServer, |
| b69ab31 | | | 17 | openCommitInfoSidebar, |
| b69ab31 | | | 18 | resetTestMessages, |
| b69ab31 | | | 19 | simulateCommits, |
| b69ab31 | | | 20 | simulateMessageFromServer, |
| b69ab31 | | | 21 | simulateUncommittedChangedFiles, |
| b69ab31 | | | 22 | } from '../../testUtils'; |
| b69ab31 | | | 23 | |
| b69ab31 | | | 24 | describe('AmendMessageOperation', () => { |
| b69ab31 | | | 25 | beforeEach(() => { |
| b69ab31 | | | 26 | resetTestMessages(); |
| b69ab31 | | | 27 | render(<App />); |
| b69ab31 | | | 28 | act(() => { |
| b69ab31 | | | 29 | simulateMessageFromServer({ |
| b69ab31 | | | 30 | type: 'repoInfo', |
| b69ab31 | | | 31 | info: { |
| b69ab31 | | | 32 | type: 'success', |
| b69ab31 | | | 33 | command: 'sl', |
| b69ab31 | | | 34 | repoRoot: '/path/to/testrepo', |
| b69ab31 | | | 35 | dotdir: '/path/to/testrepo/.sl', |
| b69ab31 | | | 36 | codeReviewSystem: {type: 'unknown'}, |
| b69ab31 | | | 37 | pullRequestDomain: undefined, |
| b69ab31 | | | 38 | preferredSubmitCommand: undefined, |
| b69ab31 | | | 39 | isEdenFs: false, |
| b69ab31 | | | 40 | }, |
| b69ab31 | | | 41 | }); |
| b69ab31 | | | 42 | expectMessageSentToServer({ |
| b69ab31 | | | 43 | type: 'subscribe', |
| b69ab31 | | | 44 | kind: 'smartlogCommits', |
| b69ab31 | | | 45 | subscriptionID: expect.anything(), |
| b69ab31 | | | 46 | }); |
| b69ab31 | | | 47 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 48 | value: [ |
| b69ab31 | | | 49 | {path: 'file1.txt', status: 'M'}, |
| b69ab31 | | | 50 | {path: 'file2.txt', status: 'A'}, |
| b69ab31 | | | 51 | {path: 'file3.txt', status: 'R'}, |
| b69ab31 | | | 52 | ], |
| b69ab31 | | | 53 | }); |
| b69ab31 | | | 54 | simulateCommits({ |
| b69ab31 | | | 55 | value: [ |
| b69ab31 | | | 56 | COMMIT('111111111111', 'Commit 1', '0', {phase: 'public'}), |
| b69ab31 | | | 57 | COMMIT('aaaaaaaaaaaa', 'Commit A', '1'), |
| b69ab31 | | | 58 | COMMIT('bbbbbbbbbbbb', 'Commit B', 'a', {isDot: true}), |
| b69ab31 | | | 59 | COMMIT('cccccccccccc', 'Commit C', 'b'), |
| b69ab31 | | | 60 | ], |
| b69ab31 | | | 61 | }); |
| b69ab31 | | | 62 | }); |
| b69ab31 | | | 63 | }); |
| b69ab31 | | | 64 | |
| b69ab31 | | | 65 | it('on error, restores edited commit message to try again', async () => { |
| b69ab31 | | | 66 | act(() => CommitInfoTestUtils.clickToSelectCommit('aaaaaaaaaaaa')); |
| b69ab31 | | | 67 | act(() => openCommitInfoSidebar()); |
| b69ab31 | | | 68 | act(() => { |
| b69ab31 | | | 69 | CommitInfoTestUtils.clickToEditTitle(); |
| b69ab31 | | | 70 | CommitInfoTestUtils.clickToEditDescription(); |
| b69ab31 | | | 71 | }); |
| b69ab31 | | | 72 | act(() => { |
| b69ab31 | | | 73 | const title = CommitInfoTestUtils.getTitleEditor(); |
| b69ab31 | | | 74 | userEvent.type(title, 'My Commit'); |
| b69ab31 | | | 75 | const desc = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 76 | userEvent.type(desc, 'My description'); |
| b69ab31 | | | 77 | }); |
| b69ab31 | | | 78 | |
| b69ab31 | | | 79 | act(() => { |
| b69ab31 | | | 80 | CommitInfoTestUtils.clickAmendMessageButton(); |
| b69ab31 | | | 81 | }); |
| b69ab31 | | | 82 | const message = await waitFor(() => |
| b69ab31 | | | 83 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 84 | ); |
| b69ab31 | | | 85 | const id = message.operation.id; |
| b69ab31 | | | 86 | |
| b69ab31 | | | 87 | CommitInfoTestUtils.expectIsNOTEditingTitle(); |
| b69ab31 | | | 88 | |
| b69ab31 | | | 89 | act(() => CommitInfoTestUtils.clickToSelectCommit('bbbbbbbbbbbb')); |
| b69ab31 | | | 90 | expect(CommitInfoTestUtils.withinCommitInfo().getByText('You are here')).toBeInTheDocument(); |
| b69ab31 | | | 91 | |
| b69ab31 | | | 92 | act(() => { |
| b69ab31 | | | 93 | simulateMessageFromServer({ |
| b69ab31 | | | 94 | type: 'operationProgress', |
| b69ab31 | | | 95 | kind: 'exit', |
| b69ab31 | | | 96 | exitCode: 1, |
| b69ab31 | | | 97 | id, |
| b69ab31 | | | 98 | timestamp: 0, |
| b69ab31 | | | 99 | }); |
| b69ab31 | | | 100 | }); |
| b69ab31 | | | 101 | |
| b69ab31 | | | 102 | waitFor(() => { |
| b69ab31 | | | 103 | expect( |
| b69ab31 | | | 104 | CommitInfoTestUtils.withinCommitInfo().getByText('You are here'), |
| b69ab31 | | | 105 | ).not.toBeInTheDocument(); |
| b69ab31 | | | 106 | CommitInfoTestUtils.expectIsEditingTitle(); |
| b69ab31 | | | 107 | const title = CommitInfoTestUtils.getTitleEditor(); |
| b69ab31 | | | 108 | expect(title).toHaveValue('My Commit'); |
| b69ab31 | | | 109 | CommitInfoTestUtils.expectIsEditingDescription(); |
| b69ab31 | | | 110 | const desc = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 111 | expect(desc).toHaveValue('My description'); |
| b69ab31 | | | 112 | }); |
| b69ab31 | | | 113 | }); |
| b69ab31 | | | 114 | |
| b69ab31 | | | 115 | it('if a previous command errors and metaedit is queued, the message is recovered', async () => { |
| b69ab31 | | | 116 | await CommitTreeListTestUtils.clickGoto('cccccccccccc'); |
| b69ab31 | | | 117 | expectMessageSentToServer({ |
| b69ab31 | | | 118 | type: 'runOperation', |
| b69ab31 | | | 119 | operation: expect.objectContaining({ |
| b69ab31 | | | 120 | args: expect.arrayContaining(['goto']), |
| b69ab31 | | | 121 | }), |
| b69ab31 | | | 122 | }); |
| b69ab31 | | | 123 | const gotoMessage = utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')); |
| b69ab31 | | | 124 | const gotoId = gotoMessage.operation.id; |
| b69ab31 | | | 125 | |
| b69ab31 | | | 126 | act(() => { |
| b69ab31 | | | 127 | simulateMessageFromServer({ |
| b69ab31 | | | 128 | type: 'operationProgress', |
| b69ab31 | | | 129 | kind: 'spawn', |
| b69ab31 | | | 130 | id: gotoId, |
| b69ab31 | | | 131 | queue: [], |
| b69ab31 | | | 132 | }); |
| b69ab31 | | | 133 | }); |
| b69ab31 | | | 134 | |
| b69ab31 | | | 135 | // then queue a metaedit |
| b69ab31 | | | 136 | act(() => CommitInfoTestUtils.clickToSelectCommit('aaaaaaaaaaaa')); |
| b69ab31 | | | 137 | act(() => openCommitInfoSidebar()); |
| b69ab31 | | | 138 | act(() => { |
| b69ab31 | | | 139 | CommitInfoTestUtils.clickToEditTitle(); |
| b69ab31 | | | 140 | CommitInfoTestUtils.clickToEditDescription(); |
| b69ab31 | | | 141 | }); |
| b69ab31 | | | 142 | act(() => { |
| b69ab31 | | | 143 | const title = CommitInfoTestUtils.getTitleEditor(); |
| b69ab31 | | | 144 | userEvent.type(title, 'My Commit'); |
| b69ab31 | | | 145 | const desc = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 146 | userEvent.type(desc, 'My description'); |
| b69ab31 | | | 147 | }); |
| b69ab31 | | | 148 | |
| b69ab31 | | | 149 | act(() => { |
| b69ab31 | | | 150 | CommitInfoTestUtils.clickAmendMessageButton(); |
| b69ab31 | | | 151 | }); |
| b69ab31 | | | 152 | await waitFor(() => { |
| b69ab31 | | | 153 | expectMessageSentToServer({ |
| b69ab31 | | | 154 | type: 'runOperation', |
| b69ab31 | | | 155 | operation: expect.objectContaining({ |
| b69ab31 | | | 156 | args: expect.arrayContaining(['metaedit']), |
| b69ab31 | | | 157 | }), |
| b69ab31 | | | 158 | }); |
| b69ab31 | | | 159 | }); |
| b69ab31 | | | 160 | const amendMessage = utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')); |
| b69ab31 | | | 161 | const amendMessageId = amendMessage.operation.id; |
| b69ab31 | | | 162 | |
| b69ab31 | | | 163 | act(() => { |
| b69ab31 | | | 164 | simulateMessageFromServer({ |
| b69ab31 | | | 165 | type: 'operationProgress', |
| b69ab31 | | | 166 | kind: 'queue', |
| b69ab31 | | | 167 | id: amendMessageId, |
| b69ab31 | | | 168 | queue: [amendMessageId], |
| b69ab31 | | | 169 | }); |
| b69ab31 | | | 170 | }); |
| b69ab31 | | | 171 | |
| b69ab31 | | | 172 | CommitInfoTestUtils.expectIsNOTEditingTitle(); |
| b69ab31 | | | 173 | |
| b69ab31 | | | 174 | act(() => CommitInfoTestUtils.clickToSelectCommit('bbbbbbbbbbbb')); |
| b69ab31 | | | 175 | |
| b69ab31 | | | 176 | // the goto fails |
| b69ab31 | | | 177 | act(() => { |
| b69ab31 | | | 178 | simulateMessageFromServer({ |
| b69ab31 | | | 179 | type: 'operationProgress', |
| b69ab31 | | | 180 | kind: 'exit', |
| b69ab31 | | | 181 | exitCode: 1, |
| b69ab31 | | | 182 | id: gotoId, |
| b69ab31 | | | 183 | timestamp: 0, |
| b69ab31 | | | 184 | }); |
| b69ab31 | | | 185 | }); |
| b69ab31 | | | 186 | |
| b69ab31 | | | 187 | // we recover the message |
| b69ab31 | | | 188 | await waitFor(() => { |
| b69ab31 | | | 189 | CommitInfoTestUtils.expectIsEditingTitle(); |
| b69ab31 | | | 190 | const title = CommitInfoTestUtils.getTitleEditor(); |
| b69ab31 | | | 191 | expect(title).toHaveValue('Commit AMy Commit'); |
| b69ab31 | | | 192 | CommitInfoTestUtils.expectIsEditingDescription(); |
| b69ab31 | | | 193 | const desc = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 194 | expect(desc.value).toContain('My description'); |
| b69ab31 | | | 195 | }); |
| b69ab31 | | | 196 | }); |
| b69ab31 | | | 197 | }); |