fix infinite pagination test (#4279)

This commit is contained in:
Eugenio Romano
2019-02-06 23:45:26 +00:00
committed by GitHub
parent 836caf5253
commit 3fd6b5d230
3 changed files with 44 additions and 17 deletions

View File

@@ -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)',

View File

@@ -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
});
});

View File

@@ -90,7 +90,12 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
onLoadMore() {
this.requestPaginationModel.skipCount = 0;
this.requestPaginationModel.merge = false;
if (!this.requestPaginationModel.maxItems) {
this.requestPaginationModel.maxItems = this.pageSize;
} else {
this.requestPaginationModel.maxItems += this.pageSize;
}
this.loadMore.next(this.requestPaginationModel);