diff --git a/src/app/article/comment/comments.component.spec.ts b/src/app/article/comment/comments.component.spec.ts index 771ed50..6ce43c5 100644 --- a/src/app/article/comment/comments.component.spec.ts +++ b/src/app/article/comment/comments.component.spec.ts @@ -54,8 +54,8 @@ describe("Components", () => { properties.parent = { id: 3 }; createComponent().then(fixture => { let component = (fixture.debugElement.componentViewChildren[0].componentInstance); - component.commentService.onSave.next.call(component, { id: 1, reply_of: { id: 3 } }); - console.log('Comments: ' + component.comments.length); + component.commentAdded({ id: 1, reply_of: { id: 3 } }); + fixture.detectChanges(); expect(fixture.debugElement.queryAll("noosfero-comment").length).toEqual(3); done(); diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts index c1153f9..5b85eb2 100644 --- a/src/app/article/comment/comments.component.ts +++ b/src/app/article/comment/comments.component.ts @@ -31,20 +31,16 @@ export class CommentsComponent { } this.commentService.onSave.subscribe((comment: noosfero.Comment) => { - this.comments.push(comment); - this.resetShowReply(); + this.commentAdded(comment); }); } - private resetShowReply() { - this.comments.forEach((comment: noosfero.CommentViewModel) => { - comment.__show_reply = false; - }); - if (this.parent) { - this.parent.__show_reply = false; - } + commentAdded(comment: noosfero.Comment): void { + this.comments.push(comment); + this.resetShowReply(); } + loadComments() { return this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage }); } @@ -61,4 +57,13 @@ export class CommentsComponent { let pages = Math.ceil(this.total / this.perPage); return !this.parent && pages >= this.page; } + + private resetShowReply() { + this.comments.forEach((comment: noosfero.CommentViewModel) => { + comment.__show_reply = false; + }); + if (this.parent) { + this.parent.__show_reply = false; + } + } } diff --git a/src/spec/mocks.ts b/src/spec/mocks.ts index dd8ded7..20cf50e 100644 --- a/src/spec/mocks.ts +++ b/src/spec/mocks.ts @@ -131,7 +131,7 @@ export var mocks: any = { mocks.commentService['onSave'].event = fn; }, next: (param: any) => { - mocks.commentService['onSave'].event.call(this, param); + mocks.commentService['onSave'].event(param); } } }, -- libgit2 0.21.2