addons/isl/src/__tests__/succession.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, render} from '@testing-library/react';
b69ab319import userEvent from '@testing-library/user-event';
b69ab3110import App from '../App';
b69ab3111import {__TEST__} from '../CommitInfoView/CommitInfoState';
b69ab3112import {successionTracker} from '../SuccessionTracker';
b69ab3113import {CommitInfoTestUtils} from '../testQueries';
b69ab3114import {COMMIT, expectMessageSentToServer, resetTestMessages, simulateCommits} from '../testUtils';
b69ab3115
b69ab3116describe('succession', () => {
b69ab3117 beforeEach(() => {
b69ab3118 resetTestMessages();
b69ab3119 render(<App />);
b69ab3120 act(() => {
b69ab3121 expectMessageSentToServer({
b69ab3122 type: 'subscribe',
b69ab3123 kind: 'smartlogCommits',
b69ab3124 subscriptionID: expect.anything(),
b69ab3125 });
b69ab3126 simulateCommits({
b69ab3127 value: [
b69ab3128 COMMIT('1', 'Commit 1', '0', {phase: 'public'}),
b69ab3129 COMMIT('a', 'Commit A', '1'),
b69ab3130 COMMIT('b', 'Commit B', 'a', {isDot: true}),
b69ab3131 COMMIT('c', 'Commit C', 'b'),
b69ab3132 ],
b69ab3133 });
b69ab3134 });
b69ab3135 });
b69ab3136 afterEach(() => {
b69ab3137 successionTracker.clear();
b69ab3138 __TEST__.renewEditedCommitMessageSuccessionSubscription();
b69ab3139 });
b69ab3140
b69ab3141 describe('edited commit message', () => {
b69ab3142 it('uses succession to maintain edited commit message', () => {
b69ab3143 act(() => {
b69ab3144 CommitInfoTestUtils.clickToEditTitle();
b69ab3145 CommitInfoTestUtils.clickToEditDescription();
b69ab3146 });
b69ab3147
b69ab3148 CommitInfoTestUtils.expectIsEditingTitle();
b69ab3149 CommitInfoTestUtils.expectIsEditingDescription();
b69ab3150
b69ab3151 act(() => {
b69ab3152 userEvent.type(CommitInfoTestUtils.getTitleEditor(), ' modified!');
b69ab3153 userEvent.type(CommitInfoTestUtils.getDescriptionEditor(), 'my description');
b69ab3154 });
b69ab3155
b69ab3156 act(() => {
b69ab3157 simulateCommits({
b69ab3158 value: [
b69ab3159 COMMIT('1', 'Commit 1', '0', {phase: 'public'}),
b69ab3160 COMMIT('a2', 'Commit A', '1', {closestPredecessors: ['a']}),
b69ab3161 COMMIT('b2', 'Commit B', 'a2', {isDot: true, closestPredecessors: ['b']}),
b69ab3162 COMMIT('c2', 'Commit C', 'b2', {closestPredecessors: ['c']}),
b69ab3163 ],
b69ab3164 });
b69ab3165 });
b69ab3166
b69ab3167 CommitInfoTestUtils.expectIsEditingTitle();
b69ab3168 CommitInfoTestUtils.expectIsEditingDescription();
b69ab3169
b69ab3170 expect(
b69ab3171 CommitInfoTestUtils.withinCommitInfo().getByText('Commit B modified!'),
b69ab3172 ).toBeInTheDocument();
b69ab3173 expect(
b69ab3174 CommitInfoTestUtils.withinCommitInfo().getByText('my description'),
b69ab3175 ).toBeInTheDocument();
b69ab3176 });
b69ab3177
b69ab3178 it('bug: does not propagate optimistic state message', () => {
b69ab3179 // load a set of commits with hash A as head. (without any edited message for A)
b69ab3180 // load a new set of commits, with hash A succeeded by hash A2.
b69ab3181 // ensure commit info view is editable.
b69ab3182
b69ab3183 act(() => {
b69ab3184 simulateCommits({
b69ab3185 value: [
b69ab3186 COMMIT('1', 'Commit 1', '0', {phase: 'public'}),
b69ab3187 COMMIT('x', 'Commit X', '1', {isDot: true}),
b69ab3188 ],
b69ab3189 });
b69ab3190 });
b69ab3191 act(() => {
b69ab3192 simulateCommits({
b69ab3193 value: [
b69ab3194 COMMIT('1', 'Commit 1', '0', {phase: 'public'}),
b69ab3195 COMMIT('x2', 'Commit X2', '1', {isDot: true, closestPredecessors: ['x']}),
b69ab3196 ],
b69ab3197 });
b69ab3198 });
b69ab3199
b69ab31100 expect(CommitInfoTestUtils.withinCommitInfo().getByText('Commit X2')).toBeInTheDocument();
b69ab31101
b69ab31102 // Resulting commit being viewed should be editable: clicking the edit buttons work.
b69ab31103 act(() => {
b69ab31104 CommitInfoTestUtils.clickToEditTitle();
b69ab31105 CommitInfoTestUtils.clickToEditDescription();
b69ab31106 });
b69ab31107 CommitInfoTestUtils.expectIsEditingTitle();
b69ab31108 CommitInfoTestUtils.expectIsEditingDescription();
b69ab31109 });
b69ab31110 });
b69ab31111
b69ab31112 describe('commit selection state', () => {
b69ab31113 it('uses succession to maintain commit selection', () => {
b69ab31114 CommitInfoTestUtils.clickToSelectCommit('c');
b69ab31115
b69ab31116 expect(CommitInfoTestUtils.withinCommitInfo().getByText('Commit C')).toBeInTheDocument();
b69ab31117
b69ab31118 act(() => {
b69ab31119 simulateCommits({
b69ab31120 value: [
b69ab31121 COMMIT('1', 'Commit 1', '0', {phase: 'public'}),
b69ab31122 COMMIT('a2', 'Commit A', '1', {closestPredecessors: ['a']}),
b69ab31123 COMMIT('b2', 'Commit B', 'a2', {isDot: true, closestPredecessors: ['b']}),
b69ab31124 COMMIT('c2', 'Commit C', 'b2', {closestPredecessors: ['c']}),
b69ab31125 ],
b69ab31126 });
b69ab31127 });
b69ab31128
b69ab31129 // Commit C is still selected, even though its hash changed
b69ab31130 expect(CommitInfoTestUtils.withinCommitInfo().getByText('Commit C')).toBeInTheDocument();
b69ab31131 });
b69ab31132 });
b69ab31133});