-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification-spec.js
72 lines (59 loc) · 2.63 KB
/
notification-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
const Notification = require('../src/notification');
describe('Notification', () => {
it('throws an error when created with a non-string message', () => {
expect(() => new Notification('error', null)).toThrow();
expect(() => new Notification('error', 3)).toThrow();
expect(() => new Notification('error', {})).toThrow();
expect(() => new Notification('error', false)).toThrow();
expect(() => new Notification('error', [])).toThrow();
});
it('throws an error when created with non-object options', () => {
expect(() => new Notification('error', 'message', 'foo')).toThrow();
expect(() => new Notification('error', 'message', 3)).toThrow();
expect(() => new Notification('error', 'message', false)).toThrow();
expect(() => new Notification('error', 'message', [])).toThrow();
});
describe('::getTimestamp()', () =>
it('returns a Date object', () => {
const notification = new Notification('error', 'message!');
expect(notification.getTimestamp() instanceof Date).toBe(true);
}));
describe('::getIcon()', () => {
it('returns a default when no icon specified', () => {
const notification = new Notification('error', 'message!');
expect(notification.getIcon()).toBe('flame');
});
it('returns the icon specified', () => {
const notification = new Notification('error', 'message!', {
icon: 'my-icon'
});
expect(notification.getIcon()).toBe('my-icon');
});
});
describe('dismissing notifications', () => {
describe('when the notfication is dismissable', () =>
it('calls a callback when the notification is dismissed', () => {
const dismissedSpy = jasmine.createSpy();
const notification = new Notification('error', 'message', {
dismissable: true
});
notification.onDidDismiss(dismissedSpy);
expect(notification.isDismissable()).toBe(true);
expect(notification.isDismissed()).toBe(false);
notification.dismiss();
expect(dismissedSpy).toHaveBeenCalled();
expect(notification.isDismissed()).toBe(true);
}));
describe('when the notfication is not dismissable', () =>
it('does nothing when ::dismiss() is called', () => {
const dismissedSpy = jasmine.createSpy();
const notification = new Notification('error', 'message');
notification.onDidDismiss(dismissedSpy);
expect(notification.isDismissable()).toBe(false);
expect(notification.isDismissed()).toBe(true);
notification.dismiss();
expect(dismissedSpy).not.toHaveBeenCalled();
expect(notification.isDismissed()).toBe(true);
}));
});
});