Commit e8918c1033e9bae4836437c5a5f0dbe04c43e420

Authored by Victor Costa
1 parent e757c2bb
Exists in master and in 1 other branch dev-fixes

Add tests to comments component

src/app/article/article.html
... ... @@ -21,5 +21,5 @@
21 21 <div ng-bind-html="ctrl.article.body"></div>
22 22 </div>
23 23  
24   - <comments [article]="ctrl.article"></comments>
  24 + <noosfero-comments [article]="ctrl.article"></noosfero-comments>
25 25 </div>
... ...
src/app/article/comment/comment.component.ts
1 1 import { Input, Component } from 'ng-forward';
2 2  
3 3 @Component({
4   - selector: 'comment',
  4 + selector: 'noosfero-comment',
5 5 templateUrl: 'app/article/comment/comment.html'
6 6 })
7 7 export class CommentComponent {
... ...
src/app/article/comment/comment.html
... ... @@ -20,6 +20,6 @@
20 20 <div class="body">{{ctrl.comment.body}}</div>
21 21 </div>
22 22  
23   - <post-comment ng-if="ctrl.showReply" [article]="ctrl.article" [reply-of]="ctrl.comment"></post-comment>
  23 + <noosfero-post-comment ng-if="ctrl.showReply" [article]="ctrl.article" [reply-of]="ctrl.comment"></noosfero-post-comment>
24 24  
25 25 </div>
... ...
src/app/article/comment/comments.component.spec.ts 0 → 100644
... ... @@ -0,0 +1,52 @@
  1 +import {Provider, provide, Component} from 'ng-forward';
  2 +import * as helpers from "../../../spec/helpers";
  3 +
  4 +import {CommentsComponent} from './comments.component';
  5 +
  6 +const htmlTemplate: string = '<noosfero-comments [article]="ctrl.article"></noosfero-comments>';
  7 +
  8 +describe("Components", () => {
  9 + describe("Comments Component", () => {
  10 +
  11 + beforeEach(angular.mock.module("templates"));
  12 +
  13 + let commentService = jasmine.createSpyObj("commentService", ["getByArticle"]);
  14 +
  15 + let comments = [{ id: 2 }, { id: 3 }];
  16 + commentService.getByArticle = jasmine.createSpy("getByArticle")
  17 + .and.returnValue(helpers.mocks.promiseResultTemplate({ data: comments }));
  18 +
  19 + let providers = [
  20 + new Provider('CommentService', { useValue: commentService }),
  21 + new Provider('NotificationService', { useValue: helpers.mocks.notificationService })
  22 + ].concat(helpers.provideFilters("translateFilter"));
  23 +
  24 + @Component({ selector: 'test-container-component', directives: [CommentsComponent], template: htmlTemplate, providers: providers })
  25 + class ContainerComponent {
  26 + article = { id: 1 };
  27 + }
  28 +
  29 + it("render comments associated to an article", done => {
  30 + helpers.createComponentFromClass(ContainerComponent).then(fixture => {
  31 + expect(fixture.debugElement.queryAll("noosfero-comment").length).toEqual(2);
  32 + done();
  33 + });
  34 + });
  35 +
  36 + it("render a post comment tag", done => {
  37 + helpers.createComponentFromClass(ContainerComponent).then(fixture => {
  38 + expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(1);
  39 + done();
  40 + });
  41 + });
  42 +
  43 + it("update comments list when receive an event", done => {
  44 + helpers.createComponentFromClass(ContainerComponent).then(fixture => {
  45 + fixture.debugElement.getLocal("$rootScope").$emit("comment.received", {});
  46 + expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(1);
  47 + done();
  48 + });
  49 + });
  50 +
  51 + });
  52 +});
... ...
src/app/article/comment/comments.component.ts
... ... @@ -4,7 +4,7 @@ import { CommentService } from &quot;../../../lib/ng-noosfero-api/http/comment.servic
4 4 import { CommentComponent } from "./comment.component";
5 5  
6 6 @Component({
7   - selector: 'comments',
  7 + selector: 'noosfero-comments',
8 8 templateUrl: 'app/article/comment/comments.html',
9 9 directives: [PostCommentComponent, CommentComponent]
10 10 })
... ...
src/app/article/comment/comments.html
1 1 <div class="comments">
2   - <post-comment [article]="ctrl.article"></post-comment>
  2 + <noosfero-post-comment [article]="ctrl.article"></noosfero-post-comment>
3 3  
4 4 <div class="comments-list">
5   - <comment ng-repeat="comment in ctrl.comments" [comment]="comment" [article]="ctrl.article"></comment>
  5 + <noosfero-comment ng-repeat="comment in ctrl.comments" [comment]="comment" [article]="ctrl.article"></noosfero-comment>
6 6 </div>
7 7 </div>
... ...
src/app/article/comment/post-comment.component.ts
... ... @@ -3,7 +3,7 @@ import { CommentService } from &quot;../../../lib/ng-noosfero-api/http/comment.servic
3 3 import { NotificationService } from "../../shared/services/notification.service";
4 4  
5 5 @Component({
6   - selector: 'post-comment',
  6 + selector: 'noosfero-post-comment',
7 7 templateUrl: 'app/article/comment/post-comment.html'
8 8 })
9 9 @Inject(CommentService, NotificationService, "$rootScope")
... ...