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