forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-notification-spec.ts
153 lines (131 loc) · 3.78 KB
/
api-notification-spec.ts
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { expect } from 'chai';
import { Notification } from 'electron/main';
import { once } from 'node:events';
import { ifit } from './lib/spec-helpers';
describe('Notification module', () => {
it('sets the correct class name on the prototype', () => {
expect(Notification.prototype.constructor.name).to.equal('Notification');
});
it('is supported', () => {
expect(Notification.isSupported()).to.be.a('boolean');
});
it('inits, gets and sets basic string properties correctly', () => {
const n = new Notification({
title: 'title',
subtitle: 'subtitle',
body: 'body',
replyPlaceholder: 'replyPlaceholder',
sound: 'sound',
closeButtonText: 'closeButtonText'
});
expect(n.title).to.equal('title');
n.title = 'title1';
expect(n.title).to.equal('title1');
expect(n.subtitle).equal('subtitle');
n.subtitle = 'subtitle1';
expect(n.subtitle).equal('subtitle1');
expect(n.body).to.equal('body');
n.body = 'body1';
expect(n.body).to.equal('body1');
expect(n.replyPlaceholder).to.equal('replyPlaceholder');
n.replyPlaceholder = 'replyPlaceholder1';
expect(n.replyPlaceholder).to.equal('replyPlaceholder1');
expect(n.sound).to.equal('sound');
n.sound = 'sound1';
expect(n.sound).to.equal('sound1');
expect(n.closeButtonText).to.equal('closeButtonText');
n.closeButtonText = 'closeButtonText1';
expect(n.closeButtonText).to.equal('closeButtonText1');
});
it('inits, gets and sets basic boolean properties correctly', () => {
const n = new Notification({
title: 'title',
body: 'body',
silent: true,
hasReply: true
});
expect(n.silent).to.be.true('silent');
n.silent = false;
expect(n.silent).to.be.false('silent');
expect(n.hasReply).to.be.true('has reply');
n.hasReply = false;
expect(n.hasReply).to.be.false('has reply');
});
it('inits, gets and sets actions correctly', () => {
const n = new Notification({
title: 'title',
body: 'body',
actions: [
{
type: 'button',
text: '1'
}, {
type: 'button',
text: '2'
}
]
});
expect(n.actions.length).to.equal(2);
expect(n.actions[0].type).to.equal('button');
expect(n.actions[0].text).to.equal('1');
expect(n.actions[1].type).to.equal('button');
expect(n.actions[1].text).to.equal('2');
n.actions = [
{
type: 'button',
text: '3'
}, {
type: 'button',
text: '4'
}
];
expect(n.actions.length).to.equal(2);
expect(n.actions[0].type).to.equal('button');
expect(n.actions[0].text).to.equal('3');
expect(n.actions[1].type).to.equal('button');
expect(n.actions[1].text).to.equal('4');
});
it('can be shown and closed', () => {
const n = new Notification({
title: 'test notification',
body: 'test body',
silent: true
});
n.show();
n.close();
});
ifit(process.platform === 'win32')('inits, gets and sets custom xml', () => {
const n = new Notification({
toastXml: '<xml/>'
});
expect(n.toastXml).to.equal('<xml/>');
});
ifit(process.platform === 'darwin')('emits show and close events', async () => {
const n = new Notification({
title: 'test notification',
body: 'test body',
silent: true
});
{
const e = once(n, 'show');
n.show();
await e;
}
{
const e = once(n, 'close');
n.close();
await e;
}
});
ifit(process.platform === 'win32')('emits failed event', async () => {
const n = new Notification({
toastXml: 'not xml'
});
{
const e = once(n, 'failed');
n.show();
await e;
}
});
// TODO(sethlu): Find way to test init with notification icon?
});