Commit 77280cd9436211e954ff7407a24f3bd3de3d3696
1 parent
64a50639
Fix the unit spec of CommentsComponent update comments
Showing
3 changed files
with
17 additions
and
12 deletions
Show diff stats
src/app/article/comment/comments.component.spec.ts
| ... | ... | @@ -54,8 +54,8 @@ describe("Components", () => { |
| 54 | 54 | properties.parent = { id: 3 }; |
| 55 | 55 | createComponent().then(fixture => { |
| 56 | 56 | let component = (<CommentsComponent>fixture.debugElement.componentViewChildren[0].componentInstance); |
| 57 | - component.commentService.onSave.next.call(component, <noosfero.Comment>{ id: 1, reply_of: { id: 3 } }); | |
| 58 | - console.log('Comments: ' + component.comments.length); | |
| 57 | + component.commentAdded(<noosfero.Comment>{ id: 1, reply_of: { id: 3 } }); | |
| 58 | + | |
| 59 | 59 | fixture.detectChanges(); |
| 60 | 60 | expect(fixture.debugElement.queryAll("noosfero-comment").length).toEqual(3); |
| 61 | 61 | done(); | ... | ... |
src/app/article/comment/comments.component.ts
| ... | ... | @@ -31,20 +31,16 @@ export class CommentsComponent { |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | this.commentService.onSave.subscribe((comment: noosfero.Comment) => { |
| 34 | - this.comments.push(comment); | |
| 35 | - this.resetShowReply(); | |
| 34 | + this.commentAdded(comment); | |
| 36 | 35 | }); |
| 37 | 36 | } |
| 38 | 37 | |
| 39 | - private resetShowReply() { | |
| 40 | - this.comments.forEach((comment: noosfero.CommentViewModel) => { | |
| 41 | - comment.__show_reply = false; | |
| 42 | - }); | |
| 43 | - if (this.parent) { | |
| 44 | - this.parent.__show_reply = false; | |
| 45 | - } | |
| 38 | + commentAdded(comment: noosfero.Comment): void { | |
| 39 | + this.comments.push(comment); | |
| 40 | + this.resetShowReply(); | |
| 46 | 41 | } |
| 47 | 42 | |
| 43 | + | |
| 48 | 44 | loadComments() { |
| 49 | 45 | return this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage }); |
| 50 | 46 | } |
| ... | ... | @@ -61,4 +57,13 @@ export class CommentsComponent { |
| 61 | 57 | let pages = Math.ceil(this.total / this.perPage); |
| 62 | 58 | return !this.parent && pages >= this.page; |
| 63 | 59 | } |
| 60 | + | |
| 61 | + private resetShowReply() { | |
| 62 | + this.comments.forEach((comment: noosfero.CommentViewModel) => { | |
| 63 | + comment.__show_reply = false; | |
| 64 | + }); | |
| 65 | + if (this.parent) { | |
| 66 | + this.parent.__show_reply = false; | |
| 67 | + } | |
| 68 | + } | |
| 64 | 69 | } | ... | ... |
src/spec/mocks.ts