| 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, waitFor, within} from '@testing-library/react'; |
| b69ab31 | | | 9 | import App from '../App'; |
| b69ab31 | | | 10 | import {CommitInfoTestUtils, ignoreRTL} from '../testQueries'; |
| b69ab31 | | | 11 | import { |
| b69ab31 | | | 12 | closeCommitInfoSidebar, |
| b69ab31 | | | 13 | COMMIT, |
| b69ab31 | | | 14 | commitInfoIsOpen, |
| b69ab31 | | | 15 | expectMessageSentToServer, |
| b69ab31 | | | 16 | openCommitInfoSidebar, |
| b69ab31 | | | 17 | resetTestMessages, |
| b69ab31 | | | 18 | simulateCommits, |
| b69ab31 | | | 19 | simulateRepoConnected, |
| b69ab31 | | | 20 | simulateUncommittedChangedFiles, |
| b69ab31 | | | 21 | } from '../testUtils'; |
| b69ab31 | | | 22 | import {CommandRunner} from '../types'; |
| b69ab31 | | | 23 | |
| b69ab31 | | | 24 | describe('CommitTreeList', () => { |
| b69ab31 | | | 25 | beforeEach(() => { |
| b69ab31 | | | 26 | resetTestMessages(); |
| b69ab31 | | | 27 | }); |
| b69ab31 | | | 28 | |
| b69ab31 | | | 29 | it('shows loading spinner on mount', () => { |
| b69ab31 | | | 30 | render(<App />); |
| b69ab31 | | | 31 | |
| b69ab31 | | | 32 | expect(screen.getByTestId('loading-spinner')).toBeInTheDocument(); |
| b69ab31 | | | 33 | }); |
| b69ab31 | | | 34 | |
| b69ab31 | | | 35 | it('shows bug button even on error', () => { |
| b69ab31 | | | 36 | render(<App />); |
| b69ab31 | | | 37 | |
| b69ab31 | | | 38 | act(() => { |
| b69ab31 | | | 39 | simulateCommits({ |
| b69ab31 | | | 40 | error: new Error('invalid certificate'), |
| b69ab31 | | | 41 | }); |
| b69ab31 | | | 42 | }); |
| b69ab31 | | | 43 | |
| b69ab31 | | | 44 | expect(screen.getByTestId('bug-button')).toBeInTheDocument(); |
| b69ab31 | | | 45 | expect(screen.getByText('invalid certificate')).toBeInTheDocument(); |
| b69ab31 | | | 46 | }); |
| b69ab31 | | | 47 | |
| b69ab31 | | | 48 | describe('after commits loaded', () => { |
| b69ab31 | | | 49 | beforeEach(() => { |
| b69ab31 | | | 50 | render(<App />); |
| b69ab31 | | | 51 | act(() => { |
| b69ab31 | | | 52 | simulateRepoConnected(); |
| b69ab31 | | | 53 | closeCommitInfoSidebar(); |
| b69ab31 | | | 54 | expectMessageSentToServer({ |
| b69ab31 | | | 55 | type: 'subscribe', |
| b69ab31 | | | 56 | kind: 'smartlogCommits', |
| b69ab31 | | | 57 | subscriptionID: expect.anything(), |
| b69ab31 | | | 58 | }); |
| b69ab31 | | | 59 | simulateCommits({ |
| b69ab31 | | | 60 | value: [ |
| b69ab31 | | | 61 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 62 | COMMIT('a', 'My Commit', '1'), |
| b69ab31 | | | 63 | COMMIT('b', 'Another Commit', 'a', {isDot: true}), |
| b69ab31 | | | 64 | ], |
| b69ab31 | | | 65 | }); |
| b69ab31 | | | 66 | }); |
| b69ab31 | | | 67 | }); |
| b69ab31 | | | 68 | |
| b69ab31 | | | 69 | it('renders commits', () => { |
| b69ab31 | | | 70 | expect(screen.getByText('My Commit')).toBeInTheDocument(); |
| b69ab31 | | | 71 | expect(screen.getByText('Another Commit')).toBeInTheDocument(); |
| b69ab31 | | | 72 | expect(screen.queryByText('some public base')).not.toBeInTheDocument(); |
| b69ab31 | | | 73 | }); |
| b69ab31 | | | 74 | |
| b69ab31 | | | 75 | it('renders exactly one head', () => { |
| b69ab31 | | | 76 | expect(screen.getByText('You are here')).toBeInTheDocument(); |
| b69ab31 | | | 77 | }); |
| b69ab31 | | | 78 | |
| b69ab31 | | | 79 | describe('uncommitted changes', () => { |
| b69ab31 | | | 80 | beforeEach(() => { |
| b69ab31 | | | 81 | act(() => { |
| b69ab31 | | | 82 | expectMessageSentToServer({ |
| b69ab31 | | | 83 | type: 'subscribe', |
| b69ab31 | | | 84 | kind: 'uncommittedChanges', |
| b69ab31 | | | 85 | subscriptionID: expect.anything(), |
| b69ab31 | | | 86 | }); |
| b69ab31 | | | 87 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 88 | value: [ |
| b69ab31 | | | 89 | {path: 'src/file.js', status: 'M'}, |
| b69ab31 | | | 90 | {path: 'src/file_add.js', status: 'A'}, |
| b69ab31 | | | 91 | {path: 'src/file_removed.js', status: 'R'}, |
| b69ab31 | | | 92 | {path: 'src/file_untracked.js', status: '?'}, |
| b69ab31 | | | 93 | {path: 'src/file_missing.js', status: '!'}, |
| b69ab31 | | | 94 | ], |
| b69ab31 | | | 95 | }); |
| b69ab31 | | | 96 | }); |
| b69ab31 | | | 97 | }); |
| b69ab31 | | | 98 | |
| b69ab31 | | | 99 | it('renders uncommitted changes', () => { |
| b69ab31 | | | 100 | expect(screen.getByText(ignoreRTL('file.js'), {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 101 | expect(screen.getByText(ignoreRTL('file_add.js'), {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 102 | expect(screen.getByText(ignoreRTL('file_removed.js'), {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 103 | expect( |
| b69ab31 | | | 104 | screen.getByText(ignoreRTL('file_untracked.js'), {exact: false}), |
| b69ab31 | | | 105 | ).toBeInTheDocument(); |
| b69ab31 | | | 106 | expect(screen.getByText(ignoreRTL('file_missing.js'), {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 107 | }); |
| b69ab31 | | | 108 | |
| b69ab31 | | | 109 | it('shows quick commit button', () => { |
| b69ab31 | | | 110 | expect(screen.getByText('Commit')).toBeInTheDocument(); |
| b69ab31 | | | 111 | }); |
| b69ab31 | | | 112 | it('shows quick amend button only on non-public commits', () => { |
| b69ab31 | | | 113 | expect(screen.getByText('Amend')).toBeInTheDocument(); |
| b69ab31 | | | 114 | // checkout a public commit |
| b69ab31 | | | 115 | act(() => { |
| b69ab31 | | | 116 | simulateCommits({ |
| b69ab31 | | | 117 | value: [ |
| b69ab31 | | | 118 | COMMIT('1', 'some public base', '0', {phase: 'public', isDot: true}), |
| b69ab31 | | | 119 | COMMIT('a', 'My Commit', '1', {successorInfo: {hash: 'a2', type: 'land'}}), |
| b69ab31 | | | 120 | COMMIT('b', 'Another Commit', 'a'), |
| b69ab31 | | | 121 | ], |
| b69ab31 | | | 122 | }); |
| b69ab31 | | | 123 | }); |
| b69ab31 | | | 124 | // no longer see quick amend |
| b69ab31 | | | 125 | expect(screen.queryByText('Amend')).not.toBeInTheDocument(); |
| b69ab31 | | | 126 | }); |
| b69ab31 | | | 127 | |
| b69ab31 | | | 128 | it('shows file actions', () => { |
| b69ab31 | | | 129 | const fileActions = screen.getAllByTestId('file-actions'); |
| b69ab31 | | | 130 | expect(fileActions).toHaveLength(5); // 5 files |
| b69ab31 | | | 131 | const revertButtons = screen.getAllByTestId('file-revert-button'); |
| b69ab31 | | | 132 | expect(revertButtons).toHaveLength(3); // modified, removed, missing files can be reverted |
| b69ab31 | | | 133 | }); |
| b69ab31 | | | 134 | |
| b69ab31 | | | 135 | it('runs revert command when clicking revert button', async () => { |
| b69ab31 | | | 136 | const revertButtons = screen.getAllByTestId('file-revert-button'); |
| b69ab31 | | | 137 | jest.spyOn(window, 'confirm').mockImplementation(() => true); |
| b69ab31 | | | 138 | act(() => { |
| b69ab31 | | | 139 | fireEvent.click(revertButtons[0]); |
| b69ab31 | | | 140 | }); |
| b69ab31 | | | 141 | await waitFor(() => { |
| b69ab31 | | | 142 | expect(window.confirm).toHaveBeenCalled(); |
| b69ab31 | | | 143 | expectMessageSentToServer({ |
| b69ab31 | | | 144 | type: 'runOperation', |
| b69ab31 | | | 145 | operation: { |
| b69ab31 | | | 146 | args: ['revert', {type: 'repo-relative-file-list', paths: ['src/file.js']}], |
| b69ab31 | | | 147 | id: expect.anything(), |
| b69ab31 | | | 148 | runner: CommandRunner.Sapling, |
| b69ab31 | | | 149 | trackEventName: 'RevertOperation', |
| b69ab31 | | | 150 | }, |
| b69ab31 | | | 151 | }); |
| b69ab31 | | | 152 | }); |
| b69ab31 | | | 153 | }); |
| b69ab31 | | | 154 | |
| b69ab31 | | | 155 | describe('addremove', () => { |
| b69ab31 | | | 156 | it('hides addremove if all files tracked', () => { |
| b69ab31 | | | 157 | act(() => { |
| b69ab31 | | | 158 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 159 | value: [ |
| b69ab31 | | | 160 | {path: 'src/file.js', status: 'M'}, |
| b69ab31 | | | 161 | {path: 'src/file_add.js', status: 'A'}, |
| b69ab31 | | | 162 | {path: 'src/file_removed.js', status: 'R'}, |
| b69ab31 | | | 163 | ], |
| b69ab31 | | | 164 | }); |
| b69ab31 | | | 165 | }); |
| b69ab31 | | | 166 | expect(screen.queryByTestId('addremove-button')).not.toBeInTheDocument(); |
| b69ab31 | | | 167 | |
| b69ab31 | | | 168 | act(() => { |
| b69ab31 | | | 169 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 170 | value: [ |
| b69ab31 | | | 171 | {path: 'src/file.js', status: 'M'}, |
| b69ab31 | | | 172 | {path: 'src/file_add.js', status: 'A'}, |
| b69ab31 | | | 173 | {path: 'src/file_removed.js', status: 'R'}, |
| b69ab31 | | | 174 | {path: 'src/file_untracked.js', status: '?'}, |
| b69ab31 | | | 175 | {path: 'src/file_missing.js', status: '!'}, |
| b69ab31 | | | 176 | ], |
| b69ab31 | | | 177 | }); |
| b69ab31 | | | 178 | }); |
| b69ab31 | | | 179 | expect(screen.queryByTestId('addremove-button')).toBeInTheDocument(); |
| b69ab31 | | | 180 | }); |
| b69ab31 | | | 181 | |
| b69ab31 | | | 182 | it('runs addremove', async () => { |
| b69ab31 | | | 183 | const addremove = screen.getByTestId('addremove-button'); |
| b69ab31 | | | 184 | act(() => { |
| b69ab31 | | | 185 | fireEvent.click(addremove); |
| b69ab31 | | | 186 | }); |
| b69ab31 | | | 187 | await waitFor(() => { |
| b69ab31 | | | 188 | expectMessageSentToServer({ |
| b69ab31 | | | 189 | type: 'runOperation', |
| b69ab31 | | | 190 | operation: { |
| b69ab31 | | | 191 | args: ['addremove'], |
| b69ab31 | | | 192 | id: expect.anything(), |
| b69ab31 | | | 193 | runner: CommandRunner.Sapling, |
| b69ab31 | | | 194 | trackEventName: 'AddRemoveOperation', |
| b69ab31 | | | 195 | }, |
| b69ab31 | | | 196 | }); |
| b69ab31 | | | 197 | }); |
| b69ab31 | | | 198 | }); |
| b69ab31 | | | 199 | |
| b69ab31 | | | 200 | it('optimistically updates file statuses while addremove is running', async () => { |
| b69ab31 | | | 201 | const addremove = screen.getByTestId('addremove-button'); |
| b69ab31 | | | 202 | act(() => { |
| b69ab31 | | | 203 | fireEvent.click(addremove); |
| b69ab31 | | | 204 | }); |
| b69ab31 | | | 205 | await waitFor(() => { |
| b69ab31 | | | 206 | expectMessageSentToServer({ |
| b69ab31 | | | 207 | type: 'runOperation', |
| b69ab31 | | | 208 | operation: { |
| b69ab31 | | | 209 | args: ['addremove'], |
| b69ab31 | | | 210 | id: expect.anything(), |
| b69ab31 | | | 211 | runner: CommandRunner.Sapling, |
| b69ab31 | | | 212 | trackEventName: 'AddRemoveOperation', |
| b69ab31 | | | 213 | }, |
| b69ab31 | | | 214 | }); |
| b69ab31 | | | 215 | }); |
| b69ab31 | | | 216 | |
| b69ab31 | | | 217 | expect( |
| b69ab31 | | | 218 | document.querySelectorAll('.changed-files .changed-file.file-ignored'), |
| b69ab31 | | | 219 | ).toHaveLength(0); |
| b69ab31 | | | 220 | }); |
| b69ab31 | | | 221 | |
| b69ab31 | | | 222 | it('runs addremove only on selected files that are untracked', async () => { |
| b69ab31 | | | 223 | const ignoredFileCheckboxes = document.querySelectorAll( |
| b69ab31 | | | 224 | '.changed-files .changed-file.file-ignored input[type="checkbox"]', |
| b69ab31 | | | 225 | ); |
| b69ab31 | | | 226 | const missingFileCheckboxes = document.querySelectorAll( |
| b69ab31 | | | 227 | '.changed-files .changed-file.file-missing input[type="checkbox"]', |
| b69ab31 | | | 228 | ); |
| b69ab31 | | | 229 | expect(ignoredFileCheckboxes).toHaveLength(1); // file_untracked.js |
| b69ab31 | | | 230 | expect(missingFileCheckboxes).toHaveLength(1); // file_missing.js |
| b69ab31 | | | 231 | act(() => { |
| b69ab31 | | | 232 | fireEvent.click(missingFileCheckboxes[0]); |
| b69ab31 | | | 233 | }); |
| b69ab31 | | | 234 | |
| b69ab31 | | | 235 | const addremove = screen.getByTestId('addremove-button'); |
| b69ab31 | | | 236 | act(() => { |
| b69ab31 | | | 237 | fireEvent.click(addremove); |
| b69ab31 | | | 238 | }); |
| b69ab31 | | | 239 | await waitFor(() => { |
| b69ab31 | | | 240 | expectMessageSentToServer({ |
| b69ab31 | | | 241 | type: 'runOperation', |
| b69ab31 | | | 242 | operation: { |
| b69ab31 | | | 243 | // note: although src/file.js & others are selected, they aren't passed to addremove as they aren't untracked |
| b69ab31 | | | 244 | args: ['addremove', {path: 'src/file_untracked.js', type: 'repo-relative-file'}], |
| b69ab31 | | | 245 | id: expect.anything(), |
| b69ab31 | | | 246 | runner: CommandRunner.Sapling, |
| b69ab31 | | | 247 | trackEventName: 'AddRemoveOperation', |
| b69ab31 | | | 248 | }, |
| b69ab31 | | | 249 | }); |
| b69ab31 | | | 250 | }); |
| b69ab31 | | | 251 | }); |
| b69ab31 | | | 252 | }); |
| b69ab31 | | | 253 | }); |
| b69ab31 | | | 254 | |
| b69ab31 | | | 255 | it('shows log errors', () => { |
| b69ab31 | | | 256 | act(() => { |
| b69ab31 | | | 257 | simulateCommits({ |
| b69ab31 | | | 258 | error: new Error('error running log'), |
| b69ab31 | | | 259 | }); |
| b69ab31 | | | 260 | }); |
| b69ab31 | | | 261 | expect(screen.getByText('Failed to fetch commits')).toBeInTheDocument(); |
| b69ab31 | | | 262 | expect(screen.getByText('error running log')).toBeInTheDocument(); |
| b69ab31 | | | 263 | |
| b69ab31 | | | 264 | // we should still have commits from the last successful fetch |
| b69ab31 | | | 265 | expect(screen.getByText('My Commit')).toBeInTheDocument(); |
| b69ab31 | | | 266 | expect(screen.getByText('Another Commit')).toBeInTheDocument(); |
| b69ab31 | | | 267 | expect(screen.queryByText('some public base')).not.toBeInTheDocument(); |
| b69ab31 | | | 268 | }); |
| b69ab31 | | | 269 | |
| b69ab31 | | | 270 | it('shows status errors', () => { |
| b69ab31 | | | 271 | act(() => { |
| b69ab31 | | | 272 | simulateUncommittedChangedFiles({ |
| b69ab31 | | | 273 | error: new Error('error running status'), |
| b69ab31 | | | 274 | }); |
| b69ab31 | | | 275 | }); |
| b69ab31 | | | 276 | expect(screen.getByText('Failed to fetch Uncommitted Changes')).toBeInTheDocument(); |
| b69ab31 | | | 277 | expect(screen.getByText('error running status')).toBeInTheDocument(); |
| b69ab31 | | | 278 | }); |
| b69ab31 | | | 279 | |
| b69ab31 | | | 280 | it('shows successor info', () => { |
| b69ab31 | | | 281 | act(() => { |
| b69ab31 | | | 282 | simulateCommits({ |
| b69ab31 | | | 283 | value: [ |
| b69ab31 | | | 284 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 285 | COMMIT('a', 'My Commit', '1', {successorInfo: {hash: 'a2', type: 'land'}}), |
| b69ab31 | | | 286 | COMMIT('b', 'Another Commit', 'a', {isDot: true}), |
| b69ab31 | | | 287 | ], |
| b69ab31 | | | 288 | }); |
| b69ab31 | | | 289 | }); |
| b69ab31 | | | 290 | expect(screen.getByText('Landed as a newer commit', {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 291 | }); |
| b69ab31 | | | 292 | |
| b69ab31 | | | 293 | it('shows button to open sidebar', () => { |
| b69ab31 | | | 294 | act(() => { |
| b69ab31 | | | 295 | simulateCommits({ |
| b69ab31 | | | 296 | value: [ |
| b69ab31 | | | 297 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 298 | COMMIT('a', 'Commit A', '1', {isDot: true}), |
| b69ab31 | | | 299 | COMMIT('b', 'Commit B', '1'), |
| b69ab31 | | | 300 | ], |
| b69ab31 | | | 301 | }); |
| b69ab31 | | | 302 | }); |
| b69ab31 | | | 303 | expect(commitInfoIsOpen()).toBeFalsy(); |
| b69ab31 | | | 304 | |
| b69ab31 | | | 305 | // doesn't appear for public commits |
| b69ab31 | | | 306 | expect( |
| b69ab31 | | | 307 | within(screen.getByTestId('commit-1')).queryByTestId('open-commit-info-button'), |
| b69ab31 | | | 308 | ).not.toBeInTheDocument(); |
| b69ab31 | | | 309 | |
| b69ab31 | | | 310 | const openButton = within(screen.getByTestId('commit-b')).getByTestId( |
| b69ab31 | | | 311 | 'open-commit-info-button', |
| b69ab31 | | | 312 | ); |
| b69ab31 | | | 313 | expect(openButton).toBeInTheDocument(); |
| b69ab31 | | | 314 | // screen reader accessible |
| b69ab31 | | | 315 | expect(screen.getByLabelText('Open commit "Commit B"')).toBeInTheDocument(); |
| b69ab31 | | | 316 | fireEvent.click(openButton); |
| b69ab31 | | | 317 | expect(commitInfoIsOpen()).toBeTruthy(); |
| b69ab31 | | | 318 | expect(CommitInfoTestUtils.withinCommitInfo().getByText('Commit B')).toBeInTheDocument(); |
| b69ab31 | | | 319 | }); |
| b69ab31 | | | 320 | |
| b69ab31 | | | 321 | it('sets to amend mode when clicking open button', () => { |
| b69ab31 | | | 322 | act(() => { |
| b69ab31 | | | 323 | simulateCommits({ |
| b69ab31 | | | 324 | value: [ |
| b69ab31 | | | 325 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 326 | COMMIT('a', 'Commit A', '1', {isDot: true}), |
| b69ab31 | | | 327 | COMMIT('b', 'Commit B', '1'), |
| b69ab31 | | | 328 | ], |
| b69ab31 | | | 329 | }); |
| b69ab31 | | | 330 | }); |
| b69ab31 | | | 331 | act(() => { |
| b69ab31 | | | 332 | openCommitInfoSidebar(); |
| b69ab31 | | | 333 | }); |
| b69ab31 | | | 334 | CommitInfoTestUtils.clickCommitMode(); |
| b69ab31 | | | 335 | |
| b69ab31 | | | 336 | const openButton = within(screen.getByTestId('commit-b')).getByTestId( |
| b69ab31 | | | 337 | 'open-commit-info-button', |
| b69ab31 | | | 338 | ); |
| b69ab31 | | | 339 | expect(openButton).toBeInTheDocument(); |
| b69ab31 | | | 340 | fireEvent.click(openButton); |
| b69ab31 | | | 341 | expect(commitInfoIsOpen()).toBeTruthy(); |
| b69ab31 | | | 342 | expect(CommitInfoTestUtils.withinCommitInfo().getByText('Commit B')).toBeInTheDocument(); |
| b69ab31 | | | 343 | }); |
| b69ab31 | | | 344 | }); |
| b69ab31 | | | 345 | |
| b69ab31 | | | 346 | describe('render dag subset', () => { |
| b69ab31 | | | 347 | describe('irrelevant cwd stacks', () => { |
| b69ab31 | | | 348 | beforeEach(() => { |
| b69ab31 | | | 349 | render(<App />); |
| b69ab31 | | | 350 | act(() => { |
| b69ab31 | | | 351 | // Set repo root to "/repo" and cwd to "/repo/www" |
| b69ab31 | | | 352 | simulateRepoConnected('/repo', '/repo/www'); |
| b69ab31 | | | 353 | closeCommitInfoSidebar(); |
| b69ab31 | | | 354 | expectMessageSentToServer({ |
| b69ab31 | | | 355 | type: 'subscribe', |
| b69ab31 | | | 356 | kind: 'smartlogCommits', |
| b69ab31 | | | 357 | subscriptionID: expect.anything(), |
| b69ab31 | | | 358 | }); |
| b69ab31 | | | 359 | simulateCommits({ |
| b69ab31 | | | 360 | value: [ |
| b69ab31 | | | 361 | COMMIT('1', 'Public base', '0', {phase: 'public'}), |
| b69ab31 | | | 362 | // Commits with different maxCommonPathPrefix values |
| b69ab31 | | | 363 | COMMIT('a', 'Commit in www', '1', {maxCommonPathPrefix: 'www/'}), |
| b69ab31 | | | 364 | COMMIT('b', 'Commit in addons', '1', {maxCommonPathPrefix: 'addons/'}), |
| b69ab31 | | | 365 | COMMIT('c', 'Commit in root', '1', {maxCommonPathPrefix: ''}), |
| b69ab31 | | | 366 | COMMIT('d', 'Commit in www/js', '1', { |
| b69ab31 | | | 367 | maxCommonPathPrefix: 'www/js/', |
| b69ab31 | | | 368 | isDot: true, |
| b69ab31 | | | 369 | }), |
| b69ab31 | | | 370 | ], |
| b69ab31 | | | 371 | }); |
| b69ab31 | | | 372 | }); |
| b69ab31 | | | 373 | }); |
| b69ab31 | | | 374 | |
| b69ab31 | | | 375 | it('shows irrelevant commits by default', () => { |
| b69ab31 | | | 376 | // By default, hideIrrelevantCwdStacks is false, so all commits should be visible |
| b69ab31 | | | 377 | expect(screen.queryByText('Commit in www')).toBeInTheDocument(); |
| b69ab31 | | | 378 | expect(screen.queryByText('Commit in addons')).toBeInTheDocument(); |
| b69ab31 | | | 379 | expect(screen.queryByText('Commit in root')).toBeInTheDocument(); |
| b69ab31 | | | 380 | expect(screen.queryByText('Commit in www/js')).toBeInTheDocument(); |
| b69ab31 | | | 381 | |
| b69ab31 | | | 382 | // But the addons/ commit should be marked as irrelevant |
| b69ab31 | | | 383 | expect(document.body.querySelectorAll('.commit.irrelevant')).toHaveLength(1); |
| b69ab31 | | | 384 | }); |
| b69ab31 | | | 385 | |
| b69ab31 | | | 386 | it('can hide irrelevant commits when enabled', async () => { |
| b69ab31 | | | 387 | fireEvent.click(screen.getByTestId('settings-gear-button')); |
| b69ab31 | | | 388 | |
| b69ab31 | | | 389 | const settingsDropdown = screen.getByTestId('settings-dropdown'); |
| b69ab31 | | | 390 | expect(settingsDropdown).toBeInTheDocument(); |
| b69ab31 | | | 391 | const cwdIrrelevantDropdown = |
| b69ab31 | | | 392 | within(settingsDropdown).getByTestId('cwd-irrelevant-commits'); |
| b69ab31 | | | 393 | expect(cwdIrrelevantDropdown).toBeInTheDocument(); |
| b69ab31 | | | 394 | |
| b69ab31 | | | 395 | // Change the dropdown value to 'hide' |
| b69ab31 | | | 396 | fireEvent.change(cwdIrrelevantDropdown, {target: {value: 'hide'}}); |
| b69ab31 | | | 397 | |
| b69ab31 | | | 398 | expect(screen.queryByText('Commit in www')).toBeInTheDocument(); |
| b69ab31 | | | 399 | expect(screen.queryByText('Commit in root')).toBeInTheDocument(); |
| b69ab31 | | | 400 | expect(screen.queryByText('Commit in www/js')).toBeInTheDocument(); |
| b69ab31 | | | 401 | |
| b69ab31 | | | 402 | expect(screen.queryByText('Commit in addons')).not.toBeInTheDocument(); |
| b69ab31 | | | 403 | }); |
| b69ab31 | | | 404 | }); |
| b69ab31 | | | 405 | |
| b69ab31 | | | 406 | describe('obsolete stacks', () => { |
| b69ab31 | | | 407 | beforeEach(() => { |
| b69ab31 | | | 408 | render(<App />); |
| b69ab31 | | | 409 | act(() => { |
| b69ab31 | | | 410 | simulateRepoConnected(); |
| b69ab31 | | | 411 | closeCommitInfoSidebar(); |
| b69ab31 | | | 412 | expectMessageSentToServer({ |
| b69ab31 | | | 413 | type: 'subscribe', |
| b69ab31 | | | 414 | kind: 'smartlogCommits', |
| b69ab31 | | | 415 | subscriptionID: expect.anything(), |
| b69ab31 | | | 416 | }); |
| b69ab31 | | | 417 | simulateCommits({ |
| b69ab31 | | | 418 | value: [ |
| b69ab31 | | | 419 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 420 | COMMIT('a', 'Commit A', '1', {successorInfo: {hash: 'a2', type: 'rebase'}}), |
| b69ab31 | | | 421 | COMMIT('b', 'Commit B', 'a', {successorInfo: {hash: 'b2', type: 'rebase'}}), |
| b69ab31 | | | 422 | COMMIT('c', 'Commit C', 'b', {successorInfo: {hash: 'c2', type: 'rebase'}}), |
| b69ab31 | | | 423 | COMMIT('d', 'Commit D', 'c', {successorInfo: {hash: 'd2', type: 'rebase'}}), |
| b69ab31 | | | 424 | COMMIT('e', 'Commit E', 'd', {isDot: true}), |
| b69ab31 | | | 425 | ], |
| b69ab31 | | | 426 | }); |
| b69ab31 | | | 427 | }); |
| b69ab31 | | | 428 | }); |
| b69ab31 | | | 429 | it('hides obsolete stacks by default', () => { |
| b69ab31 | | | 430 | expect(screen.queryByText('Commit A')).toBeInTheDocument(); |
| b69ab31 | | | 431 | expect(screen.queryByText('Commit B')).not.toBeInTheDocument(); |
| b69ab31 | | | 432 | expect(screen.queryByText('Commit C')).not.toBeInTheDocument(); |
| b69ab31 | | | 433 | expect(screen.queryByText('Commit D')).toBeInTheDocument(); |
| b69ab31 | | | 434 | expect(screen.queryByText('Commit E')).toBeInTheDocument(); |
| b69ab31 | | | 435 | }); |
| b69ab31 | | | 436 | |
| b69ab31 | | | 437 | it('can configure to not hide obsolete stacks', () => { |
| b69ab31 | | | 438 | fireEvent.click(screen.getByTestId('settings-gear-button')); |
| b69ab31 | | | 439 | fireEvent.click(screen.getByTestId('condense-obsolete-stacks')); |
| b69ab31 | | | 440 | expect(screen.queryByText('Commit A')).toBeInTheDocument(); |
| b69ab31 | | | 441 | expect(screen.queryByText('Commit B')).toBeInTheDocument(); |
| b69ab31 | | | 442 | expect(screen.queryByText('Commit C')).toBeInTheDocument(); |
| b69ab31 | | | 443 | expect(screen.queryByText('Commit D')).toBeInTheDocument(); |
| b69ab31 | | | 444 | expect(screen.queryByText('Commit E')).toBeInTheDocument(); |
| b69ab31 | | | 445 | }); |
| b69ab31 | | | 446 | }); |
| b69ab31 | | | 447 | }); |
| b69ab31 | | | 448 | }); |