addons/isl/src/__tests__/DownloadCommits.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, waitFor} from '@testing-library/react';
b69ab319import userEvent from '@testing-library/user-event';
b69ab3110import * as utils from 'shared/utils';
b69ab3111import App from '../App';
b69ab3112import {
b69ab3113 closeCommitInfoSidebar,
b69ab3114 COMMIT,
b69ab3115 expectMessageSentToServer,
b69ab3116 getLastMessageOfTypeSentToServer,
b69ab3117 resetTestMessages,
b69ab3118 simulateCommits,
b69ab3119 simulateMessageFromServer,
b69ab3120 TEST_COMMIT_HISTORY,
b69ab3121} from '../testUtils';
b69ab3122import {CommandRunner} from '../types';
b69ab3123
b69ab3124describe('Download Commits', () => {
b69ab3125 beforeEach(() => {
b69ab3126 resetTestMessages();
b69ab3127 render(<App />);
b69ab3128
b69ab3129 act(() => {
b69ab3130 closeCommitInfoSidebar();
b69ab3131 simulateCommits({value: TEST_COMMIT_HISTORY});
b69ab3132 });
b69ab3133 });
b69ab3134
b69ab3135 it('starts focused', () => {
b69ab3136 fireEvent.click(screen.getByTestId('download-commits-tooltip-button'));
b69ab3137
b69ab3138 expect(screen.getByTestId('download-commits-input')).toHaveFocus();
b69ab3139 });
b69ab3140
b69ab3141 it('runs operation', () => {
b69ab3142 fireEvent.click(screen.getByTestId('download-commits-tooltip-button'));
b69ab3143
b69ab3144 act(() => {
b69ab3145 userEvent.type(screen.getByTestId('download-commits-input'), 'aaaaaa');
b69ab3146 });
b69ab3147
b69ab3148 fireEvent.click(screen.getByTestId('download-commit-button'));
b69ab3149 expectMessageSentToServer(
b69ab3150 expect.objectContaining({
b69ab3151 type: 'runOperation',
b69ab3152 }),
b69ab3153 );
b69ab3154 });
b69ab3155
b69ab3156 it('supports goto', async () => {
b69ab3157 fireEvent.click(screen.getByTestId('download-commits-tooltip-button'));
b69ab3158
b69ab3159 act(() => {
b69ab3160 userEvent.type(screen.getByTestId('download-commits-input'), 'aaaaaa');
b69ab3161 fireEvent.click(screen.getByText('Go to'));
b69ab3162 fireEvent.click(screen.getByText('Rebase to Stack Base'));
b69ab3163 });
b69ab3164
b69ab3165 fireEvent.click(screen.getByTestId('download-commit-button'));
b69ab3166
b69ab3167 const pullMessage = await waitFor(() =>
b69ab3168 utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')),
b69ab3169 );
b69ab3170 const pullId = pullMessage.operation.id;
b69ab3171
b69ab3172 expectMessageSentToServer({
b69ab3173 type: 'runOperation',
b69ab3174 operation: {
b69ab3175 args: ['pull', '--rev', {type: 'exact-revset', revset: 'aaaaaa'}],
b69ab3176 runner: CommandRunner.Sapling,
b69ab3177 trackEventName: 'PullRevOperation',
b69ab3178 id: pullId,
b69ab3179 },
b69ab3180 });
b69ab3181 act(() =>
b69ab3182 simulateMessageFromServer({
b69ab3183 type: 'operationProgress',
b69ab3184 id: pullId,
b69ab3185 kind: 'exit',
b69ab3186 exitCode: 0,
b69ab3187 timestamp: 0,
b69ab3188 }),
b69ab3189 );
b69ab3190 await waitFor(() => {
b69ab3191 expectMessageSentToServer({
b69ab3192 type: 'fetchLatestCommit',
b69ab3193 revset: 'aaaaaa',
b69ab3194 });
b69ab3195 });
b69ab3196 act(() =>
b69ab3197 simulateMessageFromServer({
b69ab3198 type: 'fetchedLatestCommit',
b69ab3199 revset: 'aaaaaa',
b69ab31100 info: {value: COMMIT('aaaaaa', 'Commit A', '0', {phase: 'draft'})},
b69ab31101 }),
b69ab31102 );
b69ab31103 await waitFor(() =>
b69ab31104 expectMessageSentToServer({
b69ab31105 type: 'runOperation',
b69ab31106 operation: {
b69ab31107 args: [
b69ab31108 'rebase',
b69ab31109 '-s',
b69ab31110 {type: 'exact-revset', revset: 'aaaaaa'},
b69ab31111 '-d',
b69ab31112 {type: 'succeedable-revset', revset: '1'},
b69ab31113 ],
b69ab31114 runner: CommandRunner.Sapling,
b69ab31115 trackEventName: 'RebaseOperation',
b69ab31116 id: expect.anything(),
b69ab31117 },
b69ab31118 }),
b69ab31119 );
b69ab31120 expectMessageSentToServer({
b69ab31121 type: 'runOperation',
b69ab31122 operation: {
b69ab31123 args: ['goto', '--rev', {type: 'succeedable-revset', revset: 'aaaaaa'}],
b69ab31124 runner: CommandRunner.Sapling,
b69ab31125 trackEventName: 'GotoOperation',
b69ab31126 id: expect.anything(),
b69ab31127 },
b69ab31128 });
b69ab31129 });
b69ab31130
b69ab31131 it('keyboard shortcut support', () => {
b69ab31132 fireEvent.click(screen.getByTestId('download-commits-tooltip-button'));
b69ab31133
b69ab31134 act(() => {
b69ab31135 userEvent.type(screen.getByTestId('download-commits-input'), '{cmd}aaa{enter}{/cmd}');
b69ab31136 });
b69ab31137
b69ab31138 expectMessageSentToServer(
b69ab31139 expect.objectContaining({
b69ab31140 type: 'runOperation',
b69ab31141 operation: expect.objectContaining({
b69ab31142 args: expect.arrayContaining([{type: 'exact-revset', revset: 'aaa'}]),
b69ab31143 }),
b69ab31144 }),
b69ab31145 );
b69ab31146 });
b69ab31147});