pulsar/spec/notification-spec.js

73 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-05-31 19:33:56 +03:00
const Notification = require('../src/notification');
describe('Notification', () => {
it('throws an error when created with a non-string message', () => {
2019-05-31 19:33:56 +03:00
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', () => {
2019-05-31 19:33:56 +03:00
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', () => {
2019-05-31 19:33:56 +03:00
const notification = new Notification('error', 'message!');
expect(notification.getTimestamp() instanceof Date).toBe(true);
}));
describe('::getIcon()', () => {
it('returns a default when no icon specified', () => {
2019-05-31 19:33:56 +03:00
const notification = new Notification('error', 'message!');
expect(notification.getIcon()).toBe('flame');
});
it('returns the icon specified', () => {
2019-02-22 10:55:17 +03:00
const notification = new Notification('error', 'message!', {
icon: 'my-icon'
2019-05-31 19:33:56 +03:00
});
expect(notification.getIcon()).toBe('my-icon');
});
});
describe('dismissing notifications', () => {
describe('when the notfication is dismissable', () =>
it('calls a callback when the notification is dismissed', () => {
2019-05-31 19:33:56 +03:00
const dismissedSpy = jasmine.createSpy();
2019-02-22 10:55:17 +03:00
const notification = new Notification('error', 'message', {
dismissable: true
2019-05-31 19:33:56 +03:00
});
notification.onDidDismiss(dismissedSpy);
2019-05-31 19:33:56 +03:00
expect(notification.isDismissable()).toBe(true);
expect(notification.isDismissed()).toBe(false);
2019-05-31 19:33:56 +03:00
notification.dismiss();
2019-05-31 19:33:56 +03:00
expect(dismissedSpy).toHaveBeenCalled();
expect(notification.isDismissed()).toBe(true);
}));
describe('when the notfication is not dismissable', () =>
it('does nothing when ::dismiss() is called', () => {
2019-05-31 19:33:56 +03:00
const dismissedSpy = jasmine.createSpy();
const notification = new Notification('error', 'message');
notification.onDidDismiss(dismissedSpy);
2019-05-31 19:33:56 +03:00
expect(notification.isDismissable()).toBe(false);
expect(notification.isDismissed()).toBe(true);
2019-05-31 19:33:56 +03:00
notification.dismiss();
2019-05-31 19:33:56 +03:00
expect(dismissedSpy).not.toHaveBeenCalled();
expect(notification.isDismissed()).toBe(true);
}));
});
});