Commit 77280cd9436211e954ff7407a24f3bd3de3d3696

Authored by Michel Felipe
1 parent 64a50639

Fix the unit spec of CommentsComponent update comments

src/app/article/comment/comments.component.spec.ts
@@ -54,8 +54,8 @@ describe("Components", () => { @@ -54,8 +54,8 @@ describe("Components", () => {
54 properties.parent = { id: 3 }; 54 properties.parent = { id: 3 };
55 createComponent().then(fixture => { 55 createComponent().then(fixture => {
56 let component = (<CommentsComponent>fixture.debugElement.componentViewChildren[0].componentInstance); 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 fixture.detectChanges(); 59 fixture.detectChanges();
60 expect(fixture.debugElement.queryAll("noosfero-comment").length).toEqual(3); 60 expect(fixture.debugElement.queryAll("noosfero-comment").length).toEqual(3);
61 done(); 61 done();
src/app/article/comment/comments.component.ts
@@ -31,20 +31,16 @@ export class CommentsComponent { @@ -31,20 +31,16 @@ export class CommentsComponent {
31 } 31 }
32 32
33 this.commentService.onSave.subscribe((comment: noosfero.Comment) => { 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 loadComments() { 44 loadComments() {
49 return this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage }); 45 return this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage });
50 } 46 }
@@ -61,4 +57,13 @@ export class CommentsComponent { @@ -61,4 +57,13 @@ export class CommentsComponent {
61 let pages = Math.ceil(this.total / this.perPage); 57 let pages = Math.ceil(this.total / this.perPage);
62 return !this.parent && pages >= this.page; 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
@@ -131,7 +131,7 @@ export var mocks: any = { @@ -131,7 +131,7 @@ export var mocks: any = {
131 mocks.commentService['onSave'].event = fn; 131 mocks.commentService['onSave'].event = fn;
132 }, 132 },
133 next: (param: any) => { 133 next: (param: any) => {
134 - mocks.commentService['onSave'].event.call(this, param); 134 + mocks.commentService['onSave'].event(param);
135 } 135 }
136 } 136 }
137 }, 137 },