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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
import {
popCreateReleaseNotification,
putCreateReleaseNotification,
popDeleteReleaseNotification,
putDeleteReleaseNotification,
} from '~/releases/release_notification_service';
import { createAlert, VARIANT_SUCCESS } from '~/alert';
jest.mock('~/alert');
describe('~/releases/release_notification_service', () => {
const projectPath = 'test-project-path';
const releaseName = 'test-release-name';
describe('create release', () => {
const storageKey = `createRelease:${projectPath}`;
describe('prepareFlash', () => {
it('should set the session storage with project path key and release name value', () => {
putCreateReleaseNotification(projectPath, releaseName);
const item = window.sessionStorage.getItem(storageKey);
expect(item).toBe(releaseName);
});
});
describe('showNotificationsIfPresent', () => {
describe('if notification is prepared', () => {
beforeEach(() => {
window.sessionStorage.setItem(storageKey, releaseName);
popCreateReleaseNotification(projectPath);
});
it('should remove storage key', () => {
const item = window.sessionStorage.getItem(storageKey);
expect(item).toBe(null);
});
it('should create an alert message', () => {
expect(createAlert).toHaveBeenCalledTimes(1);
expect(createAlert).toHaveBeenCalledWith({
message: `Release ${releaseName} has been successfully created.`,
variant: VARIANT_SUCCESS,
});
});
});
describe('if notification is not prepared', () => {
beforeEach(() => {
popCreateReleaseNotification(projectPath);
});
it('should not create an alert message', () => {
expect(createAlert).toHaveBeenCalledTimes(0);
});
});
});
});
describe('delete release', () => {
const storageKey = `deleteRelease:${projectPath}`;
describe('prepareFlash', () => {
it('should set the session storage with project path key and release name value', () => {
putDeleteReleaseNotification(projectPath, releaseName);
const item = window.sessionStorage.getItem(storageKey);
expect(item).toBe(releaseName);
});
});
describe('showNotificationsIfPresent', () => {
describe('if notification is prepared', () => {
beforeEach(() => {
window.sessionStorage.setItem(storageKey, releaseName);
popDeleteReleaseNotification(projectPath);
});
it('should remove storage key', () => {
const item = window.sessionStorage.getItem(storageKey);
expect(item).toBe(null);
});
it('should create an alert message', () => {
expect(createAlert).toHaveBeenCalledTimes(1);
expect(createAlert).toHaveBeenCalledWith({
message: `Release ${releaseName} has been successfully deleted.`,
variant: VARIANT_SUCCESS,
});
});
});
describe('if notification is not prepared', () => {
beforeEach(() => {
popDeleteReleaseNotification(projectPath);
});
it('should not create an alert message', () => {
expect(createAlert).toHaveBeenCalledTimes(0);
});
});
});
});
});
|