| 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, render} from '@testing-library/react'; |
| b69ab31 | | | 9 | import userEvent from '@testing-library/user-event'; |
| b69ab31 | | | 10 | import App from '../App'; |
| b69ab31 | | | 11 | import {__TEST__} from '../CommitInfoView/CommitInfoState'; |
| b69ab31 | | | 12 | import {successionTracker} from '../SuccessionTracker'; |
| b69ab31 | | | 13 | import {CommitInfoTestUtils} from '../testQueries'; |
| b69ab31 | | | 14 | import {COMMIT, expectMessageSentToServer, resetTestMessages, simulateCommits} from '../testUtils'; |
| b69ab31 | | | 15 | |
| b69ab31 | | | 16 | describe('succession', () => { |
| b69ab31 | | | 17 | beforeEach(() => { |
| b69ab31 | | | 18 | resetTestMessages(); |
| b69ab31 | | | 19 | render(<App />); |
| b69ab31 | | | 20 | act(() => { |
| b69ab31 | | | 21 | expectMessageSentToServer({ |
| b69ab31 | | | 22 | type: 'subscribe', |
| b69ab31 | | | 23 | kind: 'smartlogCommits', |
| b69ab31 | | | 24 | subscriptionID: expect.anything(), |
| b69ab31 | | | 25 | }); |
| b69ab31 | | | 26 | simulateCommits({ |
| b69ab31 | | | 27 | value: [ |
| b69ab31 | | | 28 | COMMIT('1', 'Commit 1', '0', {phase: 'public'}), |
| b69ab31 | | | 29 | COMMIT('a', 'Commit A', '1'), |
| b69ab31 | | | 30 | COMMIT('b', 'Commit B', 'a', {isDot: true}), |
| b69ab31 | | | 31 | COMMIT('c', 'Commit C', 'b'), |
| b69ab31 | | | 32 | ], |
| b69ab31 | | | 33 | }); |
| b69ab31 | | | 34 | }); |
| b69ab31 | | | 35 | }); |
| b69ab31 | | | 36 | afterEach(() => { |
| b69ab31 | | | 37 | successionTracker.clear(); |
| b69ab31 | | | 38 | __TEST__.renewEditedCommitMessageSuccessionSubscription(); |
| b69ab31 | | | 39 | }); |
| b69ab31 | | | 40 | |
| b69ab31 | | | 41 | describe('edited commit message', () => { |
| b69ab31 | | | 42 | it('uses succession to maintain edited commit message', () => { |
| b69ab31 | | | 43 | act(() => { |
| b69ab31 | | | 44 | CommitInfoTestUtils.clickToEditTitle(); |
| b69ab31 | | | 45 | CommitInfoTestUtils.clickToEditDescription(); |
| b69ab31 | | | 46 | }); |
| b69ab31 | | | 47 | |
| b69ab31 | | | 48 | CommitInfoTestUtils.expectIsEditingTitle(); |
| b69ab31 | | | 49 | CommitInfoTestUtils.expectIsEditingDescription(); |
| b69ab31 | | | 50 | |
| b69ab31 | | | 51 | act(() => { |
| b69ab31 | | | 52 | userEvent.type(CommitInfoTestUtils.getTitleEditor(), ' modified!'); |
| b69ab31 | | | 53 | userEvent.type(CommitInfoTestUtils.getDescriptionEditor(), 'my description'); |
| b69ab31 | | | 54 | }); |
| b69ab31 | | | 55 | |
| b69ab31 | | | 56 | act(() => { |
| b69ab31 | | | 57 | simulateCommits({ |
| b69ab31 | | | 58 | value: [ |
| b69ab31 | | | 59 | COMMIT('1', 'Commit 1', '0', {phase: 'public'}), |
| b69ab31 | | | 60 | COMMIT('a2', 'Commit A', '1', {closestPredecessors: ['a']}), |
| b69ab31 | | | 61 | COMMIT('b2', 'Commit B', 'a2', {isDot: true, closestPredecessors: ['b']}), |
| b69ab31 | | | 62 | COMMIT('c2', 'Commit C', 'b2', {closestPredecessors: ['c']}), |
| b69ab31 | | | 63 | ], |
| b69ab31 | | | 64 | }); |
| b69ab31 | | | 65 | }); |
| b69ab31 | | | 66 | |
| b69ab31 | | | 67 | CommitInfoTestUtils.expectIsEditingTitle(); |
| b69ab31 | | | 68 | CommitInfoTestUtils.expectIsEditingDescription(); |
| b69ab31 | | | 69 | |
| b69ab31 | | | 70 | expect( |
| b69ab31 | | | 71 | CommitInfoTestUtils.withinCommitInfo().getByText('Commit B modified!'), |
| b69ab31 | | | 72 | ).toBeInTheDocument(); |
| b69ab31 | | | 73 | expect( |
| b69ab31 | | | 74 | CommitInfoTestUtils.withinCommitInfo().getByText('my description'), |
| b69ab31 | | | 75 | ).toBeInTheDocument(); |
| b69ab31 | | | 76 | }); |
| b69ab31 | | | 77 | |
| b69ab31 | | | 78 | it('bug: does not propagate optimistic state message', () => { |
| b69ab31 | | | 79 | // load a set of commits with hash A as head. (without any edited message for A) |
| b69ab31 | | | 80 | // load a new set of commits, with hash A succeeded by hash A2. |
| b69ab31 | | | 81 | // ensure commit info view is editable. |
| b69ab31 | | | 82 | |
| b69ab31 | | | 83 | act(() => { |
| b69ab31 | | | 84 | simulateCommits({ |
| b69ab31 | | | 85 | value: [ |
| b69ab31 | | | 86 | COMMIT('1', 'Commit 1', '0', {phase: 'public'}), |
| b69ab31 | | | 87 | COMMIT('x', 'Commit X', '1', {isDot: true}), |
| b69ab31 | | | 88 | ], |
| b69ab31 | | | 89 | }); |
| b69ab31 | | | 90 | }); |
| b69ab31 | | | 91 | act(() => { |
| b69ab31 | | | 92 | simulateCommits({ |
| b69ab31 | | | 93 | value: [ |
| b69ab31 | | | 94 | COMMIT('1', 'Commit 1', '0', {phase: 'public'}), |
| b69ab31 | | | 95 | COMMIT('x2', 'Commit X2', '1', {isDot: true, closestPredecessors: ['x']}), |
| b69ab31 | | | 96 | ], |
| b69ab31 | | | 97 | }); |
| b69ab31 | | | 98 | }); |
| b69ab31 | | | 99 | |
| b69ab31 | | | 100 | expect(CommitInfoTestUtils.withinCommitInfo().getByText('Commit X2')).toBeInTheDocument(); |
| b69ab31 | | | 101 | |
| b69ab31 | | | 102 | // Resulting commit being viewed should be editable: clicking the edit buttons work. |
| b69ab31 | | | 103 | act(() => { |
| b69ab31 | | | 104 | CommitInfoTestUtils.clickToEditTitle(); |
| b69ab31 | | | 105 | CommitInfoTestUtils.clickToEditDescription(); |
| b69ab31 | | | 106 | }); |
| b69ab31 | | | 107 | CommitInfoTestUtils.expectIsEditingTitle(); |
| b69ab31 | | | 108 | CommitInfoTestUtils.expectIsEditingDescription(); |
| b69ab31 | | | 109 | }); |
| b69ab31 | | | 110 | }); |
| b69ab31 | | | 111 | |
| b69ab31 | | | 112 | describe('commit selection state', () => { |
| b69ab31 | | | 113 | it('uses succession to maintain commit selection', () => { |
| b69ab31 | | | 114 | CommitInfoTestUtils.clickToSelectCommit('c'); |
| b69ab31 | | | 115 | |
| b69ab31 | | | 116 | expect(CommitInfoTestUtils.withinCommitInfo().getByText('Commit C')).toBeInTheDocument(); |
| b69ab31 | | | 117 | |
| b69ab31 | | | 118 | act(() => { |
| b69ab31 | | | 119 | simulateCommits({ |
| b69ab31 | | | 120 | value: [ |
| b69ab31 | | | 121 | COMMIT('1', 'Commit 1', '0', {phase: 'public'}), |
| b69ab31 | | | 122 | COMMIT('a2', 'Commit A', '1', {closestPredecessors: ['a']}), |
| b69ab31 | | | 123 | COMMIT('b2', 'Commit B', 'a2', {isDot: true, closestPredecessors: ['b']}), |
| b69ab31 | | | 124 | COMMIT('c2', 'Commit C', 'b2', {closestPredecessors: ['c']}), |
| b69ab31 | | | 125 | ], |
| b69ab31 | | | 126 | }); |
| b69ab31 | | | 127 | }); |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | // Commit C is still selected, even though its hash changed |
| b69ab31 | | | 130 | expect(CommitInfoTestUtils.withinCommitInfo().getByText('Commit C')).toBeInTheDocument(); |
| b69ab31 | | | 131 | }); |
| b69ab31 | | | 132 | }); |
| b69ab31 | | | 133 | }); |