Commit e8918c1033e9bae4836437c5a5f0dbe04c43e420
1 parent
e757c2bb
Exists in
master
and in
1 other branch
Add tests to comments component
Showing
7 changed files
with
59 additions
and
7 deletions
Show diff stats
src/app/article/article.html
src/app/article/comment/comment.component.ts
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> | ... | ... |
| ... | ... | @@ -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 "../../../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 "../../../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") | ... | ... |