addons/isl/src/__tests__/operations/amendOperation.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} from '../../testQueries';
b69ab3113import {
b69ab3114 COMMIT,
b69ab3115 expectMessageSentToServer,
b69ab3116 getLastMessageOfTypeSentToServer,
b69ab3117 openCommitInfoSidebar,
b69ab3118 resetTestMessages,
b69ab3119 simulateCommits,
b69ab3120 simulateMessageFromServer,
b69ab3121 simulateUncommittedChangedFiles,
b69ab3122} from '../../testUtils';
b69ab3123
b69ab3124describe('AmendOperation', () => {
b69ab3125 beforeEach(() => {
b69ab3126 resetTestMessages();
b69ab3127 render(<App />);
b69ab3128 act(() => {
b69ab3129 expectMessageSentToServer({
b69ab3130 type: 'subscribe',
b69ab3131 kind: 'smartlogCommits',
b69ab3132 subscriptionID: expect.anything(),
b69ab3133 });
b69ab3134 simulateUncommittedChangedFiles({
b69ab3135 value: [
b69ab3136 {path: 'file1.txt', status: 'M'},
b69ab3137 {path: 'file2.txt', status: 'A'},
b69ab3138 {path: 'file3.txt', status: 'R'},
b69ab3139 ],
b69ab3140 });
b69ab3141 simulateCommits({
b69ab3142 value: [
b69ab3143 COMMIT('1', 'Commit 1', '0', {phase: 'public'}),
b69ab3144 COMMIT('a', 'Commit A', '1'),
b69ab3145 COMMIT('b', 'Commit B', 'a', {isDot: true}),
b69ab3146 ],
b69ab3147 });
b69ab3148 });
b69ab3149 });
b69ab3150
b69ab3151 it('on error, restores edited commit message to try again', async () => {
b69ab3152 act(() => openCommitInfoSidebar());
b69ab3153 act(() => {
b69ab3154 CommitInfoTestUtils.clickToEditTitle();
b69ab3155 CommitInfoTestUtils.clickToEditDescription();
b69ab3156 });
b69ab3157 act(() => {
b69ab3158 const title = CommitInfoTestUtils.getTitleEditor();
b69ab3159 userEvent.type(title, 'My Commit');
b69ab3160 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab3161 userEvent.type(desc, 'My description');
b69ab3162 });
b69ab3163
b69ab3164 await CommitInfoTestUtils.clickAmendButton();
b69ab3165 const message = await waitFor(() =>
b69ab3166 utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')),
b69ab3167 );
b69ab3168 const id = message.operation.id;
b69ab3169
b69ab3170 CommitInfoTestUtils.expectIsNOTEditingTitle();
b69ab3171
b69ab3172 act(() => {
b69ab3173 simulateMessageFromServer({
b69ab3174 type: 'operationProgress',
b69ab3175 kind: 'exit',
b69ab3176 exitCode: 1,
b69ab3177 id,
b69ab3178 timestamp: 0,
b69ab3179 });
b69ab3180 });
b69ab3181
b69ab3182 waitFor(() => {
b69ab3183 CommitInfoTestUtils.expectIsEditingTitle();
b69ab3184 const title = CommitInfoTestUtils.getTitleEditor();
b69ab3185 expect(title).toHaveValue('My Commit');
b69ab3186 CommitInfoTestUtils.expectIsEditingDescription();
b69ab3187 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab3188 expect(desc).toHaveValue('My description');
b69ab3189 });
b69ab3190 });
b69ab3191
b69ab3192 it('on error, merges messages when restoring edited commit message to try again', async () => {
b69ab3193 act(() => openCommitInfoSidebar());
b69ab3194
b69ab3195 act(() => {
b69ab3196 CommitInfoTestUtils.clickToEditTitle();
b69ab3197 CommitInfoTestUtils.clickToEditDescription();
b69ab3198 });
b69ab3199 act(() => {
b69ab31100 const title = CommitInfoTestUtils.getTitleEditor();
b69ab31101 userEvent.type(title, 'My Commit');
b69ab31102 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab31103 userEvent.type(desc, 'My description');
b69ab31104 });
b69ab31105
b69ab31106 await CommitInfoTestUtils.clickAmendButton();
b69ab31107 const message = await waitFor(() =>
b69ab31108 utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')),
b69ab31109 );
b69ab31110 const id = message.operation.id;
b69ab31111
b69ab31112 CommitInfoTestUtils.expectIsNOTEditingTitle();
b69ab31113
b69ab31114 act(() => {
b69ab31115 openCommitInfoSidebar();
b69ab31116 });
b69ab31117 act(() => {
b69ab31118 CommitInfoTestUtils.clickToEditTitle();
b69ab31119 CommitInfoTestUtils.clickToEditDescription();
b69ab31120 });
b69ab31121 act(() => {
b69ab31122 const title = CommitInfoTestUtils.getTitleEditor();
b69ab31123 userEvent.type(title, 'other title');
b69ab31124 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab31125 userEvent.type(desc, 'other description');
b69ab31126 });
b69ab31127
b69ab31128 act(() => {
b69ab31129 simulateMessageFromServer({
b69ab31130 type: 'operationProgress',
b69ab31131 kind: 'exit',
b69ab31132 exitCode: 1,
b69ab31133 id,
b69ab31134 timestamp: 0,
b69ab31135 });
b69ab31136 });
b69ab31137
b69ab31138 waitFor(() => {
b69ab31139 CommitInfoTestUtils.expectIsEditingTitle();
b69ab31140 const title = CommitInfoTestUtils.getTitleEditor();
b69ab31141 expect(title).toHaveValue('other title, My Commit');
b69ab31142 CommitInfoTestUtils.expectIsEditingDescription();
b69ab31143 const desc = CommitInfoTestUtils.getDescriptionEditor();
b69ab31144 expect(desc).toHaveValue('other description, My description');
b69ab31145 });
b69ab31146 });
b69ab31147});