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