| 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 {CommandArg} from '../types'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import {act, fireEvent, render, screen, waitFor} from '@testing-library/react'; |
| b69ab31 | | | 11 | import App from '../App'; |
| b69ab31 | | | 12 | import {ignoreRTL} from '../testQueries'; |
| b69ab31 | | | 13 | import { |
| b69ab31 | | | 14 | closeCommitInfoSidebar, |
| b69ab31 | | | 15 | COMMIT, |
| b69ab31 | | | 16 | expectMessageSentToServer, |
| b69ab31 | | | 17 | resetTestMessages, |
| b69ab31 | | | 18 | simulateCommits, |
| b69ab31 | | | 19 | simulateRepoConnected, |
| b69ab31 | | | 20 | simulateUncommittedChangedFiles, |
| b69ab31 | | | 21 | } from '../testUtils'; |
| b69ab31 | | | 22 | |
| b69ab31 | | | 23 | describe('CopyRenameFiles', () => { |
| b69ab31 | | | 24 | beforeEach(() => { |
| b69ab31 | | | 25 | resetTestMessages(); |
| b69ab31 | | | 26 | render(<App />); |
| b69ab31 | | | 27 | act(() => { |
| b69ab31 | | | 28 | simulateRepoConnected(); |
| b69ab31 | | | 29 | closeCommitInfoSidebar(); |
| b69ab31 | | | 30 | expectMessageSentToServer({ |
| b69ab31 | | | 31 | type: 'subscribe', |
| b69ab31 | | | 32 | kind: 'smartlogCommits', |
| b69ab31 | | | 33 | subscriptionID: expect.anything(), |
| b69ab31 | | | 34 | }); |
| b69ab31 | | | 35 | simulateCommits({ |
| b69ab31 | | | 36 | value: [ |
| b69ab31 | | | 37 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 38 | COMMIT('a', 'My Commit', '1'), |
| b69ab31 | | | 39 | COMMIT('b', 'Another Commit', 'a', {isDot: true}), |
| b69ab31 | | | 40 | ], |
| b69ab31 | | | 41 | }); |
| b69ab31 | | | 42 | }); |
| b69ab31 | | | 43 | }); |
| b69ab31 | | | 44 | |
| b69ab31 | | | 45 | it('shows copied files', () => { |
| b69ab31 | | | 46 | act(() => { |
| b69ab31 | | | 47 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 48 | value: [ |
| b69ab31 | | | 49 | {path: 'file_copy.js', status: 'A', copy: 'file.js'}, |
| b69ab31 | | | 50 | {path: 'path/to/file.txt', status: 'A', copy: 'path/original/copiedFrom.txt'}, |
| b69ab31 | | | 51 | {path: 'path/copied/file.txt', status: 'A', copy: 'path/original/file.txt'}, |
| b69ab31 | | | 52 | ], |
| b69ab31 | | | 53 | }); |
| b69ab31 | | | 54 | }); |
| b69ab31 | | | 55 | expect(screen.getByText(ignoreRTL('file.js → file_copy.js'))).toBeInTheDocument(); |
| b69ab31 | | | 56 | expect(screen.getByText(ignoreRTL('copiedFrom.txt → file.txt'))).toBeInTheDocument(); |
| b69ab31 | | | 57 | expect(screen.getByText(ignoreRTL('original/file.txt → copied/file.txt'))).toBeInTheDocument(); |
| b69ab31 | | | 58 | }); |
| b69ab31 | | | 59 | |
| b69ab31 | | | 60 | it("removed files aren't hidden except for renames", () => { |
| b69ab31 | | | 61 | act(() => { |
| b69ab31 | | | 62 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 63 | value: [ |
| b69ab31 | | | 64 | {path: 'file_rem.js', status: 'R'}, |
| b69ab31 | | | 65 | {path: 'file_copy.js', status: 'A', copy: 'file_orig1.js'}, |
| b69ab31 | | | 66 | {path: 'file_rename.js', status: 'A', copy: 'file_orig2.js'}, |
| b69ab31 | | | 67 | ], |
| b69ab31 | | | 68 | }); |
| b69ab31 | | | 69 | }); |
| b69ab31 | | | 70 | expect(screen.getByText(ignoreRTL('file_rem.js'))).toBeInTheDocument(); |
| b69ab31 | | | 71 | }); |
| b69ab31 | | | 72 | |
| b69ab31 | | | 73 | it('shows renamed files', () => { |
| b69ab31 | | | 74 | act(() => { |
| b69ab31 | | | 75 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 76 | value: [ |
| b69ab31 | | | 77 | {path: 'file_rename.js', status: 'A', copy: 'file.js'}, |
| b69ab31 | | | 78 | {path: 'file.js', status: 'R'}, |
| b69ab31 | | | 79 | {path: 'path/to/file.txt', status: 'A', copy: 'path/original/movedFrom.txt'}, |
| b69ab31 | | | 80 | {path: 'path/original/movedFrom.txt', status: 'R'}, |
| b69ab31 | | | 81 | {path: 'path/moved/file.txt', status: 'A', copy: 'path/original/file.txt'}, |
| b69ab31 | | | 82 | {path: 'path/original/file.txt', status: 'R'}, |
| b69ab31 | | | 83 | ], |
| b69ab31 | | | 84 | }); |
| b69ab31 | | | 85 | }); |
| b69ab31 | | | 86 | expect(screen.getByText(ignoreRTL('file.js → file_rename.js'))).toBeInTheDocument(); |
| b69ab31 | | | 87 | expect(screen.getByText(ignoreRTL('movedFrom.txt → file.txt'))).toBeInTheDocument(); |
| b69ab31 | | | 88 | expect(screen.getByText(ignoreRTL('original/file.txt → moved/file.txt'))).toBeInTheDocument(); |
| b69ab31 | | | 89 | // removed files are visually hidden: |
| b69ab31 | | | 90 | expect(screen.queryByText(ignoreRTL('file.js'))).not.toBeInTheDocument(); |
| b69ab31 | | | 91 | expect(screen.queryByText(ignoreRTL('movedFrom.txt'))).not.toBeInTheDocument(); |
| b69ab31 | | | 92 | expect(screen.queryByText(ignoreRTL('original/movedFrom.txt'))).not.toBeInTheDocument(); |
| b69ab31 | | | 93 | expect(screen.queryByText(ignoreRTL('path/original/movedFrom.txt'))).not.toBeInTheDocument(); |
| b69ab31 | | | 94 | expect(screen.queryByText(ignoreRTL('moved/file.txt'))).not.toBeInTheDocument(); |
| b69ab31 | | | 95 | expect(screen.queryByText(ignoreRTL('path/moved/file.txt'))).not.toBeInTheDocument(); |
| b69ab31 | | | 96 | }); |
| b69ab31 | | | 97 | |
| b69ab31 | | | 98 | it('selecting renamed files selects removed file as well', async () => { |
| b69ab31 | | | 99 | act(() => { |
| b69ab31 | | | 100 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 101 | value: [ |
| b69ab31 | | | 102 | {path: 'randomFile.txt', status: 'M'}, |
| b69ab31 | | | 103 | {path: 'path/moved/file.txt', status: 'A', copy: 'path/original/file.txt'}, |
| b69ab31 | | | 104 | {path: 'path/original/file.txt', status: 'R'}, |
| b69ab31 | | | 105 | ], |
| b69ab31 | | | 106 | }); |
| b69ab31 | | | 107 | }); |
| b69ab31 | | | 108 | |
| b69ab31 | | | 109 | // deselect everything |
| b69ab31 | | | 110 | act(() => { |
| b69ab31 | | | 111 | fireEvent.click(screen.getByTestId('deselect-all-button')); |
| b69ab31 | | | 112 | }); |
| b69ab31 | | | 113 | // select the renamed file |
| b69ab31 | | | 114 | const modifiedFileCheckboxes = document.querySelectorAll( |
| b69ab31 | | | 115 | '.changed-files .changed-file.file-modified input[type="checkbox"]', |
| b69ab31 | | | 116 | ); |
| b69ab31 | | | 117 | act(() => { |
| b69ab31 | | | 118 | fireEvent.click(modifiedFileCheckboxes[1]); |
| b69ab31 | | | 119 | }); |
| b69ab31 | | | 120 | // create a commit |
| b69ab31 | | | 121 | fireEvent.click(screen.getByTestId('quick-commit-button')); |
| b69ab31 | | | 122 | await waitFor(() => { |
| b69ab31 | | | 123 | expectMessageSentToServer({ |
| b69ab31 | | | 124 | type: 'runOperation', |
| b69ab31 | | | 125 | operation: expect.objectContaining({ |
| b69ab31 | | | 126 | args: [ |
| b69ab31 | | | 127 | 'commit', |
| b69ab31 | | | 128 | '--addremove', |
| b69ab31 | | | 129 | '--message', |
| b69ab31 | | | 130 | expect.anything(), |
| b69ab31 | | | 131 | // both moved and removed file are passed, even though we only selected the single moved file |
| b69ab31 | | | 132 | {type: 'repo-relative-file', path: 'path/moved/file.txt'}, |
| b69ab31 | | | 133 | {type: 'repo-relative-file', path: 'path/original/file.txt'}, |
| b69ab31 | | | 134 | ] as Array<CommandArg>, |
| b69ab31 | | | 135 | }), |
| b69ab31 | | | 136 | }); |
| b69ab31 | | | 137 | }); |
| b69ab31 | | | 138 | }); |
| b69ab31 | | | 139 | }); |