-
Notifications
You must be signed in to change notification settings - Fork 470
Expand file tree
/
Copy pathBeforeUnloadManager.test.tsx
More file actions
49 lines (40 loc) · 1.61 KB
/
BeforeUnloadManager.test.tsx
File metadata and controls
49 lines (40 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { fireEvent } from '@testing-library/react';
import { Provider } from 'react-redux';
import { render, act } from 'firefox-profiler/test/fixtures/testing-library';
import { BeforeUnloadManager } from '../../components/app/BeforeUnloadManager';
import { blankStore } from '../fixtures/stores';
import { uploadStarted } from 'firefox-profiler/actions/publish';
import { getUploadPhase } from '../../selectors/publish';
describe('app/BeforeUnloadManager', () => {
function setup() {
const store = blankStore();
const { dispatch, getState } = store;
const createBeforeUnloadManager = () =>
render(
<Provider store={store}>
<BeforeUnloadManager />
</Provider>
);
return { dispatch, getState, createBeforeUnloadManager };
}
it('Prevents default beforeunload behaviour', () => {
const { dispatch, getState, createBeforeUnloadManager } = setup();
createBeforeUnloadManager();
// simulate profile upload phase
act(() => {
dispatch(uploadStarted());
});
expect(getUploadPhase(getState())).toBe('uploading');
const event = new Event('beforeunload');
/* Because of the current jsdom implementation, we need to mock
preventDefault().
*/
event.preventDefault = jest.fn();
fireEvent(window as any, event);
expect((event as any).returnValue).toBeTruthy();
expect(event.preventDefault).toHaveBeenCalled();
});
});