4.0 KB148 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import {act, fireEvent, render, screen, waitFor} from '@testing-library/react';
9import userEvent from '@testing-library/user-event';
10import * as utils from 'shared/utils';
11import App from '../App';
12import {
13 closeCommitInfoSidebar,
14 COMMIT,
15 expectMessageSentToServer,
16 getLastMessageOfTypeSentToServer,
17 resetTestMessages,
18 simulateCommits,
19 simulateMessageFromServer,
20 TEST_COMMIT_HISTORY,
21} from '../testUtils';
22import {CommandRunner} from '../types';
23
24describe('Download Commits', () => {
25 beforeEach(() => {
26 resetTestMessages();
27 render(<App />);
28
29 act(() => {
30 closeCommitInfoSidebar();
31 simulateCommits({value: TEST_COMMIT_HISTORY});
32 });
33 });
34
35 it('starts focused', () => {
36 fireEvent.click(screen.getByTestId('download-commits-tooltip-button'));
37
38 expect(screen.getByTestId('download-commits-input')).toHaveFocus();
39 });
40
41 it('runs operation', () => {
42 fireEvent.click(screen.getByTestId('download-commits-tooltip-button'));
43
44 act(() => {
45 userEvent.type(screen.getByTestId('download-commits-input'), 'aaaaaa');
46 });
47
48 fireEvent.click(screen.getByTestId('download-commit-button'));
49 expectMessageSentToServer(
50 expect.objectContaining({
51 type: 'runOperation',
52 }),
53 );
54 });
55
56 it('supports goto', async () => {
57 fireEvent.click(screen.getByTestId('download-commits-tooltip-button'));
58
59 act(() => {
60 userEvent.type(screen.getByTestId('download-commits-input'), 'aaaaaa');
61 fireEvent.click(screen.getByText('Go to'));
62 fireEvent.click(screen.getByText('Rebase to Stack Base'));
63 });
64
65 fireEvent.click(screen.getByTestId('download-commit-button'));
66
67 const pullMessage = await waitFor(() =>
68 utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')),
69 );
70 const pullId = pullMessage.operation.id;
71
72 expectMessageSentToServer({
73 type: 'runOperation',
74 operation: {
75 args: ['pull', '--rev', {type: 'exact-revset', revset: 'aaaaaa'}],
76 runner: CommandRunner.Sapling,
77 trackEventName: 'PullRevOperation',
78 id: pullId,
79 },
80 });
81 act(() =>
82 simulateMessageFromServer({
83 type: 'operationProgress',
84 id: pullId,
85 kind: 'exit',
86 exitCode: 0,
87 timestamp: 0,
88 }),
89 );
90 await waitFor(() => {
91 expectMessageSentToServer({
92 type: 'fetchLatestCommit',
93 revset: 'aaaaaa',
94 });
95 });
96 act(() =>
97 simulateMessageFromServer({
98 type: 'fetchedLatestCommit',
99 revset: 'aaaaaa',
100 info: {value: COMMIT('aaaaaa', 'Commit A', '0', {phase: 'draft'})},
101 }),
102 );
103 await waitFor(() =>
104 expectMessageSentToServer({
105 type: 'runOperation',
106 operation: {
107 args: [
108 'rebase',
109 '-s',
110 {type: 'exact-revset', revset: 'aaaaaa'},
111 '-d',
112 {type: 'succeedable-revset', revset: '1'},
113 ],
114 runner: CommandRunner.Sapling,
115 trackEventName: 'RebaseOperation',
116 id: expect.anything(),
117 },
118 }),
119 );
120 expectMessageSentToServer({
121 type: 'runOperation',
122 operation: {
123 args: ['goto', '--rev', {type: 'succeedable-revset', revset: 'aaaaaa'}],
124 runner: CommandRunner.Sapling,
125 trackEventName: 'GotoOperation',
126 id: expect.anything(),
127 },
128 });
129 });
130
131 it('keyboard shortcut support', () => {
132 fireEvent.click(screen.getByTestId('download-commits-tooltip-button'));
133
134 act(() => {
135 userEvent.type(screen.getByTestId('download-commits-input'), '{cmd}aaa{enter}{/cmd}');
136 });
137
138 expectMessageSentToServer(
139 expect.objectContaining({
140 type: 'runOperation',
141 operation: expect.objectContaining({
142 args: expect.arrayContaining([{type: 'exact-revset', revset: 'aaa'}]),
143 }),
144 }),
145 );
146 });
147});
148