comment.component.spec.ts
2.58 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 {Provider, provide, Component} from 'ng-forward';
import * as helpers from "../../../spec/helpers";
import {CommentComponent} from './comment.component';
import {PostCommentComponent} from './post-comment/post-comment.component';
const htmlTemplate: string = '<noosfero-comment [article]="ctrl.article" [comment]="ctrl.comment"></noosfero-comment>';
describe("Components", () => {
describe("Comment Component", () => {
beforeEach(angular.mock.module("templates"));
let postCommentEventService = jasmine.createSpyObj("postCommentEventService", ["subscribe"]);
function createComponent() {
let providers = [
new Provider('PostCommentEventService', { useValue: postCommentEventService })
].concat(helpers.provideFilters("translateFilter"));
@Component({ selector: 'test-container-component', directives: [CommentComponent], template: htmlTemplate, providers: providers })
class ContainerComponent {
article = { id: 1 };
comment = { title: "title", body: "body" };
}
return helpers.createComponentFromClass(ContainerComponent);
}
it("render a comment", done => {
createComponent().then(fixture => {
expect(fixture.debugElement.queryAll(".comment").length).toEqual(1);
done();
});
});
it("not render a post comment tag in the beginning", done => {
createComponent().then(fixture => {
expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(0);
done();
});
});
it("set show reply to true when click reply", done => {
createComponent().then(fixture => {
let component: CommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
component.reply();
expect(component.showReply).toBeTruthy(1);
done();
});
});
it("close form when receive a reply", done => {
let func: Function;
postCommentEventService.subscribe = (fn: Function) => {
func = fn;
};
createComponent().then(fixture => {
let component = fixture.debugElement.componentViewChildren[0];
component.componentInstance.showReply = true;
func(<noosfero.Comment>{});
expect(component.componentInstance.showReply).toEqual(false);
done();
});
});
});
});