notification.component.spec.ts
2.78 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
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 {Notification} from "./notification.component";
const tcb = new TestComponentBuilder();
describe("Components", () => {
describe("Profile Image Component", () => {
beforeEach(angular.mock.module("templates"));
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: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.languageService);
component.error();
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
text: Notification.DEFAULT_ERROR_MESSAGE,
type: "error"
}));
done();
});
it("display a success message when call notification success", done => {
let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
sweetAlert.swal = jasmine.createSpy("swal");
let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.languageService);
component.success("title", "message", 1000);
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
type: "success"
}));
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: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.languageService);
component.httpError(500, {});
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
text: "notification.http_error.500.message"
}));
done();
});
it("set the default timer in success messages", done => {
let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
sweetAlert.swal = jasmine.createSpy("swal");
let component: Notification = new Notification(<any>helpers.mocks.$log, <any>sweetAlert, <any>helpers.mocks.languageService);
component.success("title", "message");
expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
type: "success",
timer: Notification.DEFAULT_SUCCESS_TIMER
}));
done();
});
});
});