[ADF-2406] [Document Picker] Unnecessary extra request is made on Load more click (#3019)

* [ADF-2406] [Document Picker] Unnecessary extra request is made on Load more click

fixed bug

* [ADF-2406] refactored code

* [ADF-2406] added tests
This commit is contained in:
suzanadirla 2018-03-06 11:19:06 +02:00 committed by Denys Vuika
parent ac994ed7af
commit c1f0537a0d
2 changed files with 27 additions and 2 deletions

View File

@ -1278,4 +1278,30 @@ describe('DocumentList', () => {
expect(documentList.reload).toHaveBeenCalled(); expect(documentList.reload).toHaveBeenCalled();
}); });
it('should NOT reload data on onNgChanges upon reset of skipCount to 0', () => {
spyOn(documentList, 'reload').and.stub();
documentList.maxItems = 10;
documentList.skipCount = 10;
const firstChange = true;
documentList.ngOnChanges({ skipCount: new SimpleChange(undefined, 0, !firstChange) });
expect(documentList.reload).not.toHaveBeenCalled();
});
it('should reload data upon changing pagination setting skipCount to 0', () => {
spyOn(documentList, 'reload').and.stub();
documentList.maxItems = 5;
documentList.skipCount = 5;
documentList.updatePagination({
maxItems: 5,
skipCount: 0
});
expect(documentList.reload).toHaveBeenCalled();
});
}); });

View File

@ -577,8 +577,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
private isSkipCountChanged(changePage: SimpleChanges) { private isSkipCountChanged(changePage: SimpleChanges) {
return changePage.skipCount && return changePage.skipCount &&
!changePage.skipCount.isFirstChange() && !changePage.skipCount.isFirstChange() &&
changePage.skipCount.currentValue !== null && changePage.skipCount.currentValue &&
changePage.skipCount.currentValue !== undefined &&
changePage.skipCount.currentValue !== changePage.skipCount.previousValue; changePage.skipCount.currentValue !== changePage.skipCount.previousValue;
} }