| 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 | |
| 8 | import {act, fireEvent, render, screen} from '@testing-library/react'; |
| 9 | import App from '../App'; |
| 10 | import { |
| 11 | closeCommitInfoSidebar, |
| 12 | COMMIT, |
| 13 | dragAndDropCommits, |
| 14 | resetTestMessages, |
| 15 | simulateCommits, |
| 16 | } from '../testUtils'; |
| 17 | |
| 18 | describe('focus mode', () => { |
| 19 | const COMMITS = [ |
| 20 | COMMIT('3', 'another public branch', '0', { |
| 21 | phase: 'public', |
| 22 | remoteBookmarks: ['remote/stable'], |
| 23 | }), |
| 24 | COMMIT('y', 'Commit Y', 'x'), |
| 25 | COMMIT('x', 'Commit X', '2'), |
| 26 | COMMIT('c2', 'Commit C2', '2', {closestPredecessors: ['c']}), |
| 27 | COMMIT('2', 'another public branch', '0', { |
| 28 | phase: 'public', |
| 29 | remoteBookmarks: ['remote/master'], |
| 30 | }), |
| 31 | COMMIT('f', 'Commit F', 'e'), // after `.` still included |
| 32 | COMMIT('e', 'Commit E', 'd', {isDot: true}), |
| 33 | COMMIT('d', 'Commit D', 'c'), // branch |
| 34 | COMMIT('c', 'Commit C', 'b'), |
| 35 | COMMIT('b2', 'Commit B2', 'a', {closestPredecessors: ['b']}), // succeeded within this branch |
| 36 | COMMIT('b', 'Commit B', 'a'), |
| 37 | COMMIT('a', 'Commit A', '1'), |
| 38 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| 39 | ]; |
| 40 | |
| 41 | beforeEach(() => { |
| 42 | resetTestMessages(); |
| 43 | render(<App />); |
| 44 | |
| 45 | act(() => { |
| 46 | closeCommitInfoSidebar(); |
| 47 | simulateCommits({value: COMMITS}); |
| 48 | }); |
| 49 | }); |
| 50 | |
| 51 | const toggleFocusMode = () => { |
| 52 | const toggle = screen.getByTestId('focus-mode-toggle'); |
| 53 | fireEvent.click(toggle); |
| 54 | }; |
| 55 | |
| 56 | it('can set focus mode', () => { |
| 57 | toggleFocusMode(); |
| 58 | expect(screen.getByTestId('focus-mode-toggle').dataset.focusMode).toEqual('true'); |
| 59 | toggleFocusMode(); |
| 60 | expect(screen.getByTestId('focus-mode-toggle').dataset.focusMode).toEqual('false'); |
| 61 | }); |
| 62 | |
| 63 | it('hides commits outside your stack', () => { |
| 64 | expect(screen.getByText('remote/master')).toBeInTheDocument(); |
| 65 | expect(screen.getByText('remote/stable')).toBeInTheDocument(); |
| 66 | expect(screen.getByText('Commit A')).toBeInTheDocument(); |
| 67 | expect(screen.getByText('Commit B')).toBeInTheDocument(); |
| 68 | expect(screen.getByText('Commit B2')).toBeInTheDocument(); |
| 69 | expect(screen.getByText('Commit C')).toBeInTheDocument(); |
| 70 | expect(screen.getByText('Commit C2')).toBeInTheDocument(); |
| 71 | expect(screen.getByText('Commit D')).toBeInTheDocument(); |
| 72 | expect(screen.getByText('Commit E')).toBeInTheDocument(); |
| 73 | expect(screen.getByText('Commit F')).toBeInTheDocument(); |
| 74 | |
| 75 | expect(screen.getByText('Commit X')).toBeInTheDocument(); |
| 76 | expect(screen.getByText('Commit Y')).toBeInTheDocument(); |
| 77 | |
| 78 | toggleFocusMode(); |
| 79 | |
| 80 | expect(screen.getByText('remote/master')).toBeInTheDocument(); |
| 81 | expect(screen.getByText('remote/stable')).toBeInTheDocument(); |
| 82 | expect(screen.getByText('Commit A')).toBeInTheDocument(); |
| 83 | expect(screen.getByText('Commit B')).toBeInTheDocument(); |
| 84 | expect(screen.getByText('Commit B2')).toBeInTheDocument(); |
| 85 | expect(screen.getByText('Commit C')).toBeInTheDocument(); |
| 86 | expect(screen.getByText('Commit C2')).toBeInTheDocument(); |
| 87 | expect(screen.getByText('Commit D')).toBeInTheDocument(); |
| 88 | expect(screen.getByText('Commit E')).toBeInTheDocument(); |
| 89 | expect(screen.getByText('Commit F')).toBeInTheDocument(); |
| 90 | |
| 91 | expect(screen.queryByText('Commit X')).not.toBeInTheDocument(); |
| 92 | expect(screen.queryByText('Commit Y')).not.toBeInTheDocument(); |
| 93 | }); |
| 94 | |
| 95 | it('when on a public commit, hide stacks based on the same public commit', () => { |
| 96 | act(() => { |
| 97 | simulateCommits({ |
| 98 | value: [ |
| 99 | COMMIT('c', 'Commit C', '1'), |
| 100 | COMMIT('b', 'Commit B', '1'), |
| 101 | COMMIT('a', 'Commit A', '1'), |
| 102 | COMMIT('2', 'another public branch', '0', { |
| 103 | phase: 'public', |
| 104 | remoteBookmarks: ['remote/master'], |
| 105 | }), |
| 106 | COMMIT('1', 'some public base', '0', { |
| 107 | phase: 'public', |
| 108 | isDot: true, |
| 109 | remoteBookmarks: ['remote/stable'], |
| 110 | }), |
| 111 | ], |
| 112 | }); |
| 113 | }); |
| 114 | expect(screen.getByText('remote/master')).toBeInTheDocument(); |
| 115 | expect(screen.getByText('remote/stable')).toBeInTheDocument(); |
| 116 | expect(screen.getByText('Commit A')).toBeInTheDocument(); |
| 117 | expect(screen.getByText('Commit B')).toBeInTheDocument(); |
| 118 | expect(screen.getByText('Commit C')).toBeInTheDocument(); |
| 119 | |
| 120 | toggleFocusMode(); |
| 121 | |
| 122 | expect(screen.getByText('remote/master')).toBeInTheDocument(); |
| 123 | expect(screen.getByText('remote/stable')).toBeInTheDocument(); |
| 124 | expect(screen.queryByText('Commit A')).not.toBeInTheDocument(); |
| 125 | expect(screen.queryByText('Commit B')).not.toBeInTheDocument(); |
| 126 | expect(screen.queryByText('Commit C')).not.toBeInTheDocument(); |
| 127 | }); |
| 128 | |
| 129 | it('lets you drag and drop rebase commits outside the focus stack', () => { |
| 130 | jest.useFakeTimers(); |
| 131 | |
| 132 | toggleFocusMode(); |
| 133 | |
| 134 | dragAndDropCommits('f', '2'); |
| 135 | |
| 136 | expect(screen.getAllByText('Commit F')).toHaveLength(2); |
| 137 | expect(screen.getByText('Run Rebase')).toBeInTheDocument(); |
| 138 | jest.useRealTimers(); |
| 139 | }); |
| 140 | }); |
| 141 | |