From 3fd6b5d230def38029fa0227e488b4f21ff56a50 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Wed, 6 Feb 2019 23:45:26 +0000 Subject: [PATCH] fix infinite pagination test (#4279) --- .../document-list.component.spec.ts | 23 ++++++++------ .../infinite-pagination.component.spec.ts | 31 +++++++++++++++---- .../infinite-pagination.component.ts | 7 ++++- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/lib/content-services/document-list/components/document-list.component.spec.ts b/lib/content-services/document-list/components/document-list.component.spec.ts index a6b27b76e9..27c2a2ead4 100644 --- a/lib/content-services/document-list/components/document-list.component.spec.ts +++ b/lib/content-services/document-list/components/document-list.component.spec.ts @@ -941,7 +941,10 @@ describe('DocumentList', () => { it('should load folder by ID on init', () => { spyOn(documentList, 'loadFolder').and.returnValue(Promise.resolve()); - documentList.ngOnChanges({ currentFolderId: new SimpleChange(null, '1d26e465-dea3-42f3-b415-faa8364b9692', true) }); + documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692'; + + fixture.detectChanges(); + expect(documentList.loadFolder).toHaveBeenCalled(); }); @@ -1261,12 +1264,12 @@ describe('DocumentList', () => { }); it('should add includeFields in the server request when present', () => { - fixture.detectChanges(); - documentList.currentFolderId = 'fake-id'; - documentList.includeFields = ['test-include']; spyOn(documentListService, 'getFolder').and.callThrough(); - documentList.ngOnChanges({ currentFolderId: new SimpleChange(null, '-root-', false) }); + documentList.includeFields = ['test-include']; + documentList.currentFolderId = 'fake-id'; + + fixture.detectChanges(); expect(documentListService.getFolder).toHaveBeenCalledWith(null, { where: undefined, @@ -1277,13 +1280,13 @@ describe('DocumentList', () => { }); it('should add where in the server request when present', () => { - fixture.detectChanges(); - documentList.currentFolderId = 'fake-id'; - documentList.includeFields = ['test-include']; - documentList.where = '(isFolder=true)'; spyOn(documentListService, 'getFolder').and.callThrough(); - documentList.ngOnChanges({ currentFolderId: new SimpleChange(null, '-root-', false) }); + documentList.includeFields = ['test-include']; + documentList.where = '(isFolder=true)'; + documentList.currentFolderId = 'fake-id'; + + fixture.detectChanges(); expect(documentListService.getFolder).toHaveBeenCalledWith(null, { where: '(isFolder=true)', diff --git a/lib/core/pagination/infinite-pagination.component.spec.ts b/lib/core/pagination/infinite-pagination.component.spec.ts index 650a76f060..d8a0718bc4 100644 --- a/lib/core/pagination/infinite-pagination.component.spec.ts +++ b/lib/core/pagination/infinite-pagination.component.spec.ts @@ -25,6 +25,7 @@ import { setupTestBed } from '../testing/setupTestBed'; import { CoreTestingModule } from '../testing/core.testing.module'; import { Component } from '@angular/core'; import { PaginationModel } from '../models/pagination.model'; +import { RequestPaginationModel } from '../models/request-pagination.model'; @Component({ template: `` @@ -152,7 +153,7 @@ describe('InfinitePaginationComponent', () => { expect(loadingSpinner).toBeNull(); }); - it('should trigger the loadMore event with the proper pagination object', (done) => { + it('should trigger the loadMore event with skipcount 0 to reload all the elements', (done) => { pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true }; component.target.pagination.next(pagination); @@ -162,7 +163,25 @@ describe('InfinitePaginationComponent', () => { fixture.detectChanges(); component.loadMore.subscribe((newPagination: Pagination) => { - expect(newPagination.skipCount).toBe(5); + expect(newPagination.skipCount).toBe(0); + done(); + }); + + let loadMoreButton = fixture.debugElement.query(By.css('[data-automation-id="adf-infinite-pagination-button"]')); + loadMoreButton.triggerEventHandler('click', {}); + }); + + it('should trigger the loadMore event with merge false to reload all the elements', (done) => { + pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true }; + + component.target.pagination.next(pagination); + + component.isLoading = false; + component.pageSize = 5; + fixture.detectChanges(); + + component.loadMore.subscribe((newPagination: RequestPaginationModel) => { + expect(newPagination.merge).toBe(false); done(); }); @@ -197,10 +216,10 @@ describe('InfinitePaginationComponent', () => { component.onLoadMore(); expect(spyTarget).toHaveBeenCalledWith({ - skipCount: 25, + skipCount: 0, maxItems: 25, hasMoreItems: false, - merge: true + merge: false }); }); @@ -213,9 +232,9 @@ describe('InfinitePaginationComponent', () => { expect(spyTarget).toHaveBeenCalledWith({ maxItems: 7, - skipCount: 7, + skipCount: 0, hasMoreItems: false, - merge: true + merge: false }); }); diff --git a/lib/core/pagination/infinite-pagination.component.ts b/lib/core/pagination/infinite-pagination.component.ts index e4938e4308..86afc5c7c4 100644 --- a/lib/core/pagination/infinite-pagination.component.ts +++ b/lib/core/pagination/infinite-pagination.component.ts @@ -90,7 +90,12 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio onLoadMore() { this.requestPaginationModel.skipCount = 0; this.requestPaginationModel.merge = false; - this.requestPaginationModel.maxItems += this.pageSize; + + if (!this.requestPaginationModel.maxItems) { + this.requestPaginationModel.maxItems = this.pageSize; + } else { + this.requestPaginationModel.maxItems += this.pageSize; + } this.loadMore.next(this.requestPaginationModel);