| 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 | expectMessageSentToServer, |
| b69ab31 | | | 14 | simulateCommits, |
| b69ab31 | | | 15 | simulateMessageFromServer, |
| b69ab31 | | | 16 | simulateRepoConnected, |
| b69ab31 | | | 17 | } from '../testUtils'; |
| b69ab31 | | | 18 | |
| b69ab31 | | | 19 | describe('cwd', () => { |
| b69ab31 | | | 20 | beforeEach(() => { |
| b69ab31 | | | 21 | render(<App />); |
| b69ab31 | | | 22 | act(() => { |
| b69ab31 | | | 23 | simulateRepoConnected(); |
| b69ab31 | | | 24 | closeCommitInfoSidebar(); |
| b69ab31 | | | 25 | expectMessageSentToServer({ |
| b69ab31 | | | 26 | type: 'subscribe', |
| b69ab31 | | | 27 | kind: 'smartlogCommits', |
| b69ab31 | | | 28 | subscriptionID: expect.anything(), |
| b69ab31 | | | 29 | }); |
| b69ab31 | | | 30 | simulateCommits({ |
| b69ab31 | | | 31 | value: [ |
| b69ab31 | | | 32 | COMMIT('1', 'some public base', '0', {phase: 'public'}), |
| b69ab31 | | | 33 | COMMIT('a', 'My Commit', '1'), |
| b69ab31 | | | 34 | COMMIT('b', 'Another Commit', 'a', {isDot: true}), |
| b69ab31 | | | 35 | ], |
| b69ab31 | | | 36 | }); |
| b69ab31 | | | 37 | }); |
| b69ab31 | | | 38 | }); |
| b69ab31 | | | 39 | |
| b69ab31 | | | 40 | it('fetches alerts', () => { |
| b69ab31 | | | 41 | expectMessageSentToServer({type: 'fetchActiveAlerts'}); |
| b69ab31 | | | 42 | }); |
| b69ab31 | | | 43 | |
| b69ab31 | | | 44 | it('shows alerts', () => { |
| b69ab31 | | | 45 | expectMessageSentToServer({type: 'fetchActiveAlerts'}); |
| b69ab31 | | | 46 | act(() => { |
| b69ab31 | | | 47 | simulateMessageFromServer({ |
| b69ab31 | | | 48 | type: 'fetchedActiveAlerts', |
| b69ab31 | | | 49 | alerts: [ |
| b69ab31 | | | 50 | { |
| b69ab31 | | | 51 | key: 'test', |
| b69ab31 | | | 52 | title: 'Test Alert', |
| b69ab31 | | | 53 | description: 'This is a test', |
| b69ab31 | | | 54 | severity: 'SEV 4', |
| b69ab31 | | | 55 | url: 'https://sapling-scm.com', |
| b69ab31 | | | 56 | ['show-in-isl']: true, |
| b69ab31 | | | 57 | }, |
| b69ab31 | | | 58 | ], |
| b69ab31 | | | 59 | }); |
| b69ab31 | | | 60 | }); |
| b69ab31 | | | 61 | expect(screen.getByText('Test Alert')).toBeInTheDocument(); |
| b69ab31 | | | 62 | expect(screen.getByText('This is a test')).toBeInTheDocument(); |
| b69ab31 | | | 63 | expect(screen.getByText('SEV 4')).toBeInTheDocument(); |
| b69ab31 | | | 64 | }); |
| b69ab31 | | | 65 | |
| b69ab31 | | | 66 | describe('version matching', () => { |
| b69ab31 | | | 67 | const simulateApplicationInfo = (version: string) => { |
| b69ab31 | | | 68 | act(() => { |
| b69ab31 | | | 69 | simulateMessageFromServer({ |
| b69ab31 | | | 70 | type: 'applicationInfo', |
| b69ab31 | | | 71 | info: { |
| b69ab31 | | | 72 | version, |
| b69ab31 | | | 73 | logFilePath: '', |
| b69ab31 | | | 74 | platformName: 'vscode', |
| b69ab31 | | | 75 | }, |
| b69ab31 | | | 76 | }); |
| b69ab31 | | | 77 | }); |
| b69ab31 | | | 78 | }; |
| b69ab31 | | | 79 | |
| b69ab31 | | | 80 | const simulateAlert = (regex: string | undefined) => { |
| b69ab31 | | | 81 | act(() => { |
| b69ab31 | | | 82 | simulateMessageFromServer({ |
| b69ab31 | | | 83 | type: 'fetchedActiveAlerts', |
| b69ab31 | | | 84 | alerts: [ |
| b69ab31 | | | 85 | { |
| b69ab31 | | | 86 | key: 'version_test', |
| b69ab31 | | | 87 | title: 'Test Alert', |
| b69ab31 | | | 88 | description: 'This is a test', |
| b69ab31 | | | 89 | severity: 'SEV 4', |
| b69ab31 | | | 90 | url: 'https://sapling-scm.com', |
| b69ab31 | | | 91 | ['show-in-isl']: true, |
| b69ab31 | | | 92 | ['isl-version-regex']: regex, |
| b69ab31 | | | 93 | }, |
| b69ab31 | | | 94 | ], |
| b69ab31 | | | 95 | }); |
| b69ab31 | | | 96 | }); |
| b69ab31 | | | 97 | }; |
| b69ab31 | | | 98 | |
| b69ab31 | | | 99 | it('shows alerts matching current version', () => { |
| b69ab31 | | | 100 | simulateApplicationInfo('0.1.38000'); |
| b69ab31 | | | 101 | simulateAlert('^0.1.38.*$'); |
| b69ab31 | | | 102 | expect(screen.getByText('Test Alert')).toBeInTheDocument(); |
| b69ab31 | | | 103 | }); |
| b69ab31 | | | 104 | |
| b69ab31 | | | 105 | it('hides alerts not matching current version', () => { |
| b69ab31 | | | 106 | simulateApplicationInfo('0.1.36000'); |
| b69ab31 | | | 107 | simulateAlert('^0.1.38.*$'); |
| b69ab31 | | | 108 | expect(screen.queryByText('Test Alert')).not.toBeInTheDocument(); |
| b69ab31 | | | 109 | }); |
| b69ab31 | | | 110 | |
| b69ab31 | | | 111 | it('shows alerts missing regex', () => { |
| b69ab31 | | | 112 | simulateApplicationInfo('0.1.36000'); |
| b69ab31 | | | 113 | simulateAlert(undefined); |
| b69ab31 | | | 114 | expect(screen.getByText('Test Alert')).toBeInTheDocument(); |
| b69ab31 | | | 115 | }); |
| b69ab31 | | | 116 | |
| b69ab31 | | | 117 | it('hides alerts when regex given, while app info is loading', () => { |
| b69ab31 | | | 118 | simulateAlert('^0.1.38.*$'); |
| b69ab31 | | | 119 | expect(screen.queryByText('Test Alert')).not.toBeInTheDocument(); |
| b69ab31 | | | 120 | simulateApplicationInfo('0.1.38'); |
| b69ab31 | | | 121 | expect(screen.getByText('Test Alert')).toBeInTheDocument(); |
| b69ab31 | | | 122 | }); |
| b69ab31 | | | 123 | }); |
| b69ab31 | | | 124 | |
| b69ab31 | | | 125 | it('dismiss alerts', () => { |
| b69ab31 | | | 126 | expectMessageSentToServer({type: 'fetchActiveAlerts'}); |
| b69ab31 | | | 127 | act(() => { |
| b69ab31 | | | 128 | simulateMessageFromServer({ |
| b69ab31 | | | 129 | type: 'fetchedActiveAlerts', |
| b69ab31 | | | 130 | alerts: [ |
| b69ab31 | | | 131 | { |
| b69ab31 | | | 132 | key: 'test-dismiss', |
| b69ab31 | | | 133 | title: 'Test Alert', |
| b69ab31 | | | 134 | description: 'This is a test', |
| b69ab31 | | | 135 | severity: 'SEV 4', |
| b69ab31 | | | 136 | url: 'https://sapling-scm.com', |
| b69ab31 | | | 137 | ['show-in-isl']: true, |
| b69ab31 | | | 138 | }, |
| b69ab31 | | | 139 | ], |
| b69ab31 | | | 140 | }); |
| b69ab31 | | | 141 | }); |
| b69ab31 | | | 142 | |
| b69ab31 | | | 143 | expect(screen.getByText('Test Alert')).toBeInTheDocument(); |
| b69ab31 | | | 144 | act(() => { |
| b69ab31 | | | 145 | fireEvent.click(screen.getByTestId('dismiss-alert')); |
| b69ab31 | | | 146 | }); |
| b69ab31 | | | 147 | const found = localStorage.getItem('isl.dismissed-alerts'); |
| b69ab31 | | | 148 | expect(found).toEqual(JSON.stringify({'test-dismiss': true})); |
| b69ab31 | | | 149 | |
| b69ab31 | | | 150 | expect(screen.queryByText('Test Alert')).not.toBeInTheDocument(); |
| b69ab31 | | | 151 | }); |
| b69ab31 | | | 152 | }); |