Process list implement pagination interface (#2872)

This commit is contained in:
Maurizio Vitale
2018-02-03 18:22:05 +00:00
committed by Eugenio Romano
parent 105bc80d2c
commit 0f6ac42e4c
17 changed files with 311 additions and 141 deletions

View File

@@ -169,35 +169,43 @@ describe('PaginationComponent', () => {
});
it('goes next', () => {
expect(component.current).toBe(3);
component.goNext();
const { skipCount } = nextPageSpy.calls.mostRecent().args[0];
expect(skipCount).toBe(75);
expect(component.current).toBe(4);
});
it('goes previous', () => {
expect(component.current).toBe(3);
component.goPrevious();
const { skipCount } = prevPageSpy.calls.mostRecent().args[0];
expect(skipCount).toBe(25);
expect(component.current).toBe(2);
});
it('changes page size', () => {
expect(component.current).toBe(3);
component.onChangePageSize(50);
const { maxItems } = changePageSizeSpy.calls.mostRecent().args[0];
expect(maxItems).toBe(50);
expect(component.current).toBe(1);
});
it('changes page number', () => {
expect(component.current).toBe(3);
component.onChangePageNumber(5);
const { skipCount } = changePageNumberSpy.calls.mostRecent().args[0];
expect(skipCount).toBe(100);
expect(component.current).toBe(5);
});
});
@@ -318,10 +326,12 @@ describe('PaginationComponent', () => {
component.target = customComponent;
component.ngOnInit();
customComponent.pagination.next(new FakePaginationInput(2, 0, 25));
customComponent.pagination.next(new FakePaginationInput(2, 1, 25));
expect(component.current).toBe(1);
component.goNext();
expect(customComponent.updatePagination).toHaveBeenCalled();
expect(component.current).toBe(2);
});
});

View File

@@ -168,6 +168,7 @@ export class PaginationComponent implements OnInit, OnDestroy {
if (this.hasItems) {
const maxItems = this.pagination.maxItems;
const skipCount = (this.next - 1) * maxItems;
this.pagination.skipCount = skipCount;
this.handlePaginationEvent(PaginationComponent.ACTIONS.NEXT_PAGE, {
skipCount,
@@ -180,6 +181,7 @@ export class PaginationComponent implements OnInit, OnDestroy {
if (this.hasItems) {
const maxItems = this.pagination.maxItems;
const skipCount = (this.previous - 1) * maxItems;
this.pagination.skipCount = skipCount;
this.handlePaginationEvent(PaginationComponent.ACTIONS.PREV_PAGE, {
skipCount,
@@ -192,6 +194,7 @@ export class PaginationComponent implements OnInit, OnDestroy {
if (this.hasItems) {
const maxItems = this.pagination.maxItems;
const skipCount = (pageNumber - 1) * maxItems;
this.pagination.skipCount = skipCount;
this.handlePaginationEvent(PaginationComponent.ACTIONS.CHANGE_PAGE_NUMBER, {
skipCount,
@@ -201,6 +204,8 @@ export class PaginationComponent implements OnInit, OnDestroy {
}
onChangePageSize(maxItems: number) {
this.pagination.skipCount = 0;
this.pagination.maxItems = maxItems;
this.handlePaginationEvent(PaginationComponent.ACTIONS.CHANGE_PAGE_SIZE, {
skipCount: 0,
maxItems