addons/isl/src/__tests__/CopyRenameFiles.test.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {CommandArg} from '../types';
b69ab319
b69ab3110import {act, fireEvent, render, screen, waitFor} from '@testing-library/react';
b69ab3111import App from '../App';
b69ab3112import {ignoreRTL} from '../testQueries';
b69ab3113import {
b69ab3114 closeCommitInfoSidebar,
b69ab3115 COMMIT,
b69ab3116 expectMessageSentToServer,
b69ab3117 resetTestMessages,
b69ab3118 simulateCommits,
b69ab3119 simulateRepoConnected,
b69ab3120 simulateUncommittedChangedFiles,
b69ab3121} from '../testUtils';
b69ab3122
b69ab3123describe('CopyRenameFiles', () => {
b69ab3124 beforeEach(() => {
b69ab3125 resetTestMessages();
b69ab3126 render(<App />);
b69ab3127 act(() => {
b69ab3128 simulateRepoConnected();
b69ab3129 closeCommitInfoSidebar();
b69ab3130 expectMessageSentToServer({
b69ab3131 type: 'subscribe',
b69ab3132 kind: 'smartlogCommits',
b69ab3133 subscriptionID: expect.anything(),
b69ab3134 });
b69ab3135 simulateCommits({
b69ab3136 value: [
b69ab3137 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab3138 COMMIT('a', 'My Commit', '1'),
b69ab3139 COMMIT('b', 'Another Commit', 'a', {isDot: true}),
b69ab3140 ],
b69ab3141 });
b69ab3142 });
b69ab3143 });
b69ab3144
b69ab3145 it('shows copied files', () => {
b69ab3146 act(() => {
b69ab3147 simulateUncommittedChangedFiles({
b69ab3148 value: [
b69ab3149 {path: 'file_copy.js', status: 'A', copy: 'file.js'},
b69ab3150 {path: 'path/to/file.txt', status: 'A', copy: 'path/original/copiedFrom.txt'},
b69ab3151 {path: 'path/copied/file.txt', status: 'A', copy: 'path/original/file.txt'},
b69ab3152 ],
b69ab3153 });
b69ab3154 });
b69ab3155 expect(screen.getByText(ignoreRTL('file.js → file_copy.js'))).toBeInTheDocument();
b69ab3156 expect(screen.getByText(ignoreRTL('copiedFrom.txt → file.txt'))).toBeInTheDocument();
b69ab3157 expect(screen.getByText(ignoreRTL('original/file.txt → copied/file.txt'))).toBeInTheDocument();
b69ab3158 });
b69ab3159
b69ab3160 it("removed files aren't hidden except for renames", () => {
b69ab3161 act(() => {
b69ab3162 simulateUncommittedChangedFiles({
b69ab3163 value: [
b69ab3164 {path: 'file_rem.js', status: 'R'},
b69ab3165 {path: 'file_copy.js', status: 'A', copy: 'file_orig1.js'},
b69ab3166 {path: 'file_rename.js', status: 'A', copy: 'file_orig2.js'},
b69ab3167 ],
b69ab3168 });
b69ab3169 });
b69ab3170 expect(screen.getByText(ignoreRTL('file_rem.js'))).toBeInTheDocument();
b69ab3171 });
b69ab3172
b69ab3173 it('shows renamed files', () => {
b69ab3174 act(() => {
b69ab3175 simulateUncommittedChangedFiles({
b69ab3176 value: [
b69ab3177 {path: 'file_rename.js', status: 'A', copy: 'file.js'},
b69ab3178 {path: 'file.js', status: 'R'},
b69ab3179 {path: 'path/to/file.txt', status: 'A', copy: 'path/original/movedFrom.txt'},
b69ab3180 {path: 'path/original/movedFrom.txt', status: 'R'},
b69ab3181 {path: 'path/moved/file.txt', status: 'A', copy: 'path/original/file.txt'},
b69ab3182 {path: 'path/original/file.txt', status: 'R'},
b69ab3183 ],
b69ab3184 });
b69ab3185 });
b69ab3186 expect(screen.getByText(ignoreRTL('file.js → file_rename.js'))).toBeInTheDocument();
b69ab3187 expect(screen.getByText(ignoreRTL('movedFrom.txt → file.txt'))).toBeInTheDocument();
b69ab3188 expect(screen.getByText(ignoreRTL('original/file.txt → moved/file.txt'))).toBeInTheDocument();
b69ab3189 // removed files are visually hidden:
b69ab3190 expect(screen.queryByText(ignoreRTL('file.js'))).not.toBeInTheDocument();
b69ab3191 expect(screen.queryByText(ignoreRTL('movedFrom.txt'))).not.toBeInTheDocument();
b69ab3192 expect(screen.queryByText(ignoreRTL('original/movedFrom.txt'))).not.toBeInTheDocument();
b69ab3193 expect(screen.queryByText(ignoreRTL('path/original/movedFrom.txt'))).not.toBeInTheDocument();
b69ab3194 expect(screen.queryByText(ignoreRTL('moved/file.txt'))).not.toBeInTheDocument();
b69ab3195 expect(screen.queryByText(ignoreRTL('path/moved/file.txt'))).not.toBeInTheDocument();
b69ab3196 });
b69ab3197
b69ab3198 it('selecting renamed files selects removed file as well', async () => {
b69ab3199 act(() => {
b69ab31100 simulateUncommittedChangedFiles({
b69ab31101 value: [
b69ab31102 {path: 'randomFile.txt', status: 'M'},
b69ab31103 {path: 'path/moved/file.txt', status: 'A', copy: 'path/original/file.txt'},
b69ab31104 {path: 'path/original/file.txt', status: 'R'},
b69ab31105 ],
b69ab31106 });
b69ab31107 });
b69ab31108
b69ab31109 // deselect everything
b69ab31110 act(() => {
b69ab31111 fireEvent.click(screen.getByTestId('deselect-all-button'));
b69ab31112 });
b69ab31113 // select the renamed file
b69ab31114 const modifiedFileCheckboxes = document.querySelectorAll(
b69ab31115 '.changed-files .changed-file.file-modified input[type="checkbox"]',
b69ab31116 );
b69ab31117 act(() => {
b69ab31118 fireEvent.click(modifiedFileCheckboxes[1]);
b69ab31119 });
b69ab31120 // create a commit
b69ab31121 fireEvent.click(screen.getByTestId('quick-commit-button'));
b69ab31122 await waitFor(() => {
b69ab31123 expectMessageSentToServer({
b69ab31124 type: 'runOperation',
b69ab31125 operation: expect.objectContaining({
b69ab31126 args: [
b69ab31127 'commit',
b69ab31128 '--addremove',
b69ab31129 '--message',
b69ab31130 expect.anything(),
b69ab31131 // both moved and removed file are passed, even though we only selected the single moved file
b69ab31132 {type: 'repo-relative-file', path: 'path/moved/file.txt'},
b69ab31133 {type: 'repo-relative-file', path: 'path/original/file.txt'},
b69ab31134 ] as Array<CommandArg>,
b69ab31135 }),
b69ab31136 });
b69ab31137 });
b69ab31138 });
b69ab31139});