diff --git a/src/app/article/comment/comment.component.spec.ts b/src/app/article/comment/comment.component.spec.ts index 5ba026c..7603d07 100644 --- a/src/app/article/comment/comment.component.spec.ts +++ b/src/app/article/comment/comment.component.spec.ts @@ -8,6 +8,8 @@ describe("Components", () => { describe("Comment Component", () => { let properties: any; + let notificationService = helpers.mocks.notificationService; + let commentService = jasmine.createSpyObj("commentService", ["removeFromArticle"]); beforeEach(angular.mock.module("templates")); beforeEach(() => { @@ -18,9 +20,8 @@ describe("Components", () => { }); function createComponent() { - let commentService = jasmine.createSpyObj("commentService", ["removeFromArticle"]); let providers = [ - helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService), + helpers.createProviderToValue('NotificationService', notificationService), helpers.createProviderToValue("CommentService", commentService) ].concat(helpers.provideFilters("translateFilter")); @@ -78,5 +79,16 @@ describe("Components", () => { done(); }); }); + + it("call comment service to remove comment", done => { + notificationService.confirmation = (params: any, func: Function) => { func(); }; + commentService.removeFromArticle = jasmine.createSpy("removeFromArticle").and.returnValue(Promise.resolve()); + createComponent().then(fixture => { + let component = fixture.debugElement.componentViewChildren[0].componentInstance; + component.remove(); + expect(commentService.removeFromArticle).toHaveBeenCalled(); + done(); + }); + }); }); }); diff --git a/src/app/article/comment/comment.component.ts b/src/app/article/comment/comment.component.ts index 822b0f6..d841123 100644 --- a/src/app/article/comment/comment.component.ts +++ b/src/app/article/comment/comment.component.ts @@ -5,6 +5,7 @@ import { NotificationService } from "../../shared/services/notification.service" @Component({ selector: 'noosfero-comment', + outputs: ['commentRemoved'], templateUrl: 'app/article/comment/comment.html' }) @Inject(CommentService, NotificationService) @@ -14,6 +15,7 @@ export class CommentComponent { @Input() article: noosfero.Article; @Input() displayActions = true; @Input() displayReplies = true; + @Output() commentRemoved: EventEmitter = new EventEmitter(); showReply() { return this.comment && this.comment.__show_reply === true; @@ -33,7 +35,7 @@ export class CommentComponent { remove() { this.notificationService.confirmation({ title: "comment.remove.confirmation.title", message: "comment.remove.confirmation.message" }, () => { this.commentService.removeFromArticle(this.article, this.comment).then((result: noosfero.RestResult) => { - // FIXME send event + this.commentRemoved.next(this.comment); this.notificationService.success({ title: "comment.remove.success.title", message: "comment.remove.success.message" }); }); }); diff --git a/src/app/article/comment/comments.component.spec.ts b/src/app/article/comment/comments.component.spec.ts index 2c33512..b406994 100644 --- a/src/app/article/comment/comments.component.spec.ts +++ b/src/app/article/comment/comments.component.spec.ts @@ -83,5 +83,26 @@ describe("Components", () => { }); }); + it("remove comment when calling commentRemoved", done => { + createComponent().then(fixture => { + let component: CommentsComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + let comment = { id: 1 }; + component.comments = [comment]; + component.commentRemoved(comment); + expect(component.comments).toEqual([]); + done(); + }); + }); + + it("do nothing when call commentRemoved with a comment that doesn't belongs to the comments list", done => { + createComponent().then(fixture => { + let component: CommentsComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + let comment = { id: 1 }; + component.comments = [comment]; + component.commentRemoved({ id: 2 }); + expect(component.comments).toEqual([comment]); + done(); + }); + }); }); }); diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts index 7da9533..64651f8 100644 --- a/src/app/article/comment/comments.component.ts +++ b/src/app/article/comment/comments.component.ts @@ -37,6 +37,13 @@ export class CommentsComponent { this.resetShowReply(); } + commentRemoved(comment: noosfero.Comment): void { + let index = this.comments.indexOf(comment, 0); + if (index >= 0) { + this.comments.splice(index, 1); + } + } + private resetShowReply() { this.comments.forEach((comment: noosfero.CommentViewModel) => { comment.__show_reply = false; diff --git a/src/app/article/comment/comments.html b/src/app/article/comment/comments.html index cf08d05..efb3d11 100644 --- a/src/app/article/comment/comments.html +++ b/src/app/article/comment/comments.html @@ -2,7 +2,7 @@
- +
-- libgit2 0.21.2