diff --git a/src/app/article/comment/comments.component.spec.ts b/src/app/article/comment/comments.component.spec.ts index 9d51b4b..9c12ebf 100644 --- a/src/app/article/comment/comments.component.spec.ts +++ b/src/app/article/comment/comments.component.spec.ts @@ -60,14 +60,27 @@ describe("Components", () => { it("load comments for next page", done => { createComponent().then(fixture => { + let headers = jasmine.createSpy("headers").and.returnValue(3); commentService.getByArticle = jasmine.createSpy("getByArticle") - .and.returnValue(helpers.mocks.promiseResultTemplate({ data: { id: 4 } })); + .and.returnValue(helpers.mocks.promiseResultTemplate({ data: { id: 4 }, headers: headers })); let component: CommentsComponent = fixture.debugElement.componentViewChildren[0].componentInstance; component.loadNextPage(); expect(component['page']).toEqual(3); expect(component.comments.length).toEqual(3); + expect(component['total']).toEqual(3); done(); }); }); + + it("not display more when there is no more comments to load", done => { + createComponent().then(fixture => { + let component: CommentsComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + component['total'] = 0; + component.parent = null; + expect(component.displayMore()).toBeFalsy(); + done(); + }); + }); + }); }); diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts index 87ea5f3..23699f1 100644 --- a/src/app/article/comment/comments.component.ts +++ b/src/app/article/comment/comments.component.ts @@ -17,6 +17,7 @@ export class CommentsComponent { @Input() parent: noosfero.Comment; private page = 1; private perPage = 5; + private total = 0; constructor(private commentService: CommentService, private $rootScope: ng.IScope) { $rootScope.$on(PostCommentComponent.EVENT_COMMENT_RECEIVED, (event: ng.IAngularEvent, comment: noosfero.Comment) => { @@ -38,7 +39,13 @@ export class CommentsComponent { loadNextPage() { this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage }).then((result: noosfero.RestResult) => { this.comments = this.comments.concat(result.data); + this.total = result.headers ? result.headers("total") : this.comments.length; this.page++; }); } + + displayMore() { + let pages = Math.ceil(this.total / this.perPage); + return !this.parent && pages >= this.page; + } } diff --git a/src/app/article/comment/comments.html b/src/app/article/comment/comments.html index f7aa1ec..09137da 100644 --- a/src/app/article/comment/comments.html +++ b/src/app/article/comment/comments.html @@ -4,5 +4,5 @@
- + -- libgit2 0.21.2