Files
Umbraco-CMS/src/Umbraco.Web.UI.Client/libs/notification/notification.context.test.ts

86 lines
2.6 KiB
TypeScript
Raw Normal View History

import { expect } from '@open-wc/testing';
2022-08-09 15:39:07 +02:00
2023-03-01 17:10:00 +01:00
import { UmbNotificationHandler, UmbNotificationContext } from '.';
2022-08-02 16:21:47 +02:00
describe('UmbNotificationContext', () => {
let notificationContext: UmbNotificationContext;
2022-08-04 10:03:14 +02:00
beforeEach(async () => {
notificationContext = new UmbNotificationContext();
2022-08-04 10:03:14 +02:00
});
describe('Public API', () => {
describe('properties', () => {
it('has a dialog property', () => {
expect(notificationContext).to.have.property('notifications');
2022-08-04 10:03:14 +02:00
});
});
describe('methods', () => {
it('has a peek method', () => {
expect(notificationContext).to.have.property('peek').that.is.a('function');
2022-08-04 10:03:14 +02:00
});
it('has a stay method', () => {
expect(notificationContext).to.have.property('stay').that.is.a('function');
2022-08-04 10:03:14 +02:00
});
});
});
describe('peek', () => {
let peekNotificationHandler: UmbNotificationHandler | undefined = undefined;
2022-08-10 15:06:43 +02:00
let layoutElement: any;
2022-08-04 10:03:14 +02:00
beforeEach(async () => {
const peekOptions = {
data: { headline: 'Peek notification headline', message: 'Peek notification message' },
};
peekNotificationHandler = notificationContext.peek('positive', peekOptions);
2022-08-10 15:06:43 +02:00
layoutElement = peekNotificationHandler.element.querySelector('umb-notification-layout-default');
2022-08-04 10:03:14 +02:00
});
it('it sets notification color', () => {
expect(peekNotificationHandler?.color).to.equal('positive');
});
it('should set peek data on the notification element', () => {
2022-08-10 15:06:43 +02:00
const data = layoutElement.data;
2022-08-04 10:03:14 +02:00
expect(data.headline).to.equal('Peek notification headline');
expect(data.message).to.equal('Peek notification message');
});
it('it sets duration to 6000 ms', () => {
expect(peekNotificationHandler?.duration).to.equal(6000);
});
});
describe('stay', () => {
let stayNotificationHandler: UmbNotificationHandler | undefined = undefined;
2022-08-10 15:06:43 +02:00
let layoutElement: any;
2022-08-04 10:03:14 +02:00
beforeEach(async () => {
const stayOptions = {
data: { headline: 'Stay notification headline', message: 'Stay notification message' },
};
stayNotificationHandler = notificationContext.stay('danger', stayOptions);
2022-08-10 15:06:43 +02:00
layoutElement = stayNotificationHandler.element.querySelector('umb-notification-layout-default');
2022-08-04 10:03:14 +02:00
});
it('it sets notification color', () => {
expect(stayNotificationHandler?.color).to.equal('danger');
});
it('should set stay data on the notification element', () => {
2022-08-10 15:06:43 +02:00
const data = layoutElement?.data;
2022-08-04 10:03:14 +02:00
expect(data.headline).to.equal('Stay notification headline');
expect(data.message).to.equal('Stay notification message');
});
it('it sets the duration to null', () => {
expect(stayNotificationHandler?.duration).to.equal(null);
});
});
});