export-comment-button.component.spec.ts
2.69 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
import {ExportCommentButtonHotspotComponent} from "./export-comment-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';
import {PermissionDirective} from '../../../app/shared/components/permission/permission.directive';
let htmlTemplate = '<export-comment-button-hotspot [article]="ctrl.article"></export-comment-button-hotspot>';
describe("Components", () => {
describe("Export Comment Button Hotspot Component", () => {
let serviceMock = jasmine.createSpyObj("CommentParagraphService", ["getArticle"]);
let providers = [new Provider('CommentParagraphService', { useValue: serviceMock })]
.concat(helpers.provideFilters('translateFilter'));
let helper: ComponentTestHelper<ExportCommentButtonHotspotComponent>;
beforeEach(angular.mock.module("templates"));
beforeEach((done) => {
let cls = createClass({
template: htmlTemplate,
directives: [ExportCommentButtonHotspotComponent, PermissionDirective],
providers: providers,
properties: {
article: {}
}
});
helper = new ComponentTestHelper<ExportCommentButtonHotspotComponent>(cls, done);
});
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();
expect(helper.all('.export-comment-button').length).toEqual(1);
});
it('return false when comment paragraph is not active', () => {
expect(helper.component.isActivated()).toBeFalsy();
expect(helper.all('.export-comment-button').length).toEqual(0);
});
it('return false when article has no setting attribute', () => {
helper.component.article = <noosfero.Article>{};
helper.detectChanges();
expect(helper.component.isActivated()).toBeFalsy();
expect(helper.all('.export-comment-button').length).toEqual(0);
});
it('not display export comment button when user does not have permission', () => {
helper.component.article = <noosfero.Article>{ setting: { comment_paragraph_plugin_activate: true } };
helper.detectChanges();
expect(helper.find('.export-comment-button').attr('style')).toEqual("display: none; ");
});
});
});