summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
76bf355)
Change-Id: I4b9c2e66e1f75931eff60e68cc33214f9933e352
Issue-ID: NONRTRIC-474
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
* ========================LICENSE_END===================================
*/
* ========================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<ToastrService>;
+ 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.inject(NotificationService);
+ it("should be created", () => {
expect(service).toBeTruthy();
});
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,
+ });
+ });
* ========================LICENSE_END===================================
*/
* ========================LICENSE_END===================================
*/
-import { Injectable } from '@angular/core';
-import { ToastrService } from 'ngx-toastr';
+import { Injectable } from "@angular/core";
+import { ToastrService } from "ngx-toastr";
})
export class NotificationService {
})
export class NotificationService {
-
- constructor(public toastr: ToastrService) { }
+ constructor(public toastr: ToastrService) {}
successConfig = {
timeOut: 10000,
successConfig = {
timeOut: 10000,
- closeButton: true
- };
-
- warningConfig = {
- disableTimeOut: true,
- closeButton: true
};
errorConfig = {
disableTimeOut: true,
};
errorConfig = {
disableTimeOut: true,
};
success(msg: string) {
};
success(msg: string) {
- this.toastr.success(msg, '', this.successConfig);
- }
-
- warn(msg: string) {
- this.toastr.warning(msg, '', this.warningConfig);
+ this.toastr.success(msg, "", this.successConfig);
- this.toastr.error(msg, '', this.errorConfig);
+ this.toastr.error(msg, "", this.errorConfig);