From 2ebd4ad01385ec66ab6bfaddd4cbae23e8ca938e Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 4 Apr 2016 11:58:06 -0300 Subject: [PATCH] Toggle reply form when clicked from comment component --- src/app/article/comment/comment.component.spec.ts | 29 ++++++++++++++++++++++------- src/app/article/comment/comment.component.ts | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/app/article/comment/comment.component.spec.ts b/src/app/article/comment/comment.component.spec.ts index 332e08e..0b0c812 100644 --- a/src/app/article/comment/comment.component.spec.ts +++ b/src/app/article/comment/comment.component.spec.ts @@ -2,6 +2,7 @@ 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 = ''; @@ -10,28 +11,33 @@ describe("Components", () => { beforeEach(angular.mock.module("templates")); - @Component({ selector: 'test-container-component', directives: [CommentComponent], template: htmlTemplate, providers: helpers.provideFilters("translateFilter") }) - class ContainerComponent { - article = { id: 1 }; - comment = { title: "title", body: "body" }; + function createComponent() { + let providers = 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 => { - helpers.createComponentFromClass(ContainerComponent).then(fixture => { + createComponent().then(fixture => { expect(fixture.debugElement.queryAll(".comment").length).toEqual(1); done(); }); }); it("not render a post comment tag in the beginning", done => { - helpers.createComponentFromClass(ContainerComponent).then(fixture => { + createComponent().then(fixture => { expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(0); done(); }); }); it("set show reply to true when click reply", done => { - helpers.createComponentFromClass(ContainerComponent).then(fixture => { + createComponent().then(fixture => { let component: CommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance; component.reply(); expect(component.showReply).toBeTruthy(1); @@ -39,5 +45,14 @@ describe("Components", () => { }); }); + it("close form when receive a reply", done => { + createComponent().then(fixture => { + let component = fixture.debugElement.componentViewChildren[0]; + component.componentInstance.showReply = true; + fixture.debugElement.getLocal("$rootScope").$broadcast(PostCommentComponent.EVENT_COMMENT_RECEIVED, {}); + expect(component.componentInstance.showReply).toEqual(false); + done(); + }); + }); }); }); diff --git a/src/app/article/comment/comment.component.ts b/src/app/article/comment/comment.component.ts index 2d041bb..adafabd 100644 --- a/src/app/article/comment/comment.component.ts +++ b/src/app/article/comment/comment.component.ts @@ -20,6 +20,6 @@ export class CommentComponent { } reply() { - this.showReply = true; + this.showReply = !this.showReply; } } -- libgit2 0.21.2