| 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} from '@testing-library/react'; |
| b69ab31 | | | 9 | import userEvent from '@testing-library/user-event'; |
| b69ab31 | | | 10 | import App from '../App'; |
| b69ab31 | | | 11 | import {CommitInfoTestUtils} from '../testQueries'; |
| b69ab31 | | | 12 | import { |
| b69ab31 | | | 13 | closeCommitInfoSidebar, |
| b69ab31 | | | 14 | expectMessageNOTSentToServer, |
| b69ab31 | | | 15 | expectMessageSentToServer, |
| b69ab31 | | | 16 | openCommitInfoSidebar, |
| b69ab31 | | | 17 | resetTestMessages, |
| b69ab31 | | | 18 | simulateCommits, |
| b69ab31 | | | 19 | TEST_COMMIT_HISTORY, |
| b69ab31 | | | 20 | } from '../testUtils'; |
| b69ab31 | | | 21 | import {CommandRunner} from '../types'; |
| b69ab31 | | | 22 | |
| b69ab31 | | | 23 | /*eslint-disable @typescript-eslint/no-non-null-assertion */ |
| b69ab31 | | | 24 | |
| b69ab31 | | | 25 | describe('combine', () => { |
| b69ab31 | | | 26 | beforeEach(() => { |
| b69ab31 | | | 27 | resetTestMessages(); |
| b69ab31 | | | 28 | render(<App />); |
| b69ab31 | | | 29 | act(() => { |
| b69ab31 | | | 30 | closeCommitInfoSidebar(); |
| b69ab31 | | | 31 | expectMessageSentToServer({ |
| b69ab31 | | | 32 | type: 'subscribe', |
| b69ab31 | | | 33 | kind: 'smartlogCommits', |
| b69ab31 | | | 34 | subscriptionID: expect.anything(), |
| b69ab31 | | | 35 | }); |
| b69ab31 | | | 36 | simulateCommits({ |
| b69ab31 | | | 37 | value: TEST_COMMIT_HISTORY, |
| b69ab31 | | | 38 | }); |
| b69ab31 | | | 39 | }); |
| b69ab31 | | | 40 | }); |
| b69ab31 | | | 41 | |
| b69ab31 | | | 42 | describe('shows preview for contiguous commits', () => { |
| b69ab31 | | | 43 | it('shows preview button for contiguous commits', () => { |
| b69ab31 | | | 44 | CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true); |
| b69ab31 | | | 45 | CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true); |
| b69ab31 | | | 46 | CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true); |
| b69ab31 | | | 47 | |
| b69ab31 | | | 48 | expect(screen.getByText('Combine 3 commits')).toBeInTheDocument(); |
| b69ab31 | | | 49 | }); |
| b69ab31 | | | 50 | |
| b69ab31 | | | 51 | it('gaps prevents button', () => { |
| b69ab31 | | | 52 | CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true); |
| b69ab31 | | | 53 | CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true); |
| b69ab31 | | | 54 | |
| b69ab31 | | | 55 | expect(screen.queryByText(/Combine \d+ commits/)).not.toBeInTheDocument(); |
| b69ab31 | | | 56 | }); |
| b69ab31 | | | 57 | }); |
| b69ab31 | | | 58 | |
| b69ab31 | | | 59 | it('allows cancelling', () => { |
| b69ab31 | | | 60 | CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true); |
| b69ab31 | | | 61 | CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true); |
| b69ab31 | | | 62 | |
| b69ab31 | | | 63 | fireEvent.click(screen.getByText('Combine 2 commits')); |
| b69ab31 | | | 64 | fireEvent.click(screen.getByText('Cancel')); |
| b69ab31 | | | 65 | |
| b69ab31 | | | 66 | expectMessageNOTSentToServer({ |
| b69ab31 | | | 67 | type: 'runOperation', |
| b69ab31 | | | 68 | operation: expect.anything(), |
| b69ab31 | | | 69 | }); |
| b69ab31 | | | 70 | }); |
| b69ab31 | | | 71 | |
| b69ab31 | | | 72 | it('runs combine operation', () => { |
| b69ab31 | | | 73 | CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true); |
| b69ab31 | | | 74 | CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true); |
| b69ab31 | | | 75 | CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true); |
| b69ab31 | | | 76 | |
| b69ab31 | | | 77 | fireEvent.click(screen.getByText('Combine 3 commits')); |
| b69ab31 | | | 78 | const runCombineButton = screen.getByText('Run Combine'); |
| b69ab31 | | | 79 | expect(runCombineButton).toBeInTheDocument(); |
| b69ab31 | | | 80 | fireEvent.click(runCombineButton); |
| b69ab31 | | | 81 | |
| b69ab31 | | | 82 | expectMessageSentToServer({ |
| b69ab31 | | | 83 | type: 'runOperation', |
| b69ab31 | | | 84 | operation: { |
| b69ab31 | | | 85 | args: [ |
| b69ab31 | | | 86 | 'fold', |
| b69ab31 | | | 87 | '--exact', |
| b69ab31 | | | 88 | {type: 'exact-revset', revset: 'b::d'}, |
| b69ab31 | | | 89 | '--message', |
| b69ab31 | | | 90 | 'Commit B, Commit C, Commit D\n', |
| b69ab31 | | | 91 | ], |
| b69ab31 | | | 92 | id: expect.anything(), |
| b69ab31 | | | 93 | runner: CommandRunner.Sapling, |
| b69ab31 | | | 94 | trackEventName: 'FoldOperation', |
| b69ab31 | | | 95 | }, |
| b69ab31 | | | 96 | }); |
| b69ab31 | | | 97 | }); |
| b69ab31 | | | 98 | |
| b69ab31 | | | 99 | it('shows preview of combined message', () => { |
| b69ab31 | | | 100 | act(() => openCommitInfoSidebar()); |
| b69ab31 | | | 101 | |
| b69ab31 | | | 102 | CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true); |
| b69ab31 | | | 103 | CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true); |
| b69ab31 | | | 104 | CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true); |
| b69ab31 | | | 105 | |
| b69ab31 | | | 106 | fireEvent.click(CommitInfoTestUtils.withinCommitInfo().getByText('Combine 3 commits')); |
| b69ab31 | | | 107 | |
| b69ab31 | | | 108 | expect(screen.getByText('Previewing result of combined commits')).toBeInTheDocument(); |
| b69ab31 | | | 109 | |
| b69ab31 | | | 110 | expect( |
| b69ab31 | | | 111 | CommitInfoTestUtils.withinCommitInfo().getByText('Commit B, Commit C, Commit D'), |
| b69ab31 | | | 112 | ).toBeInTheDocument(); |
| b69ab31 | | | 113 | }); |
| b69ab31 | | | 114 | |
| b69ab31 | | | 115 | it('allows editing combined message', () => { |
| b69ab31 | | | 116 | act(() => openCommitInfoSidebar()); |
| b69ab31 | | | 117 | |
| b69ab31 | | | 118 | CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true); |
| b69ab31 | | | 119 | CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true); |
| b69ab31 | | | 120 | CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true); |
| b69ab31 | | | 121 | |
| b69ab31 | | | 122 | fireEvent.click(CommitInfoTestUtils.withinCommitInfo().getByText('Combine 3 commits')); |
| b69ab31 | | | 123 | |
| b69ab31 | | | 124 | CommitInfoTestUtils.clickToEditDescription(); |
| b69ab31 | | | 125 | act(() => { |
| b69ab31 | | | 126 | userEvent.type(CommitInfoTestUtils.getDescriptionEditor(), 'new description'); |
| b69ab31 | | | 127 | }); |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | fireEvent.click(CommitInfoTestUtils.withinCommitInfo().getByText('Run Combine')); |
| b69ab31 | | | 130 | |
| b69ab31 | | | 131 | expectMessageSentToServer({ |
| b69ab31 | | | 132 | type: 'runOperation', |
| b69ab31 | | | 133 | operation: expect.objectContaining({ |
| b69ab31 | | | 134 | args: [ |
| b69ab31 | | | 135 | 'fold', |
| b69ab31 | | | 136 | '--exact', |
| b69ab31 | | | 137 | {type: 'exact-revset', revset: 'b::d'}, |
| b69ab31 | | | 138 | '--message', |
| b69ab31 | | | 139 | expect.stringContaining('new description'), |
| b69ab31 | | | 140 | ], |
| b69ab31 | | | 141 | }), |
| b69ab31 | | | 142 | }); |
| b69ab31 | | | 143 | }); |
| b69ab31 | | | 144 | |
| b69ab31 | | | 145 | describe('optimistic state', () => { |
| b69ab31 | | | 146 | it('shows preview before running', () => { |
| b69ab31 | | | 147 | CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true); |
| b69ab31 | | | 148 | CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true); |
| b69ab31 | | | 149 | CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true); |
| b69ab31 | | | 150 | |
| b69ab31 | | | 151 | fireEvent.click(screen.getByText('Combine 3 commits')); |
| b69ab31 | | | 152 | |
| b69ab31 | | | 153 | act(() => closeCommitInfoSidebar()); |
| b69ab31 | | | 154 | |
| b69ab31 | | | 155 | // combined commit is there |
| b69ab31 | | | 156 | expect(screen.getByText('Commit B, Commit C, Commit D')).toBeInTheDocument(); |
| b69ab31 | | | 157 | // original commits are gone |
| b69ab31 | | | 158 | expect(screen.queryByText('Commit B')).not.toBeInTheDocument(); |
| b69ab31 | | | 159 | expect(screen.queryByText('Commit C')).not.toBeInTheDocument(); |
| b69ab31 | | | 160 | expect(screen.queryByText('Commit D')).not.toBeInTheDocument(); |
| b69ab31 | | | 161 | // parent and children are still there |
| b69ab31 | | | 162 | expect(screen.getByText('Commit A')).toBeInTheDocument(); |
| b69ab31 | | | 163 | expect(screen.getByText('Commit E')).toBeInTheDocument(); |
| b69ab31 | | | 164 | }); |
| b69ab31 | | | 165 | |
| b69ab31 | | | 166 | it('shows optimistic state when running', () => { |
| b69ab31 | | | 167 | CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true); |
| b69ab31 | | | 168 | CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true); |
| b69ab31 | | | 169 | CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true); |
| b69ab31 | | | 170 | |
| b69ab31 | | | 171 | fireEvent.click(screen.getByText('Combine 3 commits')); |
| b69ab31 | | | 172 | fireEvent.click(screen.getByText('Run Combine')); |
| b69ab31 | | | 173 | |
| b69ab31 | | | 174 | act(() => closeCommitInfoSidebar()); |
| b69ab31 | | | 175 | |
| b69ab31 | | | 176 | // combined commit is there |
| b69ab31 | | | 177 | expect(screen.getByText('Commit B, Commit C, Commit D')).toBeInTheDocument(); |
| b69ab31 | | | 178 | // original commits are gone |
| b69ab31 | | | 179 | expect(screen.queryByText('Commit B')).not.toBeInTheDocument(); |
| b69ab31 | | | 180 | expect(screen.queryByText('Commit C')).not.toBeInTheDocument(); |
| b69ab31 | | | 181 | expect(screen.queryByText('Commit D')).not.toBeInTheDocument(); |
| b69ab31 | | | 182 | // parent and children are still there |
| b69ab31 | | | 183 | expect(screen.getByText('Commit A')).toBeInTheDocument(); |
| b69ab31 | | | 184 | expect(screen.getByText('Commit E')).toBeInTheDocument(); |
| b69ab31 | | | 185 | }); |
| b69ab31 | | | 186 | }); |
| b69ab31 | | | 187 | }); |