blob: 38b16dd0c2c22e17aa3d397e8c032f6e9782a2c7 (
plain)
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
50
51
52
53
54
|
import {
displaySuccessfulInvitationAlert,
reloadOnInvitationSuccess,
} from '~/invite_members/utils/trigger_successful_invite_alert';
import {
TOAST_MESSAGE_LOCALSTORAGE_KEY,
TOAST_MESSAGE_SUCCESSFUL,
} from '~/invite_members/constants';
import { createAlert } from '~/flash';
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
jest.mock('~/flash');
useLocalStorageSpy();
describe('Display Successful Invitation Alert', () => {
it('does not show alert if localStorage key not present', () => {
localStorage.removeItem(TOAST_MESSAGE_LOCALSTORAGE_KEY);
displaySuccessfulInvitationAlert();
expect(createAlert).not.toHaveBeenCalled();
});
it('shows alert when localStorage key is present', () => {
localStorage.setItem(TOAST_MESSAGE_LOCALSTORAGE_KEY, 'true');
displaySuccessfulInvitationAlert();
expect(createAlert).toHaveBeenCalledWith({
message: TOAST_MESSAGE_SUCCESSFUL,
variant: 'info',
});
});
});
describe('Reload On Invitation Success', () => {
const { location } = window;
beforeAll(() => {
delete window.location;
window.location = { reload: jest.fn() };
});
afterAll(() => {
window.location = location;
});
it('sets localStorage value and calls window.location.reload', () => {
reloadOnInvitationSuccess();
expect(localStorage.setItem).toHaveBeenCalledWith(TOAST_MESSAGE_LOCALSTORAGE_KEY, 'true');
expect(window.location.reload).toHaveBeenCalled();
});
});
|