comments.component.spec.ts
2.1 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
import {Provider, provide, Component} from 'ng-forward';
import * as helpers from "../../../spec/helpers";
import {CommentsComponent} from './comments.component';
const htmlTemplate: string = '<noosfero-comments [article]="ctrl.article"></noosfero-comments>';
describe("Components", () => {
describe("Comments Component", () => {
beforeEach(angular.mock.module("templates"));
let commentService = jasmine.createSpyObj("commentService", ["getByArticle"]);
let comments = [{ id: 2 }, { id: 3 }];
commentService.getByArticle = jasmine.createSpy("getByArticle")
.and.returnValue(helpers.mocks.promiseResultTemplate({ data: comments }));
let providers = [
new Provider('CommentService', { useValue: commentService }),
new Provider('NotificationService', { useValue: helpers.mocks.notificationService })
].concat(helpers.provideFilters("translateFilter"));
@Component({ selector: 'test-container-component', directives: [CommentsComponent], template: htmlTemplate, providers: providers })
class ContainerComponent {
article = { id: 1 };
}
it("render comments associated to an article", done => {
helpers.createComponentFromClass(ContainerComponent).then(fixture => {
expect(fixture.debugElement.queryAll("noosfero-comment").length).toEqual(2);
done();
});
});
it("render a post comment tag", done => {
helpers.createComponentFromClass(ContainerComponent).then(fixture => {
expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(1);
done();
});
});
it("update comments list when receive an event", done => {
helpers.createComponentFromClass(ContainerComponent).then(fixture => {
fixture.debugElement.getLocal("$rootScope").$emit("comment.received", {});
expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(1);
done();
});
});
});
});