custom-content.component.spec.ts
3.54 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
import {CustomContentComponent} from './custom-content.component';
import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper';
import * as helpers from "../../../spec/helpers";
const htmlTemplate: string = '<custom-content [attribute]="\'custom_footer\'" [profile]="ctrl.profile"></custom-content>';
describe("Components", () => {
describe("Custom Content Component", () => {
let helper: ComponentTestHelper<CustomContentComponent>;
beforeEach(angular.mock.module("templates"));
beforeEach(angular.mock.module("ngSanitize"));
beforeEach((done) => {
let profileService = jasmine.createSpyObj("profileService", ["update"]);
let notificationService = jasmine.createSpyObj("notificationService", ["success"]);
let properties = { profile: { custom_footer: "footer" } };
let cls = createClass({
template: htmlTemplate,
directives: [CustomContentComponent],
properties: properties,
providers: [
helpers.createProviderToValue("$uibModal", helpers.mocks.$modal),
helpers.createProviderToValue("ProfileService", profileService),
helpers.createProviderToValue("NotificationService", notificationService)
]
});
helper = new ComponentTestHelper<CustomContentComponent>(cls, done);
});
it("set modal instance when open edit modal", () => {
helper.component['$uibModal'].open = jasmine.createSpy("open");
helper.component.openEdit();
expect(helper.component['$uibModal'].open).toHaveBeenCalled();
expect(helper.component.originalContent).toEqual(helper.component.content);
});
it("restore original content when cancelled", () => {
helper.component.openEdit();
helper.component.content = "modified";
helper.component.cancel();
expect(helper.component.content).toEqual(helper.component.originalContent);
});
it("keep modified content when click on preview", () => {
helper.component.openEdit();
helper.component.content = "modified";
helper.component.preview();
expect(helper.component.content).toEqual("modified");
});
it("not override original content when cancelled openEdit again", () => {
helper.component.openEdit();
helper.component.content = "modified";
helper.component.openEdit();
expect(helper.component.originalContent).toEqual("footer");
});
it("reset modal instance when close edit modal", () => {
let modalInstance = jasmine.createSpyObj("modalInstance", ["close"]);
helper.component['$uibModal'].open = jasmine.createSpy("open").and.returnValue(modalInstance);
helper.component.openEdit();
expect(helper.component['$uibModal'].open).toHaveBeenCalled();
helper.component.cancel();
expect(modalInstance.close).toHaveBeenCalled();
expect(helper.component['modalInstance']).toBeNull();
});
it("call profile service to update profile when save", () => {
helper.component['profileService'].update = jasmine.createSpy("update").and.returnValue({
then: (func: Function) => { func(); }
});
helper.component.save();
expect(helper.component['notificationService'].success).toHaveBeenCalled();
});
});
});