allow-comment.component.spec.ts
3.49 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
import {AllowCommentComponent} from "./allow-comment.component";
import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper';
import * as helpers from "../../../spec/helpers";
import {Provider} from 'ng-forward';
import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
let htmlTemplate = '<comment-paragraph-plugin-allow-comment [content]="ctrl.content" [paragraph-uuid]="ctrl.paragraphUuid" [article]="ctrl.article"></comment-paragraph-plugin-allow-comment>';
describe("Components", () => {
describe("Allow Comment Component", () => {
let serviceMock = {
commentParagraphCount: () => {
return Promise.resolve(5);
}
};
let functionToggleCommentParagraph: Function;
let eventServiceMock = {
// toggleCommentParagraph
subscribeToggleCommentParagraph: (fn: Function) => {
functionToggleCommentParagraph = fn;
}
};
let providers = [
new Provider('CommentParagraphService', { useValue: serviceMock }),
new Provider('CommentParagraphEventService', { useValue: eventServiceMock })
];
let helper: ComponentTestHelper<AllowCommentComponent>;
beforeEach(angular.mock.module("templates"));
beforeEach((done) => {
let cls = createClass({
template: htmlTemplate,
directives: [AllowCommentComponent],
providers: providers,
properties: {
content: "",
paragraphUuid: "uuid",
article: {
setting: {
comment_paragraph_plugin_activate: true
}
}
}
});
helper = new ComponentTestHelper<AllowCommentComponent>(cls, done);
});
it('update comments count', () => {
expect(helper.component.commentsCount).toEqual(5);
});
it('display paragraph content', () => {
expect(helper.all(".paragraph .paragraph-content").length).toEqual(1);
});
it('display button to side comments', () => {
expect(helper.all(".paragraph .paragraph-actions a").length).toEqual(1);
});
it('set display to true when click in show paragraph', () => {
helper.component.showParagraphComments();
expect(helper.component.display).toBeTruthy();
});
it('set display to false when click in hide paragraph', () => {
helper.component.hideParagraphComments();
expect(helper.component.display).toBeFalsy();
});
it('update article when receive a toogle paragraph event', () => {
functionToggleCommentParagraph({ id: 2 });
expect(helper.component.article.id).toEqual(2);
});
it('not display button to side comments when comments was closed and there is no comment paragraph', () => {
helper.component.article.accept_comments = false;
helper.component.commentsCount = 0;
expect(helper.component.isActivated()).toBeFalsy();
});
it('display button to side comments when comments was closed and there is some comments to display', () => {
helper.component.article.accept_comments = false;
helper.component.commentsCount = 2;
expect(helper.component.isActivated()).toBeTruthy();
});
});
});