addons/isl/src/__tests__/operations/amendMessageOperation.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, render, waitFor} from '@testing-library/react';
b69ab319import userEvent from '@testing-library/user-event';
b69ab3110import * as utils from 'shared/utils';
b69ab3111import App from '../../App';
b69ab3112import {CommitInfoTestUtils, CommitTreeListTestUtils} from '../../testQueries';
b69ab3113import {
b69ab3114 COMMIT,
b69ab3115 expectMessageSentToServer,
b69ab3116 getLastMessageOfTypeSentToServer,
b69ab3117 openCommitInfoSidebar,
b69ab3118 resetTestMessages,
b69ab3119 simulateCommits,
b69ab3120 simulateMessageFromServer,
b69ab3121 simulateUncommittedChangedFiles,
b69ab3122} from '../../testUtils';
b69ab3123
b69ab3124describe('AmendMessageOperation', () => {
b69ab3125 beforeEach(() => {
b69ab3126 resetTestMessages();
b69ab3127 render(<App />);
b69ab3128 act(() => {
b69ab3129 simulateMessageFromServer({
b69ab3130 type: 'repoInfo',
b69ab3131 info: {
b69ab3132 type: 'success',
b69ab3133 command: 'sl',
b69ab3134 repoRoot: '/path/to/testrepo',
b69ab3135 dotdir: '/path/to/testrepo/.sl',
b69ab3136 codeReviewSystem: {type: 'unknown'},
b69ab3137 pullRequestDomain: undefined,
b69ab3138 preferredSubmitCommand: undefined,
b69ab3139 isEdenFs: false,
b69ab3140 },
b69ab3141 });
b69ab3142 expectMessageSentToServer({
b69ab3143 type: 'subscribe',
b69ab3144 kind: 'smartlogCommits',
b69ab3145 subscriptionID: expect.anything(),
b69ab3146 });
b69ab3147 simulateUncommittedChangedFiles({
b69ab3148 value: [
b69ab3149 {path: 'file1.txt', status: 'M'},
b69ab3150 {path: 'file2.txt', status: 'A'},
b69ab3151 {path: 'file3.txt', status: 'R'},
b69ab3152 ],
b69ab3153 });
b69ab3154 simulateCommits({
b69ab3155 value: [
b69ab3156 COMMIT('111111111111', 'Commit 1', '0', {phase: 'public'}),
b69ab3157 COMMIT('aaaaaaaaaaaa', 'Commit A', '1'),
b69ab3158 COMMIT('bbbbbbbbbbbb', 'Commit B', 'a', {isDot: true}),
b69ab3159 COMMIT('cccccccccccc', 'Commit C', 'b'),
b69ab3160 ],
b69ab3161 });
b69ab3162 });
b69ab3163 });
b69ab3164
b69ab3165 it('on error, restores edited commit message to try again', async () => {
b69ab3166 act(() => CommitInfoTestUtils.clickToSelectCommit('aaaaaaaaaaaa'));
b69ab3167 act(() => openCommitInfoSidebar());
b69ab3168 act(() => {
b69ab3169 CommitInfoTestUtils.clickToEditTitle();
b69ab3170 CommitInfoTestUtils.clickToEditDescription();
b69ab3171 });
b69ab3172 act(() => {
b69ab3173 const title = CommitInfoTestUtils.getTitleEditor();
b69ab3174 userEvent.type(title, 'My Commit');
b69ab3175 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab3176 userEvent.type(desc, 'My description');
b69ab3177 });
b69ab3178
b69ab3179 act(() => {
b69ab3180 CommitInfoTestUtils.clickAmendMessageButton();
b69ab3181 });
b69ab3182 const message = await waitFor(() =>
b69ab3183 utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')),
b69ab3184 );
b69ab3185 const id = message.operation.id;
b69ab3186
b69ab3187 CommitInfoTestUtils.expectIsNOTEditingTitle();
b69ab3188
b69ab3189 act(() => CommitInfoTestUtils.clickToSelectCommit('bbbbbbbbbbbb'));
b69ab3190 expect(CommitInfoTestUtils.withinCommitInfo().getByText('You are here')).toBeInTheDocument();
b69ab3191
b69ab3192 act(() => {
b69ab3193 simulateMessageFromServer({
b69ab3194 type: 'operationProgress',
b69ab3195 kind: 'exit',
b69ab3196 exitCode: 1,
b69ab3197 id,
b69ab3198 timestamp: 0,
b69ab3199 });
b69ab31100 });
b69ab31101
b69ab31102 waitFor(() => {
b69ab31103 expect(
b69ab31104 CommitInfoTestUtils.withinCommitInfo().getByText('You are here'),
b69ab31105 ).not.toBeInTheDocument();
b69ab31106 CommitInfoTestUtils.expectIsEditingTitle();
b69ab31107 const title = CommitInfoTestUtils.getTitleEditor();
b69ab31108 expect(title).toHaveValue('My Commit');
b69ab31109 CommitInfoTestUtils.expectIsEditingDescription();
b69ab31110 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab31111 expect(desc).toHaveValue('My description');
b69ab31112 });
b69ab31113 });
b69ab31114
b69ab31115 it('if a previous command errors and metaedit is queued, the message is recovered', async () => {
b69ab31116 await CommitTreeListTestUtils.clickGoto('cccccccccccc');
b69ab31117 expectMessageSentToServer({
b69ab31118 type: 'runOperation',
b69ab31119 operation: expect.objectContaining({
b69ab31120 args: expect.arrayContaining(['goto']),
b69ab31121 }),
b69ab31122 });
b69ab31123 const gotoMessage = utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation'));
b69ab31124 const gotoId = gotoMessage.operation.id;
b69ab31125
b69ab31126 act(() => {
b69ab31127 simulateMessageFromServer({
b69ab31128 type: 'operationProgress',
b69ab31129 kind: 'spawn',
b69ab31130 id: gotoId,
b69ab31131 queue: [],
b69ab31132 });
b69ab31133 });
b69ab31134
b69ab31135 // then queue a metaedit
b69ab31136 act(() => CommitInfoTestUtils.clickToSelectCommit('aaaaaaaaaaaa'));
b69ab31137 act(() => openCommitInfoSidebar());
b69ab31138 act(() => {
b69ab31139 CommitInfoTestUtils.clickToEditTitle();
b69ab31140 CommitInfoTestUtils.clickToEditDescription();
b69ab31141 });
b69ab31142 act(() => {
b69ab31143 const title = CommitInfoTestUtils.getTitleEditor();
b69ab31144 userEvent.type(title, 'My Commit');
b69ab31145 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab31146 userEvent.type(desc, 'My description');
b69ab31147 });
b69ab31148
b69ab31149 act(() => {
b69ab31150 CommitInfoTestUtils.clickAmendMessageButton();
b69ab31151 });
b69ab31152 await waitFor(() => {
b69ab31153 expectMessageSentToServer({
b69ab31154 type: 'runOperation',
b69ab31155 operation: expect.objectContaining({
b69ab31156 args: expect.arrayContaining(['metaedit']),
b69ab31157 }),
b69ab31158 });
b69ab31159 });
b69ab31160 const amendMessage = utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation'));
b69ab31161 const amendMessageId = amendMessage.operation.id;
b69ab31162
b69ab31163 act(() => {
b69ab31164 simulateMessageFromServer({
b69ab31165 type: 'operationProgress',
b69ab31166 kind: 'queue',
b69ab31167 id: amendMessageId,
b69ab31168 queue: [amendMessageId],
b69ab31169 });
b69ab31170 });
b69ab31171
b69ab31172 CommitInfoTestUtils.expectIsNOTEditingTitle();
b69ab31173
b69ab31174 act(() => CommitInfoTestUtils.clickToSelectCommit('bbbbbbbbbbbb'));
b69ab31175
b69ab31176 // the goto fails
b69ab31177 act(() => {
b69ab31178 simulateMessageFromServer({
b69ab31179 type: 'operationProgress',
b69ab31180 kind: 'exit',
b69ab31181 exitCode: 1,
b69ab31182 id: gotoId,
b69ab31183 timestamp: 0,
b69ab31184 });
b69ab31185 });
b69ab31186
b69ab31187 // we recover the message
b69ab31188 await waitFor(() => {
b69ab31189 CommitInfoTestUtils.expectIsEditingTitle();
b69ab31190 const title = CommitInfoTestUtils.getTitleEditor();
b69ab31191 expect(title).toHaveValue('Commit AMy Commit');
b69ab31192 CommitInfoTestUtils.expectIsEditingDescription();
b69ab31193 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab31194 expect(desc.value).toContain('My description');
b69ab31195 });
b69ab31196 });
b69ab31197});