addons/isl/src/__tests__/FocusMode.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 App from '../App';
b69ab3110import {
b69ab3111 closeCommitInfoSidebar,
b69ab3112 COMMIT,
b69ab3113 dragAndDropCommits,
b69ab3114 resetTestMessages,
b69ab3115 simulateCommits,
b69ab3116} from '../testUtils';
b69ab3117
b69ab3118describe('focus mode', () => {
b69ab3119 const COMMITS = [
b69ab3120 COMMIT('3', 'another public branch', '0', {
b69ab3121 phase: 'public',
b69ab3122 remoteBookmarks: ['remote/stable'],
b69ab3123 }),
b69ab3124 COMMIT('y', 'Commit Y', 'x'),
b69ab3125 COMMIT('x', 'Commit X', '2'),
b69ab3126 COMMIT('c2', 'Commit C2', '2', {closestPredecessors: ['c']}),
b69ab3127 COMMIT('2', 'another public branch', '0', {
b69ab3128 phase: 'public',
b69ab3129 remoteBookmarks: ['remote/master'],
b69ab3130 }),
b69ab3131 COMMIT('f', 'Commit F', 'e'), // after `.` still included
b69ab3132 COMMIT('e', 'Commit E', 'd', {isDot: true}),
b69ab3133 COMMIT('d', 'Commit D', 'c'), // branch
b69ab3134 COMMIT('c', 'Commit C', 'b'),
b69ab3135 COMMIT('b2', 'Commit B2', 'a', {closestPredecessors: ['b']}), // succeeded within this branch
b69ab3136 COMMIT('b', 'Commit B', 'a'),
b69ab3137 COMMIT('a', 'Commit A', '1'),
b69ab3138 COMMIT('1', 'some public base', '0', {phase: 'public'}),
b69ab3139 ];
b69ab3140
b69ab3141 beforeEach(() => {
b69ab3142 resetTestMessages();
b69ab3143 render(<App />);
b69ab3144
b69ab3145 act(() => {
b69ab3146 closeCommitInfoSidebar();
b69ab3147 simulateCommits({value: COMMITS});
b69ab3148 });
b69ab3149 });
b69ab3150
b69ab3151 const toggleFocusMode = () => {
b69ab3152 const toggle = screen.getByTestId('focus-mode-toggle');
b69ab3153 fireEvent.click(toggle);
b69ab3154 };
b69ab3155
b69ab3156 it('can set focus mode', () => {
b69ab3157 toggleFocusMode();
b69ab3158 expect(screen.getByTestId('focus-mode-toggle').dataset.focusMode).toEqual('true');
b69ab3159 toggleFocusMode();
b69ab3160 expect(screen.getByTestId('focus-mode-toggle').dataset.focusMode).toEqual('false');
b69ab3161 });
b69ab3162
b69ab3163 it('hides commits outside your stack', () => {
b69ab3164 expect(screen.getByText('remote/master')).toBeInTheDocument();
b69ab3165 expect(screen.getByText('remote/stable')).toBeInTheDocument();
b69ab3166 expect(screen.getByText('Commit A')).toBeInTheDocument();
b69ab3167 expect(screen.getByText('Commit B')).toBeInTheDocument();
b69ab3168 expect(screen.getByText('Commit B2')).toBeInTheDocument();
b69ab3169 expect(screen.getByText('Commit C')).toBeInTheDocument();
b69ab3170 expect(screen.getByText('Commit C2')).toBeInTheDocument();
b69ab3171 expect(screen.getByText('Commit D')).toBeInTheDocument();
b69ab3172 expect(screen.getByText('Commit E')).toBeInTheDocument();
b69ab3173 expect(screen.getByText('Commit F')).toBeInTheDocument();
b69ab3174
b69ab3175 expect(screen.getByText('Commit X')).toBeInTheDocument();
b69ab3176 expect(screen.getByText('Commit Y')).toBeInTheDocument();
b69ab3177
b69ab3178 toggleFocusMode();
b69ab3179
b69ab3180 expect(screen.getByText('remote/master')).toBeInTheDocument();
b69ab3181 expect(screen.getByText('remote/stable')).toBeInTheDocument();
b69ab3182 expect(screen.getByText('Commit A')).toBeInTheDocument();
b69ab3183 expect(screen.getByText('Commit B')).toBeInTheDocument();
b69ab3184 expect(screen.getByText('Commit B2')).toBeInTheDocument();
b69ab3185 expect(screen.getByText('Commit C')).toBeInTheDocument();
b69ab3186 expect(screen.getByText('Commit C2')).toBeInTheDocument();
b69ab3187 expect(screen.getByText('Commit D')).toBeInTheDocument();
b69ab3188 expect(screen.getByText('Commit E')).toBeInTheDocument();
b69ab3189 expect(screen.getByText('Commit F')).toBeInTheDocument();
b69ab3190
b69ab3191 expect(screen.queryByText('Commit X')).not.toBeInTheDocument();
b69ab3192 expect(screen.queryByText('Commit Y')).not.toBeInTheDocument();
b69ab3193 });
b69ab3194
b69ab3195 it('when on a public commit, hide stacks based on the same public commit', () => {
b69ab3196 act(() => {
b69ab3197 simulateCommits({
b69ab3198 value: [
b69ab3199 COMMIT('c', 'Commit C', '1'),
b69ab31100 COMMIT('b', 'Commit B', '1'),
b69ab31101 COMMIT('a', 'Commit A', '1'),
b69ab31102 COMMIT('2', 'another public branch', '0', {
b69ab31103 phase: 'public',
b69ab31104 remoteBookmarks: ['remote/master'],
b69ab31105 }),
b69ab31106 COMMIT('1', 'some public base', '0', {
b69ab31107 phase: 'public',
b69ab31108 isDot: true,
b69ab31109 remoteBookmarks: ['remote/stable'],
b69ab31110 }),
b69ab31111 ],
b69ab31112 });
b69ab31113 });
b69ab31114 expect(screen.getByText('remote/master')).toBeInTheDocument();
b69ab31115 expect(screen.getByText('remote/stable')).toBeInTheDocument();
b69ab31116 expect(screen.getByText('Commit A')).toBeInTheDocument();
b69ab31117 expect(screen.getByText('Commit B')).toBeInTheDocument();
b69ab31118 expect(screen.getByText('Commit C')).toBeInTheDocument();
b69ab31119
b69ab31120 toggleFocusMode();
b69ab31121
b69ab31122 expect(screen.getByText('remote/master')).toBeInTheDocument();
b69ab31123 expect(screen.getByText('remote/stable')).toBeInTheDocument();
b69ab31124 expect(screen.queryByText('Commit A')).not.toBeInTheDocument();
b69ab31125 expect(screen.queryByText('Commit B')).not.toBeInTheDocument();
b69ab31126 expect(screen.queryByText('Commit C')).not.toBeInTheDocument();
b69ab31127 });
b69ab31128
b69ab31129 it('lets you drag and drop rebase commits outside the focus stack', () => {
b69ab31130 jest.useFakeTimers();
b69ab31131
b69ab31132 toggleFocusMode();
b69ab31133
b69ab31134 dragAndDropCommits('f', '2');
b69ab31135
b69ab31136 expect(screen.getAllByText('Commit F')).toHaveLength(2);
b69ab31137 expect(screen.getByText('Run Rebase')).toBeInTheDocument();
b69ab31138 jest.useRealTimers();
b69ab31139 });
b69ab31140});