From 76d0b31b9d9ac3c6e3c66f0b29b03ef5e6a33bb7 Mon Sep 17 00:00:00 2001 From: Art Date: Fri, 17 Sep 2021 15:32:43 +0300 Subject: [PATCH] 131.2. Notification types - test NotificationService with types (#16) --- .../app/service/notification.service.spec.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/support-portal-frontend/src/app/service/notification.service.spec.ts b/support-portal-frontend/src/app/service/notification.service.spec.ts index 899735a..1d392dc 100644 --- a/support-portal-frontend/src/app/service/notification.service.spec.ts +++ b/support-portal-frontend/src/app/service/notification.service.spec.ts @@ -1,16 +1,40 @@ import {TestBed} from '@angular/core/testing'; import {NotificationService} from './notification.service'; +import {NotifierService} from "angular-notifier"; +import {NotificationType} from "../notification/notification-type"; describe('NotificationService', () => { let service: NotificationService; + let notifierSpy: jasmine.SpyObj; + + let notifierServiceSpy = jasmine.createSpyObj('NotifierService', ['notify']); beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ + providers: [{provide: NotifierService, useValue: notifierServiceSpy}] + }); service = TestBed.inject(NotificationService); + notifierSpy = TestBed.inject(NotifierService) as jasmine.SpyObj; }); it('should be created', () => { expect(service).toBeTruthy(); }); + + it("should call NotifierService's `notify` method with `info` message type when `notify` method is called with INFO notification type", () => { + + service.notify(NotificationType.INFO, "Dummy msg"); + + expect(notifierSpy.notify).toHaveBeenCalledWith("info", "Dummy msg"); + + }); + + it("should call NotifierService's `notify` method with `default` message type when `notify` method is called with DEFAULT notification type", () => { + + service.notify(NotificationType.DEFAULT, "Dummy msg"); + + expect(notifierSpy.notify).toHaveBeenCalledWith("default", "Dummy msg"); + + }); });