diff --git a/src/app/article/comment/comment.component.spec.ts b/src/app/article/comment/comment.component.spec.ts
index 3955702..332e08e 100644
--- a/src/app/article/comment/comment.component.spec.ts
+++ b/src/app/article/comment/comment.component.spec.ts
@@ -30,12 +30,11 @@ describe("Components", () => {
});
});
- it("render a post comment tag when click in reply", done => {
+ it("set show reply to true when click reply", done => {
helpers.createComponentFromClass(ContainerComponent).then(fixture => {
let component: CommentComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
component.reply();
- fixture.debugElement.getLocal("$rootScope").$apply();
- expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(1);
+ expect(component.showReply).toBeTruthy(1);
done();
});
});
diff --git a/src/app/article/comment/comment.component.ts b/src/app/article/comment/comment.component.ts
index b891cfd..2d041bb 100644
--- a/src/app/article/comment/comment.component.ts
+++ b/src/app/article/comment/comment.component.ts
@@ -1,9 +1,11 @@
-import { Input, Component } from 'ng-forward';
+import { Inject, Input, Component } from 'ng-forward';
+import { PostCommentComponent } from "./post-comment/post-comment.component";
@Component({
selector: 'noosfero-comment',
templateUrl: 'app/article/comment/comment.html'
})
+@Inject("$scope")
export class CommentComponent {
@Input() comment: noosfero.Comment;
@@ -11,6 +13,12 @@ export class CommentComponent {
showReply: boolean = false;
+ constructor(private $scope: ng.IScope) {
+ $scope.$on(PostCommentComponent.EVENT_COMMENT_RECEIVED, (event: ng.IAngularEvent, comment: noosfero.Comment) => {
+ this.showReply = false;
+ });
+ }
+
reply() {
this.showReply = true;
}
diff --git a/src/app/article/comment/comment.html b/src/app/article/comment/comment.html
index 5bf0eaf..4f312bd 100644
--- a/src/app/article/comment/comment.html
+++ b/src/app/article/comment/comment.html
@@ -19,7 +19,5 @@
{{ctrl.comment.title}}
{{ctrl.comment.body}}
-
-
-
+
diff --git a/src/app/article/comment/comments.component.spec.ts b/src/app/article/comment/comments.component.spec.ts
index e17664f..d3a3dfe 100644
--- a/src/app/article/comment/comments.component.spec.ts
+++ b/src/app/article/comment/comments.component.spec.ts
@@ -22,33 +22,39 @@ describe("Components", () => {
new Provider('NotificationService', { useValue: helpers.mocks.notificationService })
].concat(helpers.provideFilters("translateFilter"));
- @Component({ selector: 'test-container-component', directives: [CommentsComponent], template: htmlTemplate, providers: providers })
- class ContainerComponent {
- article = { id: 1 };
+ let properties = { article: { id: 1 }, parent: null };
+ function createComponent() {
+ return helpers.quickCreateComponent({
+ providers: providers,
+ directives: [CommentsComponent],
+ template: htmlTemplate,
+ properties: properties
+ });
}
+
it("render comments associated to an article", done => {
- helpers.createComponentFromClass(ContainerComponent).then(fixture => {
+ createComponent().then(fixture => {
expect(fixture.debugElement.queryAll("noosfero-comment").length).toEqual(2);
done();
});
});
it("render a post comment tag", done => {
- helpers.createComponentFromClass(ContainerComponent).then(fixture => {
+ createComponent().then(fixture => {
expect(fixture.debugElement.queryAll("noosfero-post-comment").length).toEqual(1);
done();
});
});
- it("update comments list when receive an event", done => {
- helpers.createComponentFromClass(ContainerComponent).then(fixture => {
- fixture.debugElement.getLocal("$rootScope").$emit(PostCommentComponent.EVENT_COMMENT_RECEIVED, { id: 1 });
+ it("update comments list when receive an reply", done => {
+ properties.parent = { id: 2 };
+ createComponent().then(fixture => {
+ fixture.debugElement.getLocal("$rootScope").$emit(PostCommentComponent.EVENT_COMMENT_RECEIVED, { id: 1, reply_of: properties.parent });
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 f182807..30cc96b 100644
--- a/src/app/article/comment/comments.component.ts
+++ b/src/app/article/comment/comments.component.ts
@@ -12,17 +12,26 @@ import { CommentComponent } from "./comment.component";
export class CommentsComponent {
comments: noosfero.Comment[] = [];
+ @Input() showForm = true;
@Input() article: noosfero.Article;
+ @Input() parent: noosfero.Comment;
constructor(private commentService: CommentService, private $rootScope: ng.IScope) {
$rootScope.$on(PostCommentComponent.EVENT_COMMENT_RECEIVED, (event: ng.IAngularEvent, comment: noosfero.Comment) => {
- this.comments.push(comment);
+ if ((!this.parent && !comment.reply_of) || (comment.reply_of && this.parent && comment.reply_of.id === this.parent.id)) {
+ if (!this.comments) this.comments = [];
+ this.comments.push(comment);
+ }
});
}
ngOnInit() {
- this.commentService.getByArticle(this.article).then((result: noosfero.RestResult) => {
- this.comments = result.data;
- });
+ if (this.parent) {
+ this.comments = this.parent.replies;
+ } else {
+ this.commentService.getByArticle(this.article).then((result: noosfero.RestResult) => {
+ this.comments = result.data;
+ });
+ }
}
}
diff --git a/src/app/article/comment/comments.html b/src/app/article/comment/comments.html
index 88dd8b2..3253b2d 100644
--- a/src/app/article/comment/comments.html
+++ b/src/app/article/comment/comments.html
@@ -1,5 +1,5 @@