From dfe6ab42472fd2ef273cffe94fbd088f55f5a68c Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 2 Aug 2022 16:21:47 +0200 Subject: [PATCH] add tests for notification service --- .../notifications.service.test.ts | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/Umbraco.Web.UI.Client/src/core/services/notification/notifications.service.test.ts diff --git a/src/Umbraco.Web.UI.Client/src/core/services/notification/notifications.service.test.ts b/src/Umbraco.Web.UI.Client/src/core/services/notification/notifications.service.test.ts new file mode 100644 index 0000000000..1edc53875a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/core/services/notification/notifications.service.test.ts @@ -0,0 +1,86 @@ +import { html, expect } from '@open-wc/testing'; +import { UmbNotificationService } from './notification.service'; +import { UmbNotificationHandler } from './notification-handler'; + +describe('UCPNotificationService', () => { + let notificationService: UmbNotificationService; + const options = { + data: { message: 'Notification message' } + }; + + beforeEach(async () => { + notificationService = new UmbNotificationService(); + }); + + describe('Public API', () => { + + describe('properties', () => { + it('has a dialog property', () => { + expect(notificationService).to.have.property('notifications'); + }); + }); + + describe('methods', () => { + it('has a peek method', () => { + expect(notificationService).to.have.property('peek').that.is.a('function'); + }); + + it('has a stay method', () => { + expect(notificationService).to.have.property('stay').that.is.a('function'); + }); + }); + + }); + + describe('peek', () => { + let peekNotificationHandler: UmbNotificationHandler | undefined = undefined; + + beforeEach(async () => { + const peekOptions = { + data: { headline: 'Peek notification headline', message: 'Peek notification message' } + }; + + peekNotificationHandler = notificationService.peek('positive', peekOptions); + }); + + it('it sets notification color', () => { + expect(peekNotificationHandler?.color).to.equal('positive'); + }); + + it('should set peek data on the notification element', () => { + const data = peekNotificationHandler?.element.data; + 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; + + beforeEach(async () => { + const stayOptions = { + data: { headline: 'Stay notification headline', message: 'Stay notification message' } + }; + + stayNotificationHandler = notificationService.stay('danger', stayOptions); + }); + + it('it sets notification color', () => { + expect(stayNotificationHandler?.color).to.equal('danger'); + }); + + it('should set stay data on the notification element', () => { + const data = stayNotificationHandler?.element.data; + 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); + }); + }); +}); \ No newline at end of file