X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fservices%2Fui%2Fnotification.service.spec.ts;h=87757ef57953353f005bc9fd389067634af12d0d;hb=82e05a5f48ff4e3f19e878ac22ee6b79f84c76fe;hp=b6953e65bcc611df3303573814650aaf8b01bfe7;hpb=0ad7c39f68411d7cbd1f013d1d46c8d4b1849bca;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/services/ui/notification.service.spec.ts b/webapp-frontend/src/app/services/ui/notification.service.spec.ts index b6953e6..87757ef 100644 --- a/webapp-frontend/src/app/services/ui/notification.service.spec.ts +++ b/webapp-frontend/src/app/services/ui/notification.service.spec.ts @@ -18,22 +18,47 @@ * ========================LICENSE_END=================================== */ -import { TestBed } from '@angular/core/testing'; +import { async, TestBed } from "@angular/core/testing"; -import { NotificationService } from './notification.service'; -import { ToastrModule } from 'ngx-toastr'; +import { NotificationService } from "./notification.service"; +import { ToastrService } from "ngx-toastr"; -describe('NotificationService', () => { - beforeEach(() => TestBed.configureTestingModule({ - imports: [ToastrModule.forRoot()], - providers: [ - {provide: ToastrModule} - ] +describe("NotificationService", () => { + let service: NotificationService; + let toastrSpy: jasmine.SpyObj; + beforeEach(async(() => { + toastrSpy = jasmine.createSpyObj("ToastrService", [ + "success", + "warning", + "error", + ]); + + TestBed.configureTestingModule({ + providers: [{ provide: ToastrService, useValue: toastrSpy }], + }); + service = TestBed.inject(NotificationService); })); - it('should be created', () => { - const service: NotificationService = TestBed.get(NotificationService); + it("should be created", () => { expect(service).toBeTruthy(); }); + + it("should open success with provided message and correct configuration", () => { + service.success("Success!"); + + expect(toastrSpy.success).toHaveBeenCalledWith("Success!", "", { + timeOut: 10000, + closeButton: true, + }); + }); + + it("should open error with provided message and correct configuration", () => { + service.error("Error!"); + + expect(toastrSpy.error).toHaveBeenCalledWith("Error!", "", { + disableTimeOut: true, + closeButton: true, + }); + }); });