mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
fix infinite pagination test (#4279)
This commit is contained in:
@@ -941,7 +941,10 @@ describe('DocumentList', () => {
|
|||||||
it('should load folder by ID on init', () => {
|
it('should load folder by ID on init', () => {
|
||||||
spyOn(documentList, 'loadFolder').and.returnValue(Promise.resolve());
|
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();
|
expect(documentList.loadFolder).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1261,12 +1264,12 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should add includeFields in the server request when present', () => {
|
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();
|
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, {
|
expect(documentListService.getFolder).toHaveBeenCalledWith(null, {
|
||||||
where: undefined,
|
where: undefined,
|
||||||
@@ -1277,13 +1280,13 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should add where in the server request when present', () => {
|
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();
|
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, {
|
expect(documentListService.getFolder).toHaveBeenCalledWith(null, {
|
||||||
where: '(isFolder=true)',
|
where: '(isFolder=true)',
|
||||||
|
@@ -25,6 +25,7 @@ import { setupTestBed } from '../testing/setupTestBed';
|
|||||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { PaginationModel } from '../models/pagination.model';
|
import { PaginationModel } from '../models/pagination.model';
|
||||||
|
import { RequestPaginationModel } from '../models/request-pagination.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: ``
|
template: ``
|
||||||
@@ -152,7 +153,7 @@ describe('InfinitePaginationComponent', () => {
|
|||||||
expect(loadingSpinner).toBeNull();
|
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 };
|
pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true };
|
||||||
|
|
||||||
component.target.pagination.next(pagination);
|
component.target.pagination.next(pagination);
|
||||||
@@ -162,7 +163,25 @@ describe('InfinitePaginationComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.loadMore.subscribe((newPagination: Pagination) => {
|
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();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -197,10 +216,10 @@ describe('InfinitePaginationComponent', () => {
|
|||||||
component.onLoadMore();
|
component.onLoadMore();
|
||||||
|
|
||||||
expect(spyTarget).toHaveBeenCalledWith({
|
expect(spyTarget).toHaveBeenCalledWith({
|
||||||
skipCount: 25,
|
skipCount: 0,
|
||||||
maxItems: 25,
|
maxItems: 25,
|
||||||
hasMoreItems: false,
|
hasMoreItems: false,
|
||||||
merge: true
|
merge: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -213,9 +232,9 @@ describe('InfinitePaginationComponent', () => {
|
|||||||
|
|
||||||
expect(spyTarget).toHaveBeenCalledWith({
|
expect(spyTarget).toHaveBeenCalledWith({
|
||||||
maxItems: 7,
|
maxItems: 7,
|
||||||
skipCount: 7,
|
skipCount: 0,
|
||||||
hasMoreItems: false,
|
hasMoreItems: false,
|
||||||
merge: true
|
merge: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -90,7 +90,12 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
|
|||||||
onLoadMore() {
|
onLoadMore() {
|
||||||
this.requestPaginationModel.skipCount = 0;
|
this.requestPaginationModel.skipCount = 0;
|
||||||
this.requestPaginationModel.merge = false;
|
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);
|
this.loadMore.next(this.requestPaginationModel);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user