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