addons/isl/src/__tests__/Bookmarks.test.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {act, fireEvent, render, screen} from '@testing-library/react';
b69ab319import userEvent from '@testing-library/user-event';
b69ab3110import App from '../App';
b69ab3111import {
b69ab3112 closeCommitInfoSidebar,
b69ab3113 COMMIT,
b69ab3114 expectMessageSentToServer,
b69ab3115 resetTestMessages,
b69ab3116 simulateCommits,
b69ab3117 TEST_COMMIT_HISTORY,
b69ab3118} from '../testUtils';
b69ab3119
b69ab3120/*eslint-disable @typescript-eslint/no-non-null-assertion */
b69ab3121
b69ab3122describe('bookmarks', () => {
b69ab3123 beforeEach(() => {
b69ab3124 resetTestMessages();
b69ab3125 render(<App />);
b69ab3126 act(() => {
b69ab3127 closeCommitInfoSidebar();
b69ab3128 expectMessageSentToServer({
b69ab3129 type: 'subscribe',
b69ab3130 kind: 'smartlogCommits',
b69ab3131 subscriptionID: expect.anything(),
b69ab3132 });
b69ab3133 simulateCommits({
b69ab3134 value: TEST_COMMIT_HISTORY,
b69ab3135 });
b69ab3136 });
b69ab3137 });
b69ab3138
b69ab3139 it('lets you create bookmarks', () => {
b69ab3140 act(() => {
b69ab3141 fireEvent.contextMenu(screen.getByText('Commit A'));
b69ab3142 });
b69ab3143 act(() => {
b69ab3144 fireEvent.click(screen.getByText('Create Bookmark...'));
b69ab3145 });
b69ab3146
b69ab3147 expect(screen.getByLabelText('Bookmark Name')).toBeInTheDocument();
b69ab3148 expect(screen.getByLabelText('Bookmark Name')).toHaveFocus();
b69ab3149 expect(screen.getByText('Create')).toBeInTheDocument();
b69ab3150 expect(screen.getByText('Create')).toBeDisabled();
b69ab3151 act(() => {
b69ab3152 userEvent.type(screen.getByLabelText('Bookmark Name'), 'testBook');
b69ab3153 });
b69ab3154 expect(screen.getByText('Create')).not.toBeDisabled();
b69ab3155 fireEvent.click(screen.getByText('Create'));
b69ab3156
b69ab3157 expectMessageSentToServer({
b69ab3158 type: 'runOperation',
b69ab3159 operation: expect.objectContaining({
b69ab3160 args: ['bookmark', 'testBook', '--rev', {type: 'succeedable-revset', revset: 'a'}],
b69ab3161 }),
b69ab3162 });
b69ab3163 });
b69ab3164
b69ab3165 it('lets you delete bookmarks', () => {
b69ab3166 act(() => {
b69ab3167 simulateCommits({
b69ab3168 value: [
b69ab3169 COMMIT('1', 'public commit', '0', {phase: 'public'}),
b69ab3170 COMMIT('a', 'Commit A', '1'),
b69ab3171 COMMIT('b', 'Commit B', 'a', {isDot: true, bookmarks: ['myBookmark']}),
b69ab3172 ],
b69ab3173 });
b69ab3174 });
b69ab3175 expect(screen.getByText('myBookmark')).toBeInTheDocument();
b69ab3176 act(() => {
b69ab3177 fireEvent.contextMenu(screen.getByText('myBookmark'));
b69ab3178 });
b69ab3179 const button = screen.getByText('Delete Bookmark "myBookmark"');
b69ab3180 expect(button).toBeInTheDocument();
b69ab3181 fireEvent.click(button);
b69ab3182
b69ab3183 expectMessageSentToServer({
b69ab3184 type: 'runOperation',
b69ab3185 operation: expect.objectContaining({
b69ab3186 args: ['bookmark', '--delete', 'myBookmark'],
b69ab3187 }),
b69ab3188 });
b69ab3189 });
b69ab3190});