addons/isl/src/__tests__/Combine.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} from '@testing-library/react';
b69ab319import userEvent from '@testing-library/user-event';
b69ab3110import App from '../App';
b69ab3111import {CommitInfoTestUtils} from '../testQueries';
b69ab3112import {
b69ab3113 closeCommitInfoSidebar,
b69ab3114 expectMessageNOTSentToServer,
b69ab3115 expectMessageSentToServer,
b69ab3116 openCommitInfoSidebar,
b69ab3117 resetTestMessages,
b69ab3118 simulateCommits,
b69ab3119 TEST_COMMIT_HISTORY,
b69ab3120} from '../testUtils';
b69ab3121import {CommandRunner} from '../types';
b69ab3122
b69ab3123/*eslint-disable @typescript-eslint/no-non-null-assertion */
b69ab3124
b69ab3125describe('combine', () => {
b69ab3126 beforeEach(() => {
b69ab3127 resetTestMessages();
b69ab3128 render(<App />);
b69ab3129 act(() => {
b69ab3130 closeCommitInfoSidebar();
b69ab3131 expectMessageSentToServer({
b69ab3132 type: 'subscribe',
b69ab3133 kind: 'smartlogCommits',
b69ab3134 subscriptionID: expect.anything(),
b69ab3135 });
b69ab3136 simulateCommits({
b69ab3137 value: TEST_COMMIT_HISTORY,
b69ab3138 });
b69ab3139 });
b69ab3140 });
b69ab3141
b69ab3142 describe('shows preview for contiguous commits', () => {
b69ab3143 it('shows preview button for contiguous commits', () => {
b69ab3144 CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true);
b69ab3145 CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true);
b69ab3146 CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true);
b69ab3147
b69ab3148 expect(screen.getByText('Combine 3 commits')).toBeInTheDocument();
b69ab3149 });
b69ab3150
b69ab3151 it('gaps prevents button', () => {
b69ab3152 CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true);
b69ab3153 CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true);
b69ab3154
b69ab3155 expect(screen.queryByText(/Combine \d+ commits/)).not.toBeInTheDocument();
b69ab3156 });
b69ab3157 });
b69ab3158
b69ab3159 it('allows cancelling', () => {
b69ab3160 CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true);
b69ab3161 CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true);
b69ab3162
b69ab3163 fireEvent.click(screen.getByText('Combine 2 commits'));
b69ab3164 fireEvent.click(screen.getByText('Cancel'));
b69ab3165
b69ab3166 expectMessageNOTSentToServer({
b69ab3167 type: 'runOperation',
b69ab3168 operation: expect.anything(),
b69ab3169 });
b69ab3170 });
b69ab3171
b69ab3172 it('runs combine operation', () => {
b69ab3173 CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true);
b69ab3174 CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true);
b69ab3175 CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true);
b69ab3176
b69ab3177 fireEvent.click(screen.getByText('Combine 3 commits'));
b69ab3178 const runCombineButton = screen.getByText('Run Combine');
b69ab3179 expect(runCombineButton).toBeInTheDocument();
b69ab3180 fireEvent.click(runCombineButton);
b69ab3181
b69ab3182 expectMessageSentToServer({
b69ab3183 type: 'runOperation',
b69ab3184 operation: {
b69ab3185 args: [
b69ab3186 'fold',
b69ab3187 '--exact',
b69ab3188 {type: 'exact-revset', revset: 'b::d'},
b69ab3189 '--message',
b69ab3190 'Commit B, Commit C, Commit D\n',
b69ab3191 ],
b69ab3192 id: expect.anything(),
b69ab3193 runner: CommandRunner.Sapling,
b69ab3194 trackEventName: 'FoldOperation',
b69ab3195 },
b69ab3196 });
b69ab3197 });
b69ab3198
b69ab3199 it('shows preview of combined message', () => {
b69ab31100 act(() => openCommitInfoSidebar());
b69ab31101
b69ab31102 CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true);
b69ab31103 CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true);
b69ab31104 CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true);
b69ab31105
b69ab31106 fireEvent.click(CommitInfoTestUtils.withinCommitInfo().getByText('Combine 3 commits'));
b69ab31107
b69ab31108 expect(screen.getByText('Previewing result of combined commits')).toBeInTheDocument();
b69ab31109
b69ab31110 expect(
b69ab31111 CommitInfoTestUtils.withinCommitInfo().getByText('Commit B, Commit C, Commit D'),
b69ab31112 ).toBeInTheDocument();
b69ab31113 });
b69ab31114
b69ab31115 it('allows editing combined message', () => {
b69ab31116 act(() => openCommitInfoSidebar());
b69ab31117
b69ab31118 CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true);
b69ab31119 CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true);
b69ab31120 CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true);
b69ab31121
b69ab31122 fireEvent.click(CommitInfoTestUtils.withinCommitInfo().getByText('Combine 3 commits'));
b69ab31123
b69ab31124 CommitInfoTestUtils.clickToEditDescription();
b69ab31125 act(() => {
b69ab31126 userEvent.type(CommitInfoTestUtils.getDescriptionEditor(), 'new description');
b69ab31127 });
b69ab31128
b69ab31129 fireEvent.click(CommitInfoTestUtils.withinCommitInfo().getByText('Run Combine'));
b69ab31130
b69ab31131 expectMessageSentToServer({
b69ab31132 type: 'runOperation',
b69ab31133 operation: expect.objectContaining({
b69ab31134 args: [
b69ab31135 'fold',
b69ab31136 '--exact',
b69ab31137 {type: 'exact-revset', revset: 'b::d'},
b69ab31138 '--message',
b69ab31139 expect.stringContaining('new description'),
b69ab31140 ],
b69ab31141 }),
b69ab31142 });
b69ab31143 });
b69ab31144
b69ab31145 describe('optimistic state', () => {
b69ab31146 it('shows preview before running', () => {
b69ab31147 CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true);
b69ab31148 CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true);
b69ab31149 CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true);
b69ab31150
b69ab31151 fireEvent.click(screen.getByText('Combine 3 commits'));
b69ab31152
b69ab31153 act(() => closeCommitInfoSidebar());
b69ab31154
b69ab31155 // combined commit is there
b69ab31156 expect(screen.getByText('Commit B, Commit C, Commit D')).toBeInTheDocument();
b69ab31157 // original commits are gone
b69ab31158 expect(screen.queryByText('Commit B')).not.toBeInTheDocument();
b69ab31159 expect(screen.queryByText('Commit C')).not.toBeInTheDocument();
b69ab31160 expect(screen.queryByText('Commit D')).not.toBeInTheDocument();
b69ab31161 // parent and children are still there
b69ab31162 expect(screen.getByText('Commit A')).toBeInTheDocument();
b69ab31163 expect(screen.getByText('Commit E')).toBeInTheDocument();
b69ab31164 });
b69ab31165
b69ab31166 it('shows optimistic state when running', () => {
b69ab31167 CommitInfoTestUtils.clickToSelectCommit('b', /* cmd click */ true);
b69ab31168 CommitInfoTestUtils.clickToSelectCommit('c', /* cmd click */ true);
b69ab31169 CommitInfoTestUtils.clickToSelectCommit('d', /* cmd click */ true);
b69ab31170
b69ab31171 fireEvent.click(screen.getByText('Combine 3 commits'));
b69ab31172 fireEvent.click(screen.getByText('Run Combine'));
b69ab31173
b69ab31174 act(() => closeCommitInfoSidebar());
b69ab31175
b69ab31176 // combined commit is there
b69ab31177 expect(screen.getByText('Commit B, Commit C, Commit D')).toBeInTheDocument();
b69ab31178 // original commits are gone
b69ab31179 expect(screen.queryByText('Commit B')).not.toBeInTheDocument();
b69ab31180 expect(screen.queryByText('Commit C')).not.toBeInTheDocument();
b69ab31181 expect(screen.queryByText('Commit D')).not.toBeInTheDocument();
b69ab31182 // parent and children are still there
b69ab31183 expect(screen.getByText('Commit A')).toBeInTheDocument();
b69ab31184 expect(screen.getByText('Commit E')).toBeInTheDocument();
b69ab31185 });
b69ab31186 });
b69ab31187});