addons/isl/src/__tests__/optimisticRevset.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, waitFor, within} from '@testing-library/react';
b69ab319import userEvent from '@testing-library/user-event';
b69ab3110import App from '../App';
b69ab3111import {CommitInfoTestUtils} from '../testQueries';
b69ab3112import {
b69ab3113 closeCommitInfoSidebar,
b69ab3114 COMMIT,
b69ab3115 expectMessageSentToServer,
b69ab3116 resetTestMessages,
b69ab3117 simulateCommits,
b69ab3118 simulateUncommittedChangedFiles,
b69ab3119} from '../testUtils';
b69ab3120
b69ab3121describe('Optimistic Revset', () => {
b69ab3122 beforeEach(() => {
b69ab3123 resetTestMessages();
b69ab3124 render(<App />);
b69ab3125 act(() => {
b69ab3126 expectMessageSentToServer({
b69ab3127 type: 'subscribe',
b69ab3128 kind: 'smartlogCommits',
b69ab3129 subscriptionID: expect.anything(),
b69ab3130 });
b69ab3131 simulateUncommittedChangedFiles({
b69ab3132 value: [
b69ab3133 {path: 'file1.txt', status: 'M'},
b69ab3134 {path: 'file2.txt', status: 'A'},
b69ab3135 {path: 'file3.txt', status: 'R'},
b69ab3136 ],
b69ab3137 });
b69ab3138 simulateCommits({
b69ab3139 value: [
b69ab3140 COMMIT('2', 'master', '00', {phase: 'public', remoteBookmarks: ['remote/master']}),
b69ab3141 COMMIT('1', 'Commit 1', '0', {phase: 'public'}),
b69ab3142 COMMIT('a', 'Commit A', '1'),
b69ab3143 COMMIT('b', 'Commit B', 'a', {isDot: true}),
b69ab3144 ],
b69ab3145 });
b69ab3146 });
b69ab3147 });
b69ab3148
b69ab3149 const clickQuickCommit = async () => {
b69ab3150 const quickCommitButton = screen.getByTestId('quick-commit-button');
b69ab3151 act(() => {
b69ab3152 fireEvent.click(quickCommitButton);
b69ab3153 });
b69ab3154 await waitFor(() =>
b69ab3155 expectMessageSentToServer({
b69ab3156 type: 'runOperation',
b69ab3157 operation: expect.objectContaining({
b69ab3158 args: expect.arrayContaining(['commit']),
b69ab3159 }),
b69ab3160 }),
b69ab3161 );
b69ab3162 };
b69ab3163
b69ab3164 function rightClickAndChooseFromContextMenu(element: Element, choiceMatcher: string) {
b69ab3165 act(() => {
b69ab3166 fireEvent.contextMenu(element);
b69ab3167 });
b69ab3168 const choice = within(screen.getByTestId('context-menu-container')).getByText(choiceMatcher);
b69ab3169 expect(choice).not.toEqual(null);
b69ab3170 act(() => {
b69ab3171 fireEvent.click(choice);
b69ab3172 });
b69ab3173 }
b69ab3174
b69ab3175 it('after commit, uses revset to act on optimistic commit', async () => {
b69ab3176 act(() => {
b69ab3177 CommitInfoTestUtils.clickAmendMode();
b69ab3178 closeCommitInfoSidebar();
b69ab3179 });
b69ab3180
b69ab3181 const mockDate = new Date('2024-01-01T00:00:00.000Z');
b69ab3182 jest.spyOn(Date, 'now').mockImplementation(() => {
b69ab3183 return mockDate.valueOf();
b69ab3184 });
b69ab3185
b69ab3186 const quickInput = screen.getByTestId('quick-commit-title');
b69ab3187 act(() => {
b69ab3188 userEvent.type(quickInput, 'My Commit');
b69ab3189 });
b69ab3190 await clickQuickCommit();
b69ab3191 expectMessageSentToServer({
b69ab3192 type: 'runOperation',
b69ab3193 operation: expect.objectContaining({
b69ab3194 args: ['commit', '--addremove', '--message', 'My Commit'],
b69ab3195 }),
b69ab3196 });
b69ab3197
b69ab3198 await waitFor(() => {
b69ab3199 expect(screen.getByText('My Commit')).toBeInTheDocument();
b69ab31100 });
b69ab31101
b69ab31102 rightClickAndChooseFromContextMenu(screen.getByText('My Commit'), 'Hide Commit');
b69ab31103 fireEvent.click(screen.getByText('Hide'));
b69ab31104
b69ab31105 expectMessageSentToServer({
b69ab31106 type: 'runOperation',
b69ab31107 operation: expect.objectContaining({
b69ab31108 args: [
b69ab31109 'hide',
b69ab31110 '--rev',
b69ab31111 {
b69ab31112 type: 'optimistic-revset',
b69ab31113 revset: 'first(sort((children(b)-b) & date(">Mon, 01 Jan 2024 00:00:00 GMT"),date))',
b69ab31114 fake: 'OPTIMISTIC_COMMIT_b',
b69ab31115 },
b69ab31116 ],
b69ab31117 }),
b69ab31118 });
b69ab31119 });
b69ab31120});