diff --git a/src/app/article/comment/comments.component.spec.ts b/src/app/article/comment/comments.component.spec.ts
index fcf97a9..7076529 100644
--- a/src/app/article/comment/comments.component.spec.ts
+++ b/src/app/article/comment/comments.component.spec.ts
@@ -2,6 +2,7 @@ import {Provider, provide, Component} from 'ng-forward';
import * as helpers from "../../../spec/helpers";
import {CommentsComponent} from './comments.component';
+import {PostCommentComponent} from "./post-comment.component";
const htmlTemplate: string = '';
@@ -42,8 +43,9 @@ describe("Components", () => {
it("update comments list when receive an event", done => {
helpers.createComponentFromClass(ContainerComponent).then(fixture => {
- fixture.debugElement.getLocal("$rootScope").$emit("comment.received", {});
- expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(1);
+ fixture.debugElement.getLocal("$rootScope").$emit(PostCommentComponent.EVENT_COMMENT_RECEIVED, { id: 1 });
+ fixture.debugElement.getLocal("$rootScope").$apply();
+ 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 68f2e76..a488efd 100644
--- a/src/app/article/comment/comments.component.ts
+++ b/src/app/article/comment/comments.component.ts
@@ -15,7 +15,7 @@ export class CommentsComponent {
@Input() article: noosfero.Article;
constructor(private commentService: CommentService, private $rootScope: ng.IScope) {
- $rootScope.$on("comment.received", (event: ng.IAngularEvent, comment: noosfero.Comment) => {
+ $rootScope.$on(PostCommentComponent.EVENT_COMMENT_RECEIVED, (event: ng.IAngularEvent, comment: noosfero.Comment) => {
this.comments.push(comment);
});
}
diff --git a/src/app/article/comment/post-comment.component.ts b/src/app/article/comment/post-comment.component.ts
index c940fdb..f0a1012 100644
--- a/src/app/article/comment/post-comment.component.ts
+++ b/src/app/article/comment/post-comment.component.ts
@@ -9,6 +9,8 @@ import { NotificationService } from "../../shared/services/notification.service"
@Inject(CommentService, NotificationService, "$rootScope")
export class PostCommentComponent {
+ public static EVENT_COMMENT_RECEIVED = "comment.received";
+
@Input() article: noosfero.Article;
comment: noosfero.Comment;
@@ -21,7 +23,7 @@ export class PostCommentComponent {
this.comment.reply_of_id = this.replyOf.id;
}
this.commentService.createInArticle(this.article, this.comment).then((result: noosfero.RestResult) => {
- this.$rootScope.$emit("comment.received", result.data);
+ this.$rootScope.$emit(PostCommentComponent.EVENT_COMMENT_RECEIVED, result.data);
this.notificationService.success({ title: "Good job!", message: "Comment saved!" });
});
}
--
libgit2 0.21.2