[ADF-2391] skipCount is not reset on document-list when choosing a custom source from adf-sites-dropdown, nor the currentFolderId and folderNode (#3012)

* [ADF-2391] skipCount is not reset on document-list when choosing a custom source from adf-sites-dropdown, nor the currentFolderId and folderNode

fix and tests added

* [ADF-2391] refactor code & took into account merge parameter
This commit is contained in:
suzanadirla
2018-03-06 11:58:28 +02:00
committed by Eugenio Romano
parent f41498658b
commit 0a748ac555
2 changed files with 58 additions and 0 deletions

View File

@@ -1218,6 +1218,27 @@ describe('DocumentList', () => {
expect(documentList.folderNode).toBeNull(); expect(documentList.folderNode).toBeNull();
}); });
it('should reset folder node on loading folder by node id', () => {
documentList.folderNode = <any> {};
const sitesApi = apiService.getInstance().core.sitesApi;
spyOn(sitesApi, 'getSites').and.returnValue(Promise.resolve(null));
documentList.loadFolderByNodeId('-sites-');
expect(documentList.folderNode).toBeNull();
});
it('should have correct currentFolderId on loading folder by node id', () => {
documentList.currentFolderId = '12345-some-id-6789';
const peopleApi = apiService.getInstance().core.peopleApi;
spyOn(peopleApi, 'getSiteMembership').and.returnValue(Promise.resolve());
documentList.loadFolderByNodeId('-mysites-');
expect(documentList.currentFolderId).toBe('-mysites-');
});
it('should update pagination settings', () => { it('should update pagination settings', () => {
spyOn(documentList, 'reload').and.stub(); spyOn(documentList, 'reload').and.stub();
@@ -1304,4 +1325,21 @@ describe('DocumentList', () => {
expect(documentList.reload).toHaveBeenCalled(); expect(documentList.reload).toHaveBeenCalled();
}); });
it('should reset skipCount from pagination settings on loading folder by node id', () => {
spyOn(documentList, 'reload').and.stub();
const favoritesApi = apiService.getInstance().core.favoritesApi;
spyOn(favoritesApi, 'getFavorites').and.returnValue(Promise.resolve(null));
documentList.maxItems = 0;
documentList.skipCount = 0;
documentList.updatePagination({
maxItems: 10,
skipCount: 10
});
documentList.loadFolderByNodeId('-favorites-');
expect(documentList.skipCount).toBe(0, 'skipCount is reset');
});
}); });

View File

@@ -468,6 +468,14 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
this.folderChange.emit(new NodeEntryEvent(node.entry)); this.folderChange.emit(new NodeEntryEvent(node.entry));
} }
updateCustomSourceData(nodeId: string, merge: boolean): void {
this.folderNode = null;
this.currentFolderId = nodeId;
if (!merge) {
this.skipCount = 0;
}
}
/** /**
* Invoked when executing content action for a document or folder. * Invoked when executing content action for a document or folder.
* @param node Node to be the context of the execution. * @param node Node to be the context of the execution.
@@ -589,6 +597,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
} }
private loadTrashcan(merge: boolean = false): void { private loadTrashcan(merge: boolean = false): void {
this.updateCustomSourceData('-trashcan-', merge);
const options = { const options = {
include: ['path', 'properties'], include: ['path', 'properties'],
maxItems: this.maxItems, maxItems: this.maxItems,
@@ -600,6 +610,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
} }
private loadSharedLinks(merge: boolean = false): void { private loadSharedLinks(merge: boolean = false): void {
this.updateCustomSourceData('-sharedlinks-', merge);
const options = { const options = {
include: ['properties', 'allowableOperations', 'path'], include: ['properties', 'allowableOperations', 'path'],
maxItems: this.maxItems, maxItems: this.maxItems,
@@ -611,6 +623,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
} }
private loadSites(merge: boolean = false): void { private loadSites(merge: boolean = false): void {
this.updateCustomSourceData('-sites-', merge);
const options = { const options = {
include: ['properties'], include: ['properties'],
maxItems: this.maxItems, maxItems: this.maxItems,
@@ -631,6 +645,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
} }
private loadMemberSites(merge: boolean = false): void { private loadMemberSites(merge: boolean = false): void {
this.updateCustomSourceData('-mysites-', merge);
const options = { const options = {
include: ['properties'], include: ['properties'],
maxItems: this.maxItems, maxItems: this.maxItems,
@@ -659,6 +675,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
} }
private loadFavorites(merge: boolean = false): void { private loadFavorites(merge: boolean = false): void {
this.updateCustomSourceData('-favorites-', merge);
const options = { const options = {
maxItems: this.maxItems, maxItems: this.maxItems,
skipCount: this.skipCount, skipCount: this.skipCount,
@@ -690,6 +708,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
} }
private loadRecent(merge: boolean = false): void { private loadRecent(merge: boolean = false): void {
this.updateCustomSourceData('-recent-', merge);
this.getRecentFiles('-me-') this.getRecentFiles('-me-')
.then((page: NodePaging) => this.onPageLoaded(page, merge)) .then((page: NodePaging) => this.onPageLoaded(page, merge))
.catch(error => this.error.emit(error)); .catch(error => this.error.emit(error));