-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification-manager-spec.js
91 lines (75 loc) · 3.02 KB
/
notification-manager-spec.js
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
const NotificationManager = require('../src/notification-manager');
describe('NotificationManager', () => {
let manager;
beforeEach(() => {
manager = new NotificationManager();
});
describe('the atom global', () =>
it('has a notifications instance', () => {
expect(atom.notifications instanceof NotificationManager).toBe(true);
}));
describe('adding events', () => {
let addSpy;
beforeEach(() => {
addSpy = jasmine.createSpy();
manager.onDidAddNotification(addSpy);
});
it('emits an event when a notification has been added', () => {
manager.add('error', 'Some error!', { icon: 'someIcon' });
expect(addSpy).toHaveBeenCalled();
const notification = addSpy.mostRecentCall.args[0];
expect(notification.getType()).toBe('error');
expect(notification.getMessage()).toBe('Some error!');
expect(notification.getIcon()).toBe('someIcon');
});
it('emits a fatal error when ::addFatalError has been called', () => {
manager.addFatalError('Some error!', { icon: 'someIcon' });
expect(addSpy).toHaveBeenCalled();
const notification = addSpy.mostRecentCall.args[0];
expect(notification.getType()).toBe('fatal');
});
it('emits an error when ::addError has been called', () => {
manager.addError('Some error!', { icon: 'someIcon' });
expect(addSpy).toHaveBeenCalled();
const notification = addSpy.mostRecentCall.args[0];
expect(notification.getType()).toBe('error');
});
it('emits a warning notification when ::addWarning has been called', () => {
manager.addWarning('Something!', { icon: 'someIcon' });
expect(addSpy).toHaveBeenCalled();
const notification = addSpy.mostRecentCall.args[0];
expect(notification.getType()).toBe('warning');
});
it('emits an info notification when ::addInfo has been called', () => {
manager.addInfo('Something!', { icon: 'someIcon' });
expect(addSpy).toHaveBeenCalled();
const notification = addSpy.mostRecentCall.args[0];
expect(notification.getType()).toBe('info');
});
it('emits a success notification when ::addSuccess has been called', () => {
manager.addSuccess('Something!', { icon: 'someIcon' });
expect(addSpy).toHaveBeenCalled();
const notification = addSpy.mostRecentCall.args[0];
expect(notification.getType()).toBe('success');
});
});
describe('clearing notifications', () => {
it('clears the notifications when ::clear has been called', () => {
manager.addSuccess('success');
expect(manager.getNotifications().length).toBe(1);
manager.clear();
expect(manager.getNotifications().length).toBe(0);
});
describe('adding events', () => {
let clearSpy;
beforeEach(() => {
clearSpy = jasmine.createSpy();
manager.onDidClearNotifications(clearSpy);
});
it('emits an event when the notifications have been cleared', () => {
manager.clear();
expect(clearSpy).toHaveBeenCalled();
});
});
});
});