Commit 2ebd4ad01385ec66ab6bfaddd4cbae23e8ca938e

Authored by Victor Costa
1 parent 4b876c39

Toggle reply form when clicked from comment component

src/app/article/comment/comment.component.spec.ts
... ... @@ -2,6 +2,7 @@ import {Provider, provide, Component} from 'ng-forward';
2 2 import * as helpers from "../../../spec/helpers";
3 3  
4 4 import {CommentComponent} from './comment.component';
  5 +import {PostCommentComponent} from './post-comment/post-comment.component';
5 6  
6 7 const htmlTemplate: string = '<noosfero-comment [article]="ctrl.article" [comment]="ctrl.comment"></noosfero-comment>';
7 8  
... ... @@ -10,28 +11,33 @@ describe(&quot;Components&quot;, () =&gt; {
10 11  
11 12 beforeEach(angular.mock.module("templates"));
12 13  
13   - @Component({ selector: 'test-container-component', directives: [CommentComponent], template: htmlTemplate, providers: helpers.provideFilters("translateFilter") })
14   - class ContainerComponent {
15   - article = { id: 1 };
16   - comment = { title: "title", body: "body" };
  14 + function createComponent() {
  15 + let providers = helpers.provideFilters("translateFilter");
  16 +
  17 + @Component({ selector: 'test-container-component', directives: [CommentComponent], template: htmlTemplate, providers: providers })
  18 + class ContainerComponent {
  19 + article = { id: 1 };
  20 + comment = { title: "title", body: "body" };
  21 + }
  22 + return helpers.createComponentFromClass(ContainerComponent);
17 23 }
18 24  
19 25 it("render a comment", done => {
20   - helpers.createComponentFromClass(ContainerComponent).then(fixture => {
  26 + createComponent().then(fixture => {
21 27 expect(fixture.debugElement.queryAll(".comment").length).toEqual(1);
22 28 done();
23 29 });
24 30 });
25 31  
26 32 it("not render a post comment tag in the beginning", done => {
27   - helpers.createComponentFromClass(ContainerComponent).then(fixture => {
  33 + createComponent().then(fixture => {
28 34 expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(0);
29 35 done();
30 36 });
31 37 });
32 38  
33 39 it("set show reply to true when click reply", done => {
34   - helpers.createComponentFromClass(ContainerComponent).then(fixture => {
  40 + createComponent().then(fixture => {
35 41 let component: CommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
36 42 component.reply();
37 43 expect(component.showReply).toBeTruthy(1);
... ... @@ -39,5 +45,14 @@ describe(&quot;Components&quot;, () =&gt; {
39 45 });
40 46 });
41 47  
  48 + it("close form when receive a reply", done => {
  49 + createComponent().then(fixture => {
  50 + let component = fixture.debugElement.componentViewChildren[0];
  51 + component.componentInstance.showReply = true;
  52 + fixture.debugElement.getLocal("$rootScope").$broadcast(PostCommentComponent.EVENT_COMMENT_RECEIVED, {});
  53 + expect(component.componentInstance.showReply).toEqual(false);
  54 + done();
  55 + });
  56 + });
42 57 });
43 58 });
... ...
src/app/article/comment/comment.component.ts
... ... @@ -20,6 +20,6 @@ export class CommentComponent {
20 20 }
21 21  
22 22 reply() {
23   - this.showReply = true;
  23 + this.showReply = !this.showReply;
24 24 }
25 25 }
... ...