| 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, within} from '@testing-library/react'; |
| b69ab31 | | | 9 | import userEvent from '@testing-library/user-event'; |
| b69ab31 | | | 10 | import App from '../../App'; |
| b69ab31 | | | 11 | import {CommitInfoTestUtils, CommitTreeListTestUtils} from '../../testQueries'; |
| b69ab31 | | | 12 | import { |
| b69ab31 | | | 13 | closeCommitInfoSidebar, |
| b69ab31 | | | 14 | COMMIT, |
| b69ab31 | | | 15 | expectMessageSentToServer, |
| b69ab31 | | | 16 | resetTestMessages, |
| b69ab31 | | | 17 | simulateCommits, |
| b69ab31 | | | 18 | TEST_COMMIT_HISTORY, |
| b69ab31 | | | 19 | } from '../../testUtils'; |
| b69ab31 | | | 20 | import {CommandRunner} from '../../types'; |
| b69ab31 | | | 21 | |
| b69ab31 | | | 22 | /*eslint-disable @typescript-eslint/no-non-null-assertion */ |
| b69ab31 | | | 23 | |
| b69ab31 | | | 24 | describe('hide operation', () => { |
| b69ab31 | | | 25 | beforeEach(() => { |
| b69ab31 | | | 26 | resetTestMessages(); |
| b69ab31 | | | 27 | render(<App />); |
| b69ab31 | | | 28 | act(() => { |
| 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: TEST_COMMIT_HISTORY, |
| b69ab31 | | | 37 | }); |
| b69ab31 | | | 38 | }); |
| b69ab31 | | | 39 | }); |
| b69ab31 | | | 40 | |
| b69ab31 | | | 41 | function rightClickAndChooseFromContextMenu(element: Element, choiceMatcher: string) { |
| b69ab31 | | | 42 | act(() => { |
| b69ab31 | | | 43 | fireEvent.contextMenu(element); |
| b69ab31 | | | 44 | }); |
| b69ab31 | | | 45 | const choice = within(screen.getByTestId('context-menu-container')).getByText(choiceMatcher); |
| b69ab31 | | | 46 | expect(choice).not.toEqual(null); |
| b69ab31 | | | 47 | act(() => { |
| b69ab31 | | | 48 | fireEvent.click(choice); |
| b69ab31 | | | 49 | }); |
| b69ab31 | | | 50 | } |
| b69ab31 | | | 51 | |
| b69ab31 | | | 52 | it('previews hiding a stack of commits', () => { |
| b69ab31 | | | 53 | rightClickAndChooseFromContextMenu(screen.getByText('Commit B'), 'Hide Commit and Descendants'); |
| b69ab31 | | | 54 | |
| b69ab31 | | | 55 | expect(document.querySelectorAll('.commit-preview-hidden-root')).toHaveLength(1); |
| b69ab31 | | | 56 | expect(document.querySelectorAll('.commit-preview-hidden-descendant')).toHaveLength(3); |
| b69ab31 | | | 57 | }); |
| b69ab31 | | | 58 | |
| b69ab31 | | | 59 | it('runs hide operation', () => { |
| b69ab31 | | | 60 | rightClickAndChooseFromContextMenu(screen.getByText('Commit B'), 'Hide Commit and Descendants'); |
| b69ab31 | | | 61 | |
| b69ab31 | | | 62 | const runHideButton = screen.getByText('Hide'); |
| b69ab31 | | | 63 | expect(runHideButton).toBeInTheDocument(); |
| b69ab31 | | | 64 | fireEvent.click(runHideButton); |
| b69ab31 | | | 65 | |
| b69ab31 | | | 66 | expectMessageSentToServer({ |
| b69ab31 | | | 67 | type: 'runOperation', |
| b69ab31 | | | 68 | operation: { |
| b69ab31 | | | 69 | args: ['hide', '--rev', {type: 'succeedable-revset', revset: 'b'}], |
| b69ab31 | | | 70 | id: expect.anything(), |
| b69ab31 | | | 71 | runner: CommandRunner.Sapling, |
| b69ab31 | | | 72 | trackEventName: 'HideOperation', |
| b69ab31 | | | 73 | }, |
| b69ab31 | | | 74 | }); |
| b69ab31 | | | 75 | }); |
| b69ab31 | | | 76 | |
| b69ab31 | | | 77 | it('uses exact revset if commit is obsolete', () => { |
| b69ab31 | | | 78 | act(() => { |
| b69ab31 | | | 79 | simulateCommits({ |
| b69ab31 | | | 80 | value: [ |
| b69ab31 | | | 81 | COMMIT('a', 'Commit A', '1', {successorInfo: {hash: 'a2', type: 'rebase'}}), |
| b69ab31 | | | 82 | COMMIT('a2', 'Commit A2', '2'), |
| b69ab31 | | | 83 | COMMIT('b', 'Commit B', '1'), |
| b69ab31 | | | 84 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 85 | COMMIT('2', 'some public base 2', '1', {phase: 'public'}), |
| b69ab31 | | | 86 | ], |
| b69ab31 | | | 87 | }); |
| b69ab31 | | | 88 | }); |
| b69ab31 | | | 89 | |
| b69ab31 | | | 90 | rightClickAndChooseFromContextMenu(screen.getByText('Commit A'), 'Hide Commit'); |
| b69ab31 | | | 91 | |
| b69ab31 | | | 92 | const runHideButton = screen.getByText('Hide'); |
| b69ab31 | | | 93 | expect(runHideButton).toBeInTheDocument(); |
| b69ab31 | | | 94 | fireEvent.click(runHideButton); |
| b69ab31 | | | 95 | |
| b69ab31 | | | 96 | expectMessageSentToServer({ |
| b69ab31 | | | 97 | type: 'runOperation', |
| b69ab31 | | | 98 | operation: { |
| b69ab31 | | | 99 | args: ['hide', '--rev', {type: 'exact-revset', revset: 'a'}], |
| b69ab31 | | | 100 | id: expect.anything(), |
| b69ab31 | | | 101 | runner: CommandRunner.Sapling, |
| b69ab31 | | | 102 | trackEventName: 'HideOperation', |
| b69ab31 | | | 103 | }, |
| b69ab31 | | | 104 | }); |
| b69ab31 | | | 105 | }); |
| b69ab31 | | | 106 | |
| b69ab31 | | | 107 | it('shows optimistic preview of hide', () => { |
| b69ab31 | | | 108 | rightClickAndChooseFromContextMenu(screen.getByText('Commit B'), 'Hide Commit and Descendants'); |
| b69ab31 | | | 109 | |
| b69ab31 | | | 110 | const runHideButton = screen.getByText('Hide'); |
| b69ab31 | | | 111 | fireEvent.click(runHideButton); |
| b69ab31 | | | 112 | |
| b69ab31 | | | 113 | // original commit is hidden |
| b69ab31 | | | 114 | expect(screen.queryByTestId('commit-b')).not.toBeInTheDocument(); |
| b69ab31 | | | 115 | // same for descendants |
| b69ab31 | | | 116 | expect(screen.queryByTestId('commit-c')).not.toBeInTheDocument(); |
| b69ab31 | | | 117 | expect(screen.queryByTestId('commit-d')).not.toBeInTheDocument(); |
| b69ab31 | | | 118 | expect(screen.queryByTestId('commit-e')).not.toBeInTheDocument(); |
| b69ab31 | | | 119 | }); |
| b69ab31 | | | 120 | |
| b69ab31 | | | 121 | it('does not show uninteresting public base during optimistic hide', async () => { |
| b69ab31 | | | 122 | // Go to another branch so head is not being hidden. |
| b69ab31 | | | 123 | await CommitTreeListTestUtils.clickGoto('z'); |
| b69ab31 | | | 124 | rightClickAndChooseFromContextMenu(screen.getByText('Commit A'), 'Hide Commit and Descendants'); |
| b69ab31 | | | 125 | |
| b69ab31 | | | 126 | const runHideButton = screen.getByText('Hide'); |
| b69ab31 | | | 127 | fireEvent.click(runHideButton); |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | // the whole subtree is hidden, so the parent commit is not even rendered |
| b69ab31 | | | 130 | expect(screen.queryByTestId('commit-1')).not.toBeInTheDocument(); |
| b69ab31 | | | 131 | }); |
| b69ab31 | | | 132 | |
| b69ab31 | | | 133 | it('shows public base when its the goto preview destination', () => { |
| b69ab31 | | | 134 | rightClickAndChooseFromContextMenu(screen.getByText('Commit A'), 'Hide Commit and Descendants'); |
| b69ab31 | | | 135 | |
| b69ab31 | | | 136 | const runHideButton = screen.getByText('Hide'); |
| b69ab31 | | | 137 | fireEvent.click(runHideButton); |
| b69ab31 | | | 138 | |
| b69ab31 | | | 139 | // the whole subtree and head is hidden, so the parent commit is shown as the goto destination |
| b69ab31 | | | 140 | expect(screen.queryByTestId('commit-1')).toBeInTheDocument(); |
| b69ab31 | | | 141 | }); |
| b69ab31 | | | 142 | |
| b69ab31 | | | 143 | it('does show interesting public base during optimistic hide', () => { |
| b69ab31 | | | 144 | rightClickAndChooseFromContextMenu(screen.getByText('Commit X'), 'Hide Commit and Descendants'); |
| b69ab31 | | | 145 | |
| b69ab31 | | | 146 | const runHideButton = screen.getByText('Hide'); |
| b69ab31 | | | 147 | fireEvent.click(runHideButton); |
| b69ab31 | | | 148 | |
| b69ab31 | | | 149 | // the whole subtree is hidden, but this commit has the remote/master bookmark so it's shown anyway. |
| b69ab31 | | | 150 | expect(screen.queryByTestId('commit-2')).toBeInTheDocument(); |
| b69ab31 | | | 151 | }); |
| b69ab31 | | | 152 | |
| b69ab31 | | | 153 | it('previews a hide by pressing delete with a selection', () => { |
| b69ab31 | | | 154 | CommitInfoTestUtils.clickToSelectCommit('b'); |
| b69ab31 | | | 155 | |
| b69ab31 | | | 156 | act(() => { |
| b69ab31 | | | 157 | userEvent.type(document.body, '{Backspace}'); |
| b69ab31 | | | 158 | }); |
| b69ab31 | | | 159 | |
| b69ab31 | | | 160 | const runHideButton = screen.getByText('Hide'); |
| b69ab31 | | | 161 | expect(runHideButton).toBeInTheDocument(); |
| b69ab31 | | | 162 | expect(runHideButton).toHaveFocus(); |
| b69ab31 | | | 163 | fireEvent.click(runHideButton); |
| b69ab31 | | | 164 | |
| b69ab31 | | | 165 | expectMessageSentToServer({ |
| b69ab31 | | | 166 | type: 'runOperation', |
| b69ab31 | | | 167 | operation: { |
| b69ab31 | | | 168 | args: ['hide', '--rev', {type: 'succeedable-revset', revset: 'b'}], |
| b69ab31 | | | 169 | id: expect.anything(), |
| b69ab31 | | | 170 | runner: CommandRunner.Sapling, |
| b69ab31 | | | 171 | trackEventName: 'HideOperation', |
| b69ab31 | | | 172 | }, |
| b69ab31 | | | 173 | }); |
| b69ab31 | | | 174 | }); |
| b69ab31 | | | 175 | }); |