notification.service.spec.ts
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
import {Pipe, Input, provide, Component} from 'ng-forward';
import * as helpers from "../../../spec/helpers";
import {NotificationService} from "./notification.service";
const tcb = new TestComponentBuilder();
describe("Components", () => {
describe("Profile Image Component", () => {
beforeEach(angular.mock.module("templates"));
it("display an error message when notify an error", done => {
let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
sweetAlert.swal = jasmine.createSpy("swal");
let component: NotificationService = new NotificationService(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.translatorService);
component.error({ message: "message", title: "title" });
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
title: "title",
text: "message",
type: "error"
}), null);
done();
});
it("use the default message when call notification component without a message", done => {
let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
sweetAlert.swal = jasmine.createSpy("swal");
let component: NotificationService = new NotificationService(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.translatorService);
component.error();
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
text: NotificationService.DEFAULT_ERROR_MESSAGE,
type: "error"
}), null);
done();
});
it("display a success message when call notification success", done => {
let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
sweetAlert.swal = jasmine.createSpy("swal");
let component: NotificationService = new NotificationService(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.translatorService);
component.success({ title: "title", message: "message", timer: 1000 });
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
type: "success"
}), null);
done();
});
it("display a message relative to the http error code", done => {
let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
sweetAlert.swal = jasmine.createSpy("swal");
let component: NotificationService = new NotificationService(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.translatorService);
component.httpError(500, {});
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
text: "notification.http_error.500.message"
}), null);
done();
});
it("set the default timer in success messages", done => {
let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
sweetAlert.swal = jasmine.createSpy("swal");
let component: NotificationService = new NotificationService(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.translatorService);
component.success({ title: "title", message: "message" });
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
type: "success",
timer: NotificationService.DEFAULT_SUCCESS_TIMER
}), null);
done();
});
it("display a confirmation dialog when call confirmation method", done => {
let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
sweetAlert.swal = jasmine.createSpy("swal");
let component: NotificationService = new NotificationService(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.translatorService);
let func = () => { };
component.confirmation({ title: "title", message: "message" }, func);
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
title: "title",
text: "message",
type: "warning"
}), jasmine.any(Function));
done();
});
});
});