| 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 type {CodeReviewSystem} from '../types'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import {act, fireEvent, render, screen, waitFor} from '@testing-library/react'; |
| b69ab31 | | | 11 | import userEvent from '@testing-library/user-event'; |
| b69ab31 | | | 12 | import {nextTick} from 'shared/testUtils'; |
| b69ab31 | | | 13 | import * as utils from 'shared/utils'; |
| b69ab31 | | | 14 | import App from '../App'; |
| b69ab31 | | | 15 | import {CommitInfoTestUtils} from '../testQueries'; |
| b69ab31 | | | 16 | import { |
| b69ab31 | | | 17 | COMMIT, |
| b69ab31 | | | 18 | expectMessageNOTSentToServer, |
| b69ab31 | | | 19 | expectMessageSentToServer, |
| b69ab31 | | | 20 | fireMouseEvent, |
| b69ab31 | | | 21 | getLastMessageOfTypeSentToServer, |
| b69ab31 | | | 22 | resetTestMessages, |
| b69ab31 | | | 23 | simulateCommits, |
| b69ab31 | | | 24 | simulateMessageFromServer, |
| b69ab31 | | | 25 | simulateUncommittedChangedFiles, |
| b69ab31 | | | 26 | } from '../testUtils'; |
| b69ab31 | | | 27 | |
| b69ab31 | | | 28 | describe('Image upload inside TextArea ', () => { |
| b69ab31 | | | 29 | beforeEach(() => { |
| b69ab31 | | | 30 | resetTestMessages(); |
| b69ab31 | | | 31 | }); |
| b69ab31 | | | 32 | |
| b69ab31 | | | 33 | beforeEach(() => { |
| b69ab31 | | | 34 | render(<App />); |
| b69ab31 | | | 35 | act(() => { |
| b69ab31 | | | 36 | expectMessageSentToServer({ |
| b69ab31 | | | 37 | type: 'subscribe', |
| b69ab31 | | | 38 | kind: 'smartlogCommits', |
| b69ab31 | | | 39 | subscriptionID: expect.anything(), |
| b69ab31 | | | 40 | }); |
| b69ab31 | | | 41 | simulateCommits({ |
| b69ab31 | | | 42 | value: [ |
| b69ab31 | | | 43 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 44 | COMMIT('b', 'My Commit', '1'), |
| b69ab31 | | | 45 | COMMIT('a', 'My Commit', 'b', {isDot: true}), |
| b69ab31 | | | 46 | ], |
| b69ab31 | | | 47 | }); |
| b69ab31 | | | 48 | }); |
| b69ab31 | | | 49 | act(() => { |
| b69ab31 | | | 50 | CommitInfoTestUtils.clickToEditTitle(); |
| b69ab31 | | | 51 | CommitInfoTestUtils.clickToEditDescription(); |
| b69ab31 | | | 52 | }); |
| b69ab31 | | | 53 | }); |
| b69ab31 | | | 54 | |
| b69ab31 | | | 55 | const mockFile = new File(['Hello'], 'file.png', {type: 'image/png'}); |
| b69ab31 | | | 56 | const mockFileContentInBase64 = btoa('Hello'); // SGVsbG8= |
| b69ab31 | | | 57 | |
| b69ab31 | | | 58 | const dataTransfer = { |
| b69ab31 | | | 59 | files: [mockFile] as unknown as FileList, |
| b69ab31 | | | 60 | } as DataTransfer; |
| b69ab31 | | | 61 | |
| b69ab31 | | | 62 | describe('Drag and drop image', () => { |
| b69ab31 | | | 63 | it('renders highlight while dragging image', () => { |
| b69ab31 | | | 64 | const textarea = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 65 | |
| b69ab31 | | | 66 | act(() => void fireMouseEvent('dragenter', textarea, 0, 0, {dataTransfer})); |
| b69ab31 | | | 67 | expect(document.querySelector('.hovering-to-drop')).not.toBeNull(); |
| b69ab31 | | | 68 | act(() => void fireMouseEvent('dragleave', textarea, 0, 0, {dataTransfer})); |
| b69ab31 | | | 69 | expect(document.querySelector('.hovering-to-drop')).toBeNull(); |
| b69ab31 | | | 70 | }); |
| b69ab31 | | | 71 | |
| b69ab31 | | | 72 | it('does not try to upload other things being dragged', () => { |
| b69ab31 | | | 73 | const textarea = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 74 | act(() => { |
| b69ab31 | | | 75 | fireMouseEvent('dragenter', textarea, 0, 0, { |
| b69ab31 | | | 76 | dataTransfer: { |
| b69ab31 | | | 77 | files: [], |
| b69ab31 | | | 78 | items: [], |
| b69ab31 | | | 79 | } as unknown as DataTransfer, |
| b69ab31 | | | 80 | }); |
| b69ab31 | | | 81 | }); // drag without files is ignored |
| b69ab31 | | | 82 | expect(document.querySelector('.hovering-to-drop')).toBeNull(); |
| b69ab31 | | | 83 | }); |
| b69ab31 | | | 84 | |
| b69ab31 | | | 85 | it('lets you drag an image to upload it', async () => { |
| b69ab31 | | | 86 | const textarea = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 87 | act(() => void fireMouseEvent('dragenter', textarea, 0, 0, {dataTransfer})); |
| b69ab31 | | | 88 | act(() => { |
| b69ab31 | | | 89 | fireMouseEvent('drop', textarea, 0, 0, {dataTransfer}); |
| b69ab31 | | | 90 | }); |
| b69ab31 | | | 91 | |
| b69ab31 | | | 92 | await waitFor(() => { |
| b69ab31 | | | 93 | expectMessageSentToServer(expect.objectContaining({type: 'uploadFile'})); |
| b69ab31 | | | 94 | }); |
| b69ab31 | | | 95 | }); |
| b69ab31 | | | 96 | }); |
| b69ab31 | | | 97 | |
| b69ab31 | | | 98 | describe('Paste image to upload', () => { |
| b69ab31 | | | 99 | it('lets you paste an image to upload it', async () => { |
| b69ab31 | | | 100 | const textarea = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 101 | act(() => { |
| b69ab31 | | | 102 | fireEvent.paste(textarea, {clipboardData: dataTransfer}); |
| b69ab31 | | | 103 | }); |
| b69ab31 | | | 104 | await waitFor(() => { |
| b69ab31 | | | 105 | expectMessageSentToServer(expect.objectContaining({type: 'uploadFile'})); |
| b69ab31 | | | 106 | }); |
| b69ab31 | | | 107 | }); |
| b69ab31 | | | 108 | it('pastes without images are handled normally', async () => { |
| b69ab31 | | | 109 | const textarea = CommitInfoTestUtils.getDescriptionEditor(); |
| b69ab31 | | | 110 | act(() => void fireEvent.paste(textarea)); |
| b69ab31 | | | 111 | await nextTick(); // allow file upload to await arrayBuffer() |
| b69ab31 | | | 112 | expectMessageNOTSentToServer(expect.objectContaining({type: 'uploadFile'})); |
| b69ab31 | | | 113 | }); |
| b69ab31 | | | 114 | }); |
| b69ab31 | | | 115 | |
| b69ab31 | | | 116 | describe('file picker to upload file', () => { |
| b69ab31 | | | 117 | it('lets you pick a file to upload', async () => { |
| b69ab31 | | | 118 | const uploadButton = screen.getAllByTestId('attach-file-input')[0]; |
| b69ab31 | | | 119 | act(() => { |
| b69ab31 | | | 120 | userEvent.upload(uploadButton, [mockFile]); |
| b69ab31 | | | 121 | }); |
| b69ab31 | | | 122 | |
| b69ab31 | | | 123 | await waitFor(() => { |
| b69ab31 | | | 124 | expectMessageSentToServer(expect.objectContaining({type: 'uploadFile'})); |
| b69ab31 | | | 125 | }); |
| b69ab31 | | | 126 | }); |
| b69ab31 | | | 127 | }); |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | describe('Image upload UI', () => { |
| b69ab31 | | | 130 | async function startFileUpload() { |
| b69ab31 | | | 131 | // Get the previous upload message (if any) to avoid race conditions |
| b69ab31 | | | 132 | const previousMessage = getLastMessageOfTypeSentToServer('uploadFile'); |
| b69ab31 | | | 133 | const previousId = previousMessage?.id; |
| b69ab31 | | | 134 | |
| b69ab31 | | | 135 | const uploadButton = screen.getAllByTestId('attach-file-input')[0]; |
| b69ab31 | | | 136 | act(() => void userEvent.upload(uploadButton, [mockFile])); |
| b69ab31 | | | 137 | |
| b69ab31 | | | 138 | // Wait for a NEW upload message that's different from the previous one |
| b69ab31 | | | 139 | const message = await waitFor(() => { |
| b69ab31 | | | 140 | const latestMessage = utils.nullthrows(getLastMessageOfTypeSentToServer('uploadFile')); |
| b69ab31 | | | 141 | // If this is the first upload or the ID is different from the previous one, we're good |
| b69ab31 | | | 142 | if (!previousId || latestMessage.id !== previousId) { |
| b69ab31 | | | 143 | return latestMessage; |
| b69ab31 | | | 144 | } |
| b69ab31 | | | 145 | // Otherwise, throw to keep waiting |
| b69ab31 | | | 146 | throw new Error('Still waiting for new upload message'); |
| b69ab31 | | | 147 | }); |
| b69ab31 | | | 148 | |
| b69ab31 | | | 149 | const id = message.id; |
| b69ab31 | | | 150 | expectMessageSentToServer(expect.objectContaining({type: 'uploadFile', id})); |
| b69ab31 | | | 151 | return id; |
| b69ab31 | | | 152 | } |
| b69ab31 | | | 153 | |
| b69ab31 | | | 154 | async function simulateUploadSucceeded(id: string) { |
| b69ab31 | | | 155 | await act(async () => { |
| b69ab31 | | | 156 | simulateMessageFromServer({ |
| b69ab31 | | | 157 | type: 'uploadFileResult', |
| b69ab31 | | | 158 | id, |
| b69ab31 | | | 159 | result: {value: `https://image.example.com/${id}`}, |
| b69ab31 | | | 160 | }); |
| b69ab31 | | | 161 | await nextTick(); |
| b69ab31 | | | 162 | }); |
| b69ab31 | | | 163 | } |
| b69ab31 | | | 164 | |
| b69ab31 | | | 165 | async function simulateUploadFailed(id: string) { |
| b69ab31 | | | 166 | await act(async () => { |
| b69ab31 | | | 167 | simulateMessageFromServer({ |
| b69ab31 | | | 168 | type: 'uploadFileResult', |
| b69ab31 | | | 169 | id, |
| b69ab31 | | | 170 | result: {error: new Error('upload failed')}, |
| b69ab31 | | | 171 | }); |
| b69ab31 | | | 172 | await nextTick(); |
| b69ab31 | | | 173 | }); |
| b69ab31 | | | 174 | } |
| b69ab31 | | | 175 | |
| b69ab31 | | | 176 | const {descriptionTextContent, getDescriptionEditor} = CommitInfoTestUtils; |
| b69ab31 | | | 177 | |
| b69ab31 | | | 178 | it('shows placeholder when uploading an image', async () => { |
| b69ab31 | | | 179 | expect(descriptionTextContent()).not.toContain('Uploading'); |
| b69ab31 | | | 180 | await startFileUpload(); |
| b69ab31 | | | 181 | expect(descriptionTextContent()).toContain('Uploading #1'); |
| b69ab31 | | | 182 | }); |
| b69ab31 | | | 183 | |
| b69ab31 | | | 184 | it('sends a message to the server to upload the file', async () => { |
| b69ab31 | | | 185 | const id = await startFileUpload(); |
| b69ab31 | | | 186 | expectMessageSentToServer({ |
| b69ab31 | | | 187 | type: 'uploadFile', |
| b69ab31 | | | 188 | filename: 'file.png', |
| b69ab31 | | | 189 | id, |
| b69ab31 | | | 190 | b64Content: mockFileContentInBase64, |
| b69ab31 | | | 191 | }); |
| b69ab31 | | | 192 | }); |
| b69ab31 | | | 193 | |
| b69ab31 | | | 194 | it('removes placeholder when upload succeeds', async () => { |
| b69ab31 | | | 195 | const id = await startFileUpload(); |
| b69ab31 | | | 196 | expect(descriptionTextContent()).toContain('Uploading #1'); |
| b69ab31 | | | 197 | await simulateUploadSucceeded(id); |
| b69ab31 | | | 198 | expect(descriptionTextContent()).not.toContain('Uploading #1'); |
| b69ab31 | | | 199 | expect(descriptionTextContent()).toContain(`https://image.example.com/${id}`); |
| b69ab31 | | | 200 | }); |
| b69ab31 | | | 201 | |
| b69ab31 | | | 202 | it('removes placeholder when upload fails', async () => { |
| b69ab31 | | | 203 | const id = await startFileUpload(); |
| b69ab31 | | | 204 | expect(descriptionTextContent()).toContain('Uploading #1'); |
| b69ab31 | | | 205 | await simulateUploadFailed(id); |
| b69ab31 | | | 206 | expect(descriptionTextContent()).not.toContain('Uploading #1'); |
| b69ab31 | | | 207 | expect(descriptionTextContent()).not.toContain('https://image.example.com'); |
| b69ab31 | | | 208 | }); |
| b69ab31 | | | 209 | |
| b69ab31 | | | 210 | it('shows progress of ongoing uploads', async () => { |
| b69ab31 | | | 211 | await startFileUpload(); |
| b69ab31 | | | 212 | expect(screen.getByText('Uploading 1 file')).toBeInTheDocument(); |
| b69ab31 | | | 213 | }); |
| b69ab31 | | | 214 | |
| b69ab31 | | | 215 | it('click to cancel upload', async () => { |
| b69ab31 | | | 216 | await startFileUpload(); |
| b69ab31 | | | 217 | expect(screen.getByText('Uploading 1 file')).toBeInTheDocument(); |
| b69ab31 | | | 218 | act(() => { |
| b69ab31 | | | 219 | fireEvent.mouseOver(screen.getByText('Uploading 1 file')); |
| b69ab31 | | | 220 | }); |
| b69ab31 | | | 221 | expect(screen.getByText('Click to cancel')).toBeInTheDocument(); |
| b69ab31 | | | 222 | act(() => { |
| b69ab31 | | | 223 | fireEvent.click(screen.getByText('Click to cancel')); |
| b69ab31 | | | 224 | }); |
| b69ab31 | | | 225 | |
| b69ab31 | | | 226 | expect(descriptionTextContent()).not.toContain('Uploading #1'); |
| b69ab31 | | | 227 | expect(screen.queryByText('Uploading 1 file')).not.toBeInTheDocument(); |
| b69ab31 | | | 228 | }); |
| b69ab31 | | | 229 | |
| b69ab31 | | | 230 | it('clears hover state when cancelling', async () => { |
| b69ab31 | | | 231 | await startFileUpload(); |
| b69ab31 | | | 232 | act(() => void fireEvent.mouseOver(screen.getByText('Uploading 1 file'))); |
| b69ab31 | | | 233 | act(() => void fireEvent.click(screen.getByText('Click to cancel'))); |
| b69ab31 | | | 234 | await startFileUpload(); |
| b69ab31 | | | 235 | expect(screen.queryByText('Uploading 1 file')).toBeInTheDocument(); |
| b69ab31 | | | 236 | }); |
| b69ab31 | | | 237 | |
| b69ab31 | | | 238 | it('shows upload errors', async () => { |
| b69ab31 | | | 239 | const id = await startFileUpload(); |
| b69ab31 | | | 240 | await simulateUploadFailed(id); |
| b69ab31 | | | 241 | expect(screen.getByText('1 file upload failed')).toBeInTheDocument(); |
| b69ab31 | | | 242 | fireEvent.click(screen.getByTestId('dismiss-upload-errors')); |
| b69ab31 | | | 243 | expect(screen.queryByText('1 file upload failed')).not.toBeInTheDocument(); |
| b69ab31 | | | 244 | }); |
| b69ab31 | | | 245 | |
| b69ab31 | | | 246 | it('handles multiple placeholders', async () => { |
| b69ab31 | | | 247 | const id1 = await startFileUpload(); |
| b69ab31 | | | 248 | expect(screen.getByText('Uploading 1 file')).toBeInTheDocument(); |
| b69ab31 | | | 249 | const id2 = await startFileUpload(); |
| b69ab31 | | | 250 | expect(screen.getByText('Uploading 2 files')).toBeInTheDocument(); |
| b69ab31 | | | 251 | expect(id1).not.toEqual(id2); |
| b69ab31 | | | 252 | |
| b69ab31 | | | 253 | expect(descriptionTextContent()).toContain('Uploading #1'); |
| b69ab31 | | | 254 | expect(descriptionTextContent()).toContain('Uploading #2'); |
| b69ab31 | | | 255 | await simulateUploadSucceeded(id1); |
| b69ab31 | | | 256 | expect(descriptionTextContent()).not.toContain('Uploading #1'); |
| b69ab31 | | | 257 | expect(descriptionTextContent()).toContain('Uploading #2'); |
| b69ab31 | | | 258 | |
| b69ab31 | | | 259 | expect(descriptionTextContent()).toContain(`https://image.example.com/${id1}`); |
| b69ab31 | | | 260 | expect(descriptionTextContent()).not.toContain(`https://image.example.com/${id2}`); |
| b69ab31 | | | 261 | |
| b69ab31 | | | 262 | await simulateUploadSucceeded(id2); |
| b69ab31 | | | 263 | expect(descriptionTextContent()).not.toContain('Uploading #2'); |
| b69ab31 | | | 264 | expect(descriptionTextContent()).toContain(`https://image.example.com/${id2}`); |
| b69ab31 | | | 265 | }); |
| b69ab31 | | | 266 | |
| b69ab31 | | | 267 | it('inserts whitespace before inserted placeholder when necessary', async () => { |
| b69ab31 | | | 268 | act(() => { |
| b69ab31 | | | 269 | userEvent.type(getDescriptionEditor(), 'Hello!\n'); |
| b69ab31 | | | 270 | // ^ cursor |
| b69ab31 | | | 271 | getDescriptionEditor().selectionStart = 6; |
| b69ab31 | | | 272 | getDescriptionEditor().selectionEnd = 6; |
| b69ab31 | | | 273 | }); |
| b69ab31 | | | 274 | await startFileUpload(); |
| b69ab31 | | | 275 | expect(descriptionTextContent()).toEqual('Hello! 【 Uploading #1 】\n'); |
| b69ab31 | | | 276 | // ^ inserted space ^ no extra space |
| b69ab31 | | | 277 | }); |
| b69ab31 | | | 278 | |
| b69ab31 | | | 279 | it('inserts whitespace after inserted placeholder when necessary', async () => { |
| b69ab31 | | | 280 | act(() => { |
| b69ab31 | | | 281 | userEvent.type(getDescriptionEditor(), 'Hello!\n'); |
| b69ab31 | | | 282 | // ^ cursor |
| b69ab31 | | | 283 | getDescriptionEditor().selectionStart = 0; |
| b69ab31 | | | 284 | getDescriptionEditor().selectionEnd = 0; |
| b69ab31 | | | 285 | }); |
| b69ab31 | | | 286 | await startFileUpload(); |
| b69ab31 | | | 287 | expect(descriptionTextContent()).toEqual('【 Uploading #1 】 Hello!\n'); |
| b69ab31 | | | 288 | // ^ no space ^ inserted space |
| b69ab31 | | | 289 | }); |
| b69ab31 | | | 290 | |
| b69ab31 | | | 291 | it('preserves selection when setting placeholders', async () => { |
| b69ab31 | | | 292 | act(() => { |
| b69ab31 | | | 293 | userEvent.type(getDescriptionEditor(), 'Hello, world!\n'); |
| b69ab31 | | | 294 | // ^-----^ selection |
| b69ab31 | | | 295 | getDescriptionEditor().selectionStart = 2; |
| b69ab31 | | | 296 | getDescriptionEditor().selectionEnd = 8; |
| b69ab31 | | | 297 | }); |
| b69ab31 | | | 298 | await startFileUpload(); |
| b69ab31 | | | 299 | expect(descriptionTextContent()).toEqual('He 【 Uploading #1 】 orld!\n'); |
| b69ab31 | | | 300 | // ^ inserted spaces ^ |
| b69ab31 | | | 301 | |
| b69ab31 | | | 302 | // now cursor is after Uploading |
| b69ab31 | | | 303 | expect(getDescriptionEditor().selectionStart).toEqual(20); |
| b69ab31 | | | 304 | expect(getDescriptionEditor().selectionEnd).toEqual(20); |
| b69ab31 | | | 305 | }); |
| b69ab31 | | | 306 | |
| b69ab31 | | | 307 | it('preserves selection when replacing placeholders', async () => { |
| b69ab31 | | | 308 | act(() => { |
| b69ab31 | | | 309 | userEvent.type(getDescriptionEditor(), 'fob\nbar\nbaz'); |
| b69ab31 | | | 310 | // ^ cursor |
| b69ab31 | | | 311 | getDescriptionEditor().selectionStart = 4; |
| b69ab31 | | | 312 | getDescriptionEditor().selectionEnd = 4; |
| b69ab31 | | | 313 | }); |
| b69ab31 | | | 314 | const id = await startFileUpload(); |
| b69ab31 | | | 315 | expect(descriptionTextContent()).toEqual('fob\n【 Uploading #1 】 bar\nbaz'); |
| b69ab31 | | | 316 | // start new selection: ^--------------------------^ |
| b69ab31 | | | 317 | getDescriptionEditor().selectionStart = 2; |
| b69ab31 | | | 318 | getDescriptionEditor().selectionEnd = 26; |
| b69ab31 | | | 319 | // make sure my indices are correct |
| b69ab31 | | | 320 | expect(descriptionTextContent()[getDescriptionEditor().selectionStart]).toEqual('b'); |
| b69ab31 | | | 321 | expect(descriptionTextContent()[getDescriptionEditor().selectionEnd]).toEqual('a'); |
| b69ab31 | | | 322 | |
| b69ab31 | | | 323 | await simulateUploadSucceeded(id); |
| b69ab31 | | | 324 | expect(descriptionTextContent()).toEqual(`fob\nhttps://image.example.com/${id} bar\nbaz`); |
| b69ab31 | | | 325 | // selection is preserved: ^---------------------------------------^ |
| b69ab31 | | | 326 | |
| b69ab31 | | | 327 | // now cursor is after Uploading |
| b69ab31 | | | 328 | expect(getDescriptionEditor().selectionStart).toEqual(2); |
| b69ab31 | | | 329 | expect(getDescriptionEditor().selectionEnd).toEqual(36 + id.length); |
| b69ab31 | | | 330 | expect(descriptionTextContent()[getDescriptionEditor().selectionStart]).toEqual('b'); |
| b69ab31 | | | 331 | expect(descriptionTextContent()[getDescriptionEditor().selectionEnd]).toEqual('a'); |
| b69ab31 | | | 332 | }); |
| b69ab31 | | | 333 | |
| b69ab31 | | | 334 | describe('disable commit info view buttons while uploading', () => { |
| b69ab31 | | | 335 | beforeEach(() => { |
| b69ab31 | | | 336 | act(() => { |
| b69ab31 | | | 337 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 338 | value: [{path: 'src/file1.js', status: 'M'}], |
| b69ab31 | | | 339 | }); |
| b69ab31 | | | 340 | }); |
| b69ab31 | | | 341 | }); |
| b69ab31 | | | 342 | |
| b69ab31 | | | 343 | it('disables amend message button', async () => { |
| b69ab31 | | | 344 | CommitInfoTestUtils.clickToSelectCommit('b'); |
| b69ab31 | | | 345 | CommitInfoTestUtils.clickToEditDescription(); |
| b69ab31 | | | 346 | expect( |
| b69ab31 | | | 347 | CommitInfoTestUtils.withinCommitActionBar().getByText('Amend Message'), |
| b69ab31 | | | 348 | ).not.toBeDisabled(); |
| b69ab31 | | | 349 | const id = await startFileUpload(); |
| b69ab31 | | | 350 | expect( |
| b69ab31 | | | 351 | CommitInfoTestUtils.withinCommitActionBar().getByText('Amend Message'), |
| b69ab31 | | | 352 | ).toBeDisabled(); |
| b69ab31 | | | 353 | await simulateUploadSucceeded(id); |
| b69ab31 | | | 354 | expect( |
| b69ab31 | | | 355 | CommitInfoTestUtils.withinCommitActionBar().getByText('Amend Message'), |
| b69ab31 | | | 356 | ).not.toBeDisabled(); |
| b69ab31 | | | 357 | }); |
| b69ab31 | | | 358 | |
| b69ab31 | | | 359 | it('disables amend button', async () => { |
| b69ab31 | | | 360 | expect(CommitInfoTestUtils.withinCommitActionBar().getByText('Amend')).not.toBeDisabled(); |
| b69ab31 | | | 361 | const id = await startFileUpload(); |
| b69ab31 | | | 362 | expect(CommitInfoTestUtils.withinCommitActionBar().getByText('Amend')).toBeDisabled(); |
| b69ab31 | | | 363 | await simulateUploadSucceeded(id); |
| b69ab31 | | | 364 | expect(CommitInfoTestUtils.withinCommitActionBar().getByText('Amend')).not.toBeDisabled(); |
| b69ab31 | | | 365 | }); |
| b69ab31 | | | 366 | |
| b69ab31 | | | 367 | it('disables commit button', async () => { |
| b69ab31 | | | 368 | CommitInfoTestUtils.clickCommitMode(); |
| b69ab31 | | | 369 | expect(CommitInfoTestUtils.withinCommitActionBar().getByText('Commit')).not.toBeDisabled(); |
| b69ab31 | | | 370 | const id = await startFileUpload(); |
| b69ab31 | | | 371 | expect(CommitInfoTestUtils.withinCommitActionBar().getByText('Commit')).toBeDisabled(); |
| b69ab31 | | | 372 | await simulateUploadSucceeded(id); |
| b69ab31 | | | 373 | expect(CommitInfoTestUtils.withinCommitActionBar().getByText('Commit')).not.toBeDisabled(); |
| b69ab31 | | | 374 | }); |
| b69ab31 | | | 375 | |
| b69ab31 | | | 376 | it('disables commit and submit button', async () => { |
| b69ab31 | | | 377 | act(() => { |
| b69ab31 | | | 378 | simulateMessageFromServer({ |
| b69ab31 | | | 379 | type: 'repoInfo', |
| b69ab31 | | | 380 | info: { |
| b69ab31 | | | 381 | codeReviewSystem: {type: 'github'} as CodeReviewSystem, |
| b69ab31 | | | 382 | command: 'sl', |
| b69ab31 | | | 383 | repoRoot: '/repo', |
| b69ab31 | | | 384 | dotdir: '/repo/.sl', |
| b69ab31 | | | 385 | type: 'success', |
| b69ab31 | | | 386 | pullRequestDomain: undefined, |
| b69ab31 | | | 387 | preferredSubmitCommand: undefined, |
| b69ab31 | | | 388 | isEdenFs: false, |
| b69ab31 | | | 389 | }, |
| b69ab31 | | | 390 | }); |
| b69ab31 | | | 391 | }); |
| b69ab31 | | | 392 | // Get around internally-disabled button |
| b69ab31 | | | 393 | fireEvent.click(screen.getByTestId('settings-gear-button')); |
| b69ab31 | | | 394 | const enableSubmit = screen.queryByTestId('force-enable-github-submit'); |
| b69ab31 | | | 395 | enableSubmit && fireEvent.click(enableSubmit); |
| b69ab31 | | | 396 | CommitInfoTestUtils.clickCommitMode(); |
| b69ab31 | | | 397 | expect( |
| b69ab31 | | | 398 | CommitInfoTestUtils.withinCommitActionBar().getByText('Commit and Submit'), |
| b69ab31 | | | 399 | ).not.toBeDisabled(); |
| b69ab31 | | | 400 | const id = await startFileUpload(); |
| b69ab31 | | | 401 | expect( |
| b69ab31 | | | 402 | CommitInfoTestUtils.withinCommitActionBar().getByText('Commit and Submit'), |
| b69ab31 | | | 403 | ).toBeDisabled(); |
| b69ab31 | | | 404 | await simulateUploadSucceeded(id); |
| b69ab31 | | | 405 | expect( |
| b69ab31 | | | 406 | CommitInfoTestUtils.withinCommitActionBar().getByText('Commit and Submit'), |
| b69ab31 | | | 407 | ).not.toBeDisabled(); |
| b69ab31 | | | 408 | }); |
| b69ab31 | | | 409 | }); |
| b69ab31 | | | 410 | |
| b69ab31 | | | 411 | it('emits uploads to underlying store', async () => { |
| b69ab31 | | | 412 | CommitInfoTestUtils.clickCommitMode(); |
| b69ab31 | | | 413 | act(() => { |
| b69ab31 | | | 414 | simulateUncommittedChangedFiles({value: [{path: 'foo.txt', status: 'M'}]}); |
| b69ab31 | | | 415 | }); |
| b69ab31 | | | 416 | act(() => { |
| b69ab31 | | | 417 | userEvent.type(CommitInfoTestUtils.getTitleEditor(), 'hi'); |
| b69ab31 | | | 418 | userEvent.type(CommitInfoTestUtils.getDescriptionEditor(), 'hey\n'); |
| b69ab31 | | | 419 | }); |
| b69ab31 | | | 420 | const id = await startFileUpload(); |
| b69ab31 | | | 421 | await simulateUploadSucceeded(id); |
| b69ab31 | | | 422 | expect(descriptionTextContent()).toContain(`https://image.example.com/${id}`); |
| b69ab31 | | | 423 | |
| b69ab31 | | | 424 | act(() => { |
| b69ab31 | | | 425 | fireEvent.click(CommitInfoTestUtils.withinCommitActionBar().getByText('Commit')); |
| b69ab31 | | | 426 | }); |
| b69ab31 | | | 427 | await waitFor(() => |
| b69ab31 | | | 428 | expectMessageSentToServer({ |
| b69ab31 | | | 429 | type: 'runOperation', |
| b69ab31 | | | 430 | operation: expect.objectContaining({ |
| b69ab31 | | | 431 | args: expect.arrayContaining([ |
| b69ab31 | | | 432 | 'commit', |
| b69ab31 | | | 433 | expect.stringMatching(`hi\n+(Summary:\n)?hey\nhttps://image.example.com/${id}`), |
| b69ab31 | | | 434 | ]), |
| b69ab31 | | | 435 | }), |
| b69ab31 | | | 436 | }), |
| b69ab31 | | | 437 | ); |
| b69ab31 | | | 438 | }); |
| b69ab31 | | | 439 | }); |
| b69ab31 | | | 440 | }); |