[ADF-2175] Document List requests are executed twice when opening the copy and move dialog (#2960)

* [ADF-2175] Document List requests are executed twice when opening the dialog

fixed bug

* [ADF-2175] added unit tests for the change & refactored initial code
This commit is contained in:
suzanadirla 2018-02-20 15:59:12 +02:00 committed by Eugenio Romano
parent adb0b8df38
commit d731cc651c
2 changed files with 20 additions and 0 deletions

View File

@ -1204,4 +1204,22 @@ describe('DocumentList', () => {
expect(documentList.reload).not.toHaveBeenCalled();
});
it('should NOT reload data on first call of onNgChanges', () => {
spyOn(documentList, 'reload').and.stub();
const firstChange = true;
documentList.ngOnChanges({ skipCount: new SimpleChange(undefined, 10, firstChange) });
expect(documentList.reload).not.toHaveBeenCalled();
});
it('should reload data on NON-first calls of onNgChanges', () => {
spyOn(documentList, 'reload').and.stub();
const firstChange = true;
documentList.ngOnChanges({ skipCount: new SimpleChange(undefined, 10, !firstChange) });
expect(documentList.reload).toHaveBeenCalled();
});
});

View File

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