| 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, within} from '@testing-library/react'; |
| b69ab31 | | | 9 | import userEvent from '@testing-library/user-event'; |
| b69ab31 | | | 10 | import App from '../App'; |
| b69ab31 | | | 11 | import {CommitInfoTestUtils} from '../testQueries'; |
| b69ab31 | | | 12 | import { |
| b69ab31 | | | 13 | closeCommitInfoSidebar, |
| b69ab31 | | | 14 | COMMIT, |
| b69ab31 | | | 15 | expectMessageSentToServer, |
| b69ab31 | | | 16 | resetTestMessages, |
| b69ab31 | | | 17 | simulateCommits, |
| b69ab31 | | | 18 | simulateUncommittedChangedFiles, |
| b69ab31 | | | 19 | } from '../testUtils'; |
| b69ab31 | | | 20 | |
| b69ab31 | | | 21 | describe('Optimistic Revset', () => { |
| b69ab31 | | | 22 | beforeEach(() => { |
| b69ab31 | | | 23 | resetTestMessages(); |
| b69ab31 | | | 24 | render(<App />); |
| b69ab31 | | | 25 | act(() => { |
| b69ab31 | | | 26 | expectMessageSentToServer({ |
| b69ab31 | | | 27 | type: 'subscribe', |
| b69ab31 | | | 28 | kind: 'smartlogCommits', |
| b69ab31 | | | 29 | subscriptionID: expect.anything(), |
| b69ab31 | | | 30 | }); |
| b69ab31 | | | 31 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 32 | value: [ |
| b69ab31 | | | 33 | {path: 'file1.txt', status: 'M'}, |
| b69ab31 | | | 34 | {path: 'file2.txt', status: 'A'}, |
| b69ab31 | | | 35 | {path: 'file3.txt', status: 'R'}, |
| b69ab31 | | | 36 | ], |
| b69ab31 | | | 37 | }); |
| b69ab31 | | | 38 | simulateCommits({ |
| b69ab31 | | | 39 | value: [ |
| b69ab31 | | | 40 | COMMIT('2', 'master', '00', {phase: 'public', remoteBookmarks: ['remote/master']}), |
| b69ab31 | | | 41 | COMMIT('1', 'Commit 1', '0', {phase: 'public'}), |
| b69ab31 | | | 42 | COMMIT('a', 'Commit A', '1'), |
| b69ab31 | | | 43 | COMMIT('b', 'Commit B', 'a', {isDot: true}), |
| b69ab31 | | | 44 | ], |
| b69ab31 | | | 45 | }); |
| b69ab31 | | | 46 | }); |
| b69ab31 | | | 47 | }); |
| b69ab31 | | | 48 | |
| b69ab31 | | | 49 | const clickQuickCommit = async () => { |
| b69ab31 | | | 50 | const quickCommitButton = screen.getByTestId('quick-commit-button'); |
| b69ab31 | | | 51 | act(() => { |
| b69ab31 | | | 52 | fireEvent.click(quickCommitButton); |
| b69ab31 | | | 53 | }); |
| b69ab31 | | | 54 | await waitFor(() => |
| b69ab31 | | | 55 | expectMessageSentToServer({ |
| b69ab31 | | | 56 | type: 'runOperation', |
| b69ab31 | | | 57 | operation: expect.objectContaining({ |
| b69ab31 | | | 58 | args: expect.arrayContaining(['commit']), |
| b69ab31 | | | 59 | }), |
| b69ab31 | | | 60 | }), |
| b69ab31 | | | 61 | ); |
| b69ab31 | | | 62 | }; |
| b69ab31 | | | 63 | |
| b69ab31 | | | 64 | function rightClickAndChooseFromContextMenu(element: Element, choiceMatcher: string) { |
| b69ab31 | | | 65 | act(() => { |
| b69ab31 | | | 66 | fireEvent.contextMenu(element); |
| b69ab31 | | | 67 | }); |
| b69ab31 | | | 68 | const choice = within(screen.getByTestId('context-menu-container')).getByText(choiceMatcher); |
| b69ab31 | | | 69 | expect(choice).not.toEqual(null); |
| b69ab31 | | | 70 | act(() => { |
| b69ab31 | | | 71 | fireEvent.click(choice); |
| b69ab31 | | | 72 | }); |
| b69ab31 | | | 73 | } |
| b69ab31 | | | 74 | |
| b69ab31 | | | 75 | it('after commit, uses revset to act on optimistic commit', async () => { |
| b69ab31 | | | 76 | act(() => { |
| b69ab31 | | | 77 | CommitInfoTestUtils.clickAmendMode(); |
| b69ab31 | | | 78 | closeCommitInfoSidebar(); |
| b69ab31 | | | 79 | }); |
| b69ab31 | | | 80 | |
| b69ab31 | | | 81 | const mockDate = new Date('2024-01-01T00:00:00.000Z'); |
| b69ab31 | | | 82 | jest.spyOn(Date, 'now').mockImplementation(() => { |
| b69ab31 | | | 83 | return mockDate.valueOf(); |
| b69ab31 | | | 84 | }); |
| b69ab31 | | | 85 | |
| b69ab31 | | | 86 | const quickInput = screen.getByTestId('quick-commit-title'); |
| b69ab31 | | | 87 | act(() => { |
| b69ab31 | | | 88 | userEvent.type(quickInput, 'My Commit'); |
| b69ab31 | | | 89 | }); |
| b69ab31 | | | 90 | await clickQuickCommit(); |
| b69ab31 | | | 91 | expectMessageSentToServer({ |
| b69ab31 | | | 92 | type: 'runOperation', |
| b69ab31 | | | 93 | operation: expect.objectContaining({ |
| b69ab31 | | | 94 | args: ['commit', '--addremove', '--message', 'My Commit'], |
| b69ab31 | | | 95 | }), |
| b69ab31 | | | 96 | }); |
| b69ab31 | | | 97 | |
| b69ab31 | | | 98 | await waitFor(() => { |
| b69ab31 | | | 99 | expect(screen.getByText('My Commit')).toBeInTheDocument(); |
| b69ab31 | | | 100 | }); |
| b69ab31 | | | 101 | |
| b69ab31 | | | 102 | rightClickAndChooseFromContextMenu(screen.getByText('My Commit'), 'Hide Commit'); |
| b69ab31 | | | 103 | fireEvent.click(screen.getByText('Hide')); |
| b69ab31 | | | 104 | |
| b69ab31 | | | 105 | expectMessageSentToServer({ |
| b69ab31 | | | 106 | type: 'runOperation', |
| b69ab31 | | | 107 | operation: expect.objectContaining({ |
| b69ab31 | | | 108 | args: [ |
| b69ab31 | | | 109 | 'hide', |
| b69ab31 | | | 110 | '--rev', |
| b69ab31 | | | 111 | { |
| b69ab31 | | | 112 | type: 'optimistic-revset', |
| b69ab31 | | | 113 | revset: 'first(sort((children(b)-b) & date(">Mon, 01 Jan 2024 00:00:00 GMT"),date))', |
| b69ab31 | | | 114 | fake: 'OPTIMISTIC_COMMIT_b', |
| b69ab31 | | | 115 | }, |
| b69ab31 | | | 116 | ], |
| b69ab31 | | | 117 | }), |
| b69ab31 | | | 118 | }); |
| b69ab31 | | | 119 | }); |
| b69ab31 | | | 120 | }); |