comment-paragraph-article-button.component.spec.ts
4.17 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
import {CommentParagraphArticleButtonHotspotComponent} from "./comment-paragraph-article-button.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-article-button-hotspot [article]="ctrl.article"></comment-paragraph-article-button-hotspot>';
describe("Components", () => {
describe("Comment Paragraph Article Button Hotspot Component", () => {
let serviceMock = jasmine.createSpyObj("CommentParagraphService", ["deactivateCommentParagraph", "activateCommentParagraph"]);
let eventServiceMock = jasmine.createSpyObj("CommentParagraphEventService", ["toggleCommentParagraph"]);
let providers = [
new Provider('CommentParagraphService', { useValue: serviceMock }),
new Provider('CommentParagraphEventService', { useValue: eventServiceMock })
].concat(helpers.provideFilters('translateFilter'));
let helper: ComponentTestHelper<CommentParagraphArticleButtonHotspotComponent>;
beforeEach(angular.mock.module("templates"));
beforeEach((done) => {
let cls = createClass({
template: htmlTemplate,
directives: [CommentParagraphArticleButtonHotspotComponent],
providers: providers,
properties: {
article: {}
}
});
helper = new ComponentTestHelper<CommentParagraphArticleButtonHotspotComponent>(cls, done);
});
it('emit event when deactivate comment paragraph in an article', () => {
serviceMock.deactivateCommentParagraph = jasmine.createSpy("deactivateCommentParagraph").and.returnValue(
{ then: (fn: Function) => { fn({ data: {} }); } }
);
eventServiceMock.toggleCommentParagraph = jasmine.createSpy("toggleCommentParagraph");
helper.component.deactivateCommentParagraph();
expect(serviceMock.deactivateCommentParagraph).toHaveBeenCalled();
expect(eventServiceMock.toggleCommentParagraph).toHaveBeenCalled();
});
it('emit event when activate comment paragraph in an article', () => {
serviceMock.activateCommentParagraph = jasmine.createSpy("activateCommentParagraph").and.returnValue(
{ then: (fn: Function) => { fn({ data: {} }); } }
);
eventServiceMock.toggleCommentParagraph = jasmine.createSpy("toggleCommentParagraph");
helper.component.activateCommentParagraph();
expect(serviceMock.activateCommentParagraph).toHaveBeenCalled();
expect(eventServiceMock.toggleCommentParagraph).toHaveBeenCalled();
});
it('return true when comment paragraph is active', () => {
helper.component.article = <noosfero.Article>{ setting: { comment_paragraph_plugin_activate: true } };
helper.detectChanges();
expect(helper.component.isActivated()).toBeTruthy();
});
it('return false when comment paragraph is not active', () => {
expect(helper.component.isActivated()).toBeFalsy();
});
it('return false when article has no setting attribute', () => {
helper.component.article = <noosfero.Article>{};
helper.detectChanges();
expect(helper.component.isActivated()).toBeFalsy();
});
it('display activate button when comment paragraph is not active', () => {
expect(helper.all('.comment-paragraph-activate').length).toEqual(1);
expect(helper.all('.comment-paragraph-deactivate').length).toEqual(0);
});
it('display deactivate button when comment paragraph is active', () => {
helper.component.article = <noosfero.Article>{ setting: { comment_paragraph_plugin_activate: true } };
helper.detectChanges();
expect(helper.all('.comment-paragraph-deactivate').length).toEqual(1);
expect(helper.all('.comment-paragraph-activate').length).toEqual(0);
});
});
});