| 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} from '@testing-library/react'; |
| b69ab31 | | | 9 | import userEvent from '@testing-library/user-event'; |
| b69ab31 | | | 10 | import App from '../App'; |
| b69ab31 | | | 11 | import { |
| b69ab31 | | | 12 | closeCommitInfoSidebar, |
| b69ab31 | | | 13 | COMMIT, |
| b69ab31 | | | 14 | expectMessageSentToServer, |
| b69ab31 | | | 15 | resetTestMessages, |
| b69ab31 | | | 16 | simulateCommits, |
| b69ab31 | | | 17 | TEST_COMMIT_HISTORY, |
| b69ab31 | | | 18 | } from '../testUtils'; |
| b69ab31 | | | 19 | |
| b69ab31 | | | 20 | /*eslint-disable @typescript-eslint/no-non-null-assertion */ |
| b69ab31 | | | 21 | |
| b69ab31 | | | 22 | describe('bookmarks', () => { |
| b69ab31 | | | 23 | beforeEach(() => { |
| b69ab31 | | | 24 | resetTestMessages(); |
| b69ab31 | | | 25 | render(<App />); |
| b69ab31 | | | 26 | act(() => { |
| b69ab31 | | | 27 | closeCommitInfoSidebar(); |
| b69ab31 | | | 28 | expectMessageSentToServer({ |
| b69ab31 | | | 29 | type: 'subscribe', |
| b69ab31 | | | 30 | kind: 'smartlogCommits', |
| b69ab31 | | | 31 | subscriptionID: expect.anything(), |
| b69ab31 | | | 32 | }); |
| b69ab31 | | | 33 | simulateCommits({ |
| b69ab31 | | | 34 | value: TEST_COMMIT_HISTORY, |
| b69ab31 | | | 35 | }); |
| b69ab31 | | | 36 | }); |
| b69ab31 | | | 37 | }); |
| b69ab31 | | | 38 | |
| b69ab31 | | | 39 | it('lets you create bookmarks', () => { |
| b69ab31 | | | 40 | act(() => { |
| b69ab31 | | | 41 | fireEvent.contextMenu(screen.getByText('Commit A')); |
| b69ab31 | | | 42 | }); |
| b69ab31 | | | 43 | act(() => { |
| b69ab31 | | | 44 | fireEvent.click(screen.getByText('Create Bookmark...')); |
| b69ab31 | | | 45 | }); |
| b69ab31 | | | 46 | |
| b69ab31 | | | 47 | expect(screen.getByLabelText('Bookmark Name')).toBeInTheDocument(); |
| b69ab31 | | | 48 | expect(screen.getByLabelText('Bookmark Name')).toHaveFocus(); |
| b69ab31 | | | 49 | expect(screen.getByText('Create')).toBeInTheDocument(); |
| b69ab31 | | | 50 | expect(screen.getByText('Create')).toBeDisabled(); |
| b69ab31 | | | 51 | act(() => { |
| b69ab31 | | | 52 | userEvent.type(screen.getByLabelText('Bookmark Name'), 'testBook'); |
| b69ab31 | | | 53 | }); |
| b69ab31 | | | 54 | expect(screen.getByText('Create')).not.toBeDisabled(); |
| b69ab31 | | | 55 | fireEvent.click(screen.getByText('Create')); |
| b69ab31 | | | 56 | |
| b69ab31 | | | 57 | expectMessageSentToServer({ |
| b69ab31 | | | 58 | type: 'runOperation', |
| b69ab31 | | | 59 | operation: expect.objectContaining({ |
| b69ab31 | | | 60 | args: ['bookmark', 'testBook', '--rev', {type: 'succeedable-revset', revset: 'a'}], |
| b69ab31 | | | 61 | }), |
| b69ab31 | | | 62 | }); |
| b69ab31 | | | 63 | }); |
| b69ab31 | | | 64 | |
| b69ab31 | | | 65 | it('lets you delete bookmarks', () => { |
| b69ab31 | | | 66 | act(() => { |
| b69ab31 | | | 67 | simulateCommits({ |
| b69ab31 | | | 68 | value: [ |
| b69ab31 | | | 69 | COMMIT('1', 'public commit', '0', {phase: 'public'}), |
| b69ab31 | | | 70 | COMMIT('a', 'Commit A', '1'), |
| b69ab31 | | | 71 | COMMIT('b', 'Commit B', 'a', {isDot: true, bookmarks: ['myBookmark']}), |
| b69ab31 | | | 72 | ], |
| b69ab31 | | | 73 | }); |
| b69ab31 | | | 74 | }); |
| b69ab31 | | | 75 | expect(screen.getByText('myBookmark')).toBeInTheDocument(); |
| b69ab31 | | | 76 | act(() => { |
| b69ab31 | | | 77 | fireEvent.contextMenu(screen.getByText('myBookmark')); |
| b69ab31 | | | 78 | }); |
| b69ab31 | | | 79 | const button = screen.getByText('Delete Bookmark "myBookmark"'); |
| b69ab31 | | | 80 | expect(button).toBeInTheDocument(); |
| b69ab31 | | | 81 | fireEvent.click(button); |
| b69ab31 | | | 82 | |
| b69ab31 | | | 83 | expectMessageSentToServer({ |
| b69ab31 | | | 84 | type: 'runOperation', |
| b69ab31 | | | 85 | operation: expect.objectContaining({ |
| b69ab31 | | | 86 | args: ['bookmark', '--delete', 'myBookmark'], |
| b69ab31 | | | 87 | }), |
| b69ab31 | | | 88 | }); |
| b69ab31 | | | 89 | }); |
| b69ab31 | | | 90 | }); |