addons/isl/src/__tests__/operations/hideOperation.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 {act, fireEvent, render, screen, within} from '@testing-library/react';
b69ab319import userEvent from '@testing-library/user-event';
b69ab3110import App from '../../App';
b69ab3111import {CommitInfoTestUtils, CommitTreeListTestUtils} from '../../testQueries';
b69ab3112import {
b69ab3113 closeCommitInfoSidebar,
b69ab3114 COMMIT,
b69ab3115 expectMessageSentToServer,
b69ab3116 resetTestMessages,
b69ab3117 simulateCommits,
b69ab3118 TEST_COMMIT_HISTORY,
b69ab3119} from '../../testUtils';
b69ab3120import {CommandRunner} from '../../types';
b69ab3121
b69ab3122/*eslint-disable @typescript-eslint/no-non-null-assertion */
b69ab3123
b69ab3124describe('hide operation', () => {
b69ab3125 beforeEach(() => {
b69ab3126 resetTestMessages();
b69ab3127 render(<App />);
b69ab3128 act(() => {
b69ab3129 closeCommitInfoSidebar();
b69ab3130 expectMessageSentToServer({
b69ab3131 type: 'subscribe',
b69ab3132 kind: 'smartlogCommits',
b69ab3133 subscriptionID: expect.anything(),
b69ab3134 });
b69ab3135 simulateCommits({
b69ab3136 value: TEST_COMMIT_HISTORY,
b69ab3137 });
b69ab3138 });
b69ab3139 });
b69ab3140
b69ab3141 function rightClickAndChooseFromContextMenu(element: Element, choiceMatcher: string) {
b69ab3142 act(() => {
b69ab3143 fireEvent.contextMenu(element);
b69ab3144 });
b69ab3145 const choice = within(screen.getByTestId('context-menu-container')).getByText(choiceMatcher);
b69ab3146 expect(choice).not.toEqual(null);
b69ab3147 act(() => {
b69ab3148 fireEvent.click(choice);
b69ab3149 });
b69ab3150 }
b69ab3151
b69ab3152 it('previews hiding a stack of commits', () => {
b69ab3153 rightClickAndChooseFromContextMenu(screen.getByText('Commit B'), 'Hide Commit and Descendants');
b69ab3154
b69ab3155 expect(document.querySelectorAll('.commit-preview-hidden-root')).toHaveLength(1);
b69ab3156 expect(document.querySelectorAll('.commit-preview-hidden-descendant')).toHaveLength(3);
b69ab3157 });
b69ab3158
b69ab3159 it('runs hide operation', () => {
b69ab3160 rightClickAndChooseFromContextMenu(screen.getByText('Commit B'), 'Hide Commit and Descendants');
b69ab3161
b69ab3162 const runHideButton = screen.getByText('Hide');
b69ab3163 expect(runHideButton).toBeInTheDocument();
b69ab3164 fireEvent.click(runHideButton);
b69ab3165
b69ab3166 expectMessageSentToServer({
b69ab3167 type: 'runOperation',
b69ab3168 operation: {
b69ab3169 args: ['hide', '--rev', {type: 'succeedable-revset', revset: 'b'}],
b69ab3170 id: expect.anything(),
b69ab3171 runner: CommandRunner.Sapling,
b69ab3172 trackEventName: 'HideOperation',
b69ab3173 },
b69ab3174 });
b69ab3175 });
b69ab3176
b69ab3177 it('uses exact revset if commit is obsolete', () => {
b69ab3178 act(() => {
b69ab3179 simulateCommits({
b69ab3180 value: [
b69ab3181 COMMIT('a', 'Commit A', '1', {successorInfo: {hash: 'a2', type: 'rebase'}}),
b69ab3182 COMMIT('a2', 'Commit A2', '2'),
b69ab3183 COMMIT('b', 'Commit B', '1'),
b69ab3184 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab3185 COMMIT('2', 'some public base 2', '1', {phase: 'public'}),
b69ab3186 ],
b69ab3187 });
b69ab3188 });
b69ab3189
b69ab3190 rightClickAndChooseFromContextMenu(screen.getByText('Commit A'), 'Hide Commit');
b69ab3191
b69ab3192 const runHideButton = screen.getByText('Hide');
b69ab3193 expect(runHideButton).toBeInTheDocument();
b69ab3194 fireEvent.click(runHideButton);
b69ab3195
b69ab3196 expectMessageSentToServer({
b69ab3197 type: 'runOperation',
b69ab3198 operation: {
b69ab3199 args: ['hide', '--rev', {type: 'exact-revset', revset: 'a'}],
b69ab31100 id: expect.anything(),
b69ab31101 runner: CommandRunner.Sapling,
b69ab31102 trackEventName: 'HideOperation',
b69ab31103 },
b69ab31104 });
b69ab31105 });
b69ab31106
b69ab31107 it('shows optimistic preview of hide', () => {
b69ab31108 rightClickAndChooseFromContextMenu(screen.getByText('Commit B'), 'Hide Commit and Descendants');
b69ab31109
b69ab31110 const runHideButton = screen.getByText('Hide');
b69ab31111 fireEvent.click(runHideButton);
b69ab31112
b69ab31113 // original commit is hidden
b69ab31114 expect(screen.queryByTestId('commit-b')).not.toBeInTheDocument();
b69ab31115 // same for descendants
b69ab31116 expect(screen.queryByTestId('commit-c')).not.toBeInTheDocument();
b69ab31117 expect(screen.queryByTestId('commit-d')).not.toBeInTheDocument();
b69ab31118 expect(screen.queryByTestId('commit-e')).not.toBeInTheDocument();
b69ab31119 });
b69ab31120
b69ab31121 it('does not show uninteresting public base during optimistic hide', async () => {
b69ab31122 // Go to another branch so head is not being hidden.
b69ab31123 await CommitTreeListTestUtils.clickGoto('z');
b69ab31124 rightClickAndChooseFromContextMenu(screen.getByText('Commit A'), 'Hide Commit and Descendants');
b69ab31125
b69ab31126 const runHideButton = screen.getByText('Hide');
b69ab31127 fireEvent.click(runHideButton);
b69ab31128
b69ab31129 // the whole subtree is hidden, so the parent commit is not even rendered
b69ab31130 expect(screen.queryByTestId('commit-1')).not.toBeInTheDocument();
b69ab31131 });
b69ab31132
b69ab31133 it('shows public base when its the goto preview destination', () => {
b69ab31134 rightClickAndChooseFromContextMenu(screen.getByText('Commit A'), 'Hide Commit and Descendants');
b69ab31135
b69ab31136 const runHideButton = screen.getByText('Hide');
b69ab31137 fireEvent.click(runHideButton);
b69ab31138
b69ab31139 // the whole subtree and head is hidden, so the parent commit is shown as the goto destination
b69ab31140 expect(screen.queryByTestId('commit-1')).toBeInTheDocument();
b69ab31141 });
b69ab31142
b69ab31143 it('does show interesting public base during optimistic hide', () => {
b69ab31144 rightClickAndChooseFromContextMenu(screen.getByText('Commit X'), 'Hide Commit and Descendants');
b69ab31145
b69ab31146 const runHideButton = screen.getByText('Hide');
b69ab31147 fireEvent.click(runHideButton);
b69ab31148
b69ab31149 // the whole subtree is hidden, but this commit has the remote/master bookmark so it's shown anyway.
b69ab31150 expect(screen.queryByTestId('commit-2')).toBeInTheDocument();
b69ab31151 });
b69ab31152
b69ab31153 it('previews a hide by pressing delete with a selection', () => {
b69ab31154 CommitInfoTestUtils.clickToSelectCommit('b');
b69ab31155
b69ab31156 act(() => {
b69ab31157 userEvent.type(document.body, '{Backspace}');
b69ab31158 });
b69ab31159
b69ab31160 const runHideButton = screen.getByText('Hide');
b69ab31161 expect(runHideButton).toBeInTheDocument();
b69ab31162 expect(runHideButton).toHaveFocus();
b69ab31163 fireEvent.click(runHideButton);
b69ab31164
b69ab31165 expectMessageSentToServer({
b69ab31166 type: 'runOperation',
b69ab31167 operation: {
b69ab31168 args: ['hide', '--rev', {type: 'succeedable-revset', revset: 'b'}],
b69ab31169 id: expect.anything(),
b69ab31170 runner: CommandRunner.Sapling,
b69ab31171 trackEventName: 'HideOperation',
b69ab31172 },
b69ab31173 });
b69ab31174 });
b69ab31175});