2019-07-25 00:18:11 +00:00
|
|
|
import { expect } from 'chai';
|
2020-04-07 00:04:09 +00:00
|
|
|
import { Notification } from 'electron/main';
|
2023-06-15 14:42:27 +00:00
|
|
|
import { once } from 'node:events';
|
2023-01-25 21:01:25 +00:00
|
|
|
import { ifit } from './lib/spec-helpers';
|
2018-02-07 06:09:23 +00:00
|
|
|
|
|
|
|
describe('Notification module', () => {
|
2023-07-10 09:49:20 +00:00
|
|
|
it('sets the correct class name on the prototype', () => {
|
|
|
|
expect(Notification.prototype.constructor.name).to.equal('Notification');
|
|
|
|
});
|
|
|
|
|
2020-03-31 18:42:32 +00:00
|
|
|
it('is supported', () => {
|
|
|
|
expect(Notification.isSupported()).to.be.a('boolean');
|
|
|
|
});
|
|
|
|
|
2018-02-07 06:09:23 +00:00
|
|
|
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'
|
|
|
|
});
|
|
|
|
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.title).to.equal('title');
|
2018-02-07 06:09:23 +00:00
|
|
|
n.title = 'title1';
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.title).to.equal('title1');
|
2018-02-07 06:09:23 +00:00
|
|
|
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.subtitle).equal('subtitle');
|
2018-02-07 06:09:23 +00:00
|
|
|
n.subtitle = 'subtitle1';
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.subtitle).equal('subtitle1');
|
2018-02-07 06:09:23 +00:00
|
|
|
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.body).to.equal('body');
|
2018-02-07 06:09:23 +00:00
|
|
|
n.body = 'body1';
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.body).to.equal('body1');
|
2018-02-07 06:09:23 +00:00
|
|
|
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.replyPlaceholder).to.equal('replyPlaceholder');
|
2018-02-07 06:09:23 +00:00
|
|
|
n.replyPlaceholder = 'replyPlaceholder1';
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.replyPlaceholder).to.equal('replyPlaceholder1');
|
2018-02-07 06:09:23 +00:00
|
|
|
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.sound).to.equal('sound');
|
2018-02-07 06:09:23 +00:00
|
|
|
n.sound = 'sound1';
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.sound).to.equal('sound1');
|
2018-02-07 06:09:23 +00:00
|
|
|
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.closeButtonText).to.equal('closeButtonText');
|
2018-02-07 06:09:23 +00:00
|
|
|
n.closeButtonText = 'closeButtonText1';
|
2018-08-31 20:52:32 +00:00
|
|
|
expect(n.closeButtonText).to.equal('closeButtonText1');
|
2018-02-07 06:09:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('inits, gets and sets basic boolean properties correctly', () => {
|
|
|
|
const n = new Notification({
|
2019-07-25 00:18:11 +00:00
|
|
|
title: 'title',
|
|
|
|
body: 'body',
|
2018-02-07 06:09:23 +00:00
|
|
|
silent: true,
|
|
|
|
hasReply: true
|
|
|
|
});
|
|
|
|
|
2019-07-25 00:18:11 +00:00
|
|
|
expect(n.silent).to.be.true('silent');
|
2018-02-07 06:09:23 +00:00
|
|
|
n.silent = false;
|
2019-07-25 00:18:11 +00:00
|
|
|
expect(n.silent).to.be.false('silent');
|
2018-02-07 06:09:23 +00:00
|
|
|
|
2019-07-25 00:18:11 +00:00
|
|
|
expect(n.hasReply).to.be.true('has reply');
|
2018-02-07 06:09:23 +00:00
|
|
|
n.hasReply = false;
|
2019-07-25 00:18:11 +00:00
|
|
|
expect(n.hasReply).to.be.false('has reply');
|
2018-02-07 06:09:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('inits, gets and sets actions correctly', () => {
|
|
|
|
const n = new Notification({
|
2019-07-25 00:18:11 +00:00
|
|
|
title: 'title',
|
|
|
|
body: 'body',
|
2018-02-07 06:09:23 +00:00
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
type: 'button',
|
|
|
|
text: '1'
|
|
|
|
}, {
|
|
|
|
type: 'button',
|
|
|
|
text: '2'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2018-08-31 20:52:32 +00:00
|
|
|
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');
|
2018-02-07 06:09:23 +00:00
|
|
|
|
|
|
|
n.actions = [
|
|
|
|
{
|
|
|
|
type: 'button',
|
|
|
|
text: '3'
|
|
|
|
}, {
|
|
|
|
type: 'button',
|
|
|
|
text: '4'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2018-08-31 20:52:32 +00:00
|
|
|
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');
|
2018-02-07 06:09:23 +00:00
|
|
|
});
|
|
|
|
|
2020-03-31 18:42:32 +00:00
|
|
|
it('can be shown and closed', () => {
|
|
|
|
const n = new Notification({
|
|
|
|
title: 'test notification',
|
|
|
|
body: 'test body',
|
|
|
|
silent: true
|
|
|
|
});
|
|
|
|
n.show();
|
|
|
|
n.close();
|
|
|
|
});
|
|
|
|
|
2020-09-29 19:20:10 +00:00
|
|
|
ifit(process.platform === 'win32')('inits, gets and sets custom xml', () => {
|
|
|
|
const n = new Notification({
|
|
|
|
toastXml: '<xml/>'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(n.toastXml).to.equal('<xml/>');
|
|
|
|
});
|
|
|
|
|
2020-03-31 18:42:32 +00:00
|
|
|
ifit(process.platform === 'darwin')('emits show and close events', async () => {
|
|
|
|
const n = new Notification({
|
|
|
|
title: 'test notification',
|
|
|
|
body: 'test body',
|
|
|
|
silent: true
|
|
|
|
});
|
|
|
|
{
|
2023-02-23 23:53:53 +00:00
|
|
|
const e = once(n, 'show');
|
2020-03-31 18:42:32 +00:00
|
|
|
n.show();
|
|
|
|
await e;
|
|
|
|
}
|
|
|
|
{
|
2023-02-23 23:53:53 +00:00
|
|
|
const e = once(n, 'close');
|
2020-03-31 18:42:32 +00:00
|
|
|
n.close();
|
|
|
|
await e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-29 19:20:10 +00:00
|
|
|
ifit(process.platform === 'win32')('emits failed event', async () => {
|
|
|
|
const n = new Notification({
|
|
|
|
toastXml: 'not xml'
|
|
|
|
});
|
|
|
|
{
|
2023-02-23 23:53:53 +00:00
|
|
|
const e = once(n, 'failed');
|
2020-09-29 19:20:10 +00:00
|
|
|
n.show();
|
|
|
|
await e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-02-07 06:09:23 +00:00
|
|
|
// TODO(sethlu): Find way to test init with notification icon?
|
|
|
|
});
|