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