diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts index 5bf973b9f8..194a646677 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts @@ -916,6 +916,17 @@ describe('DocumentList', () => { expect(apiService.nodesApi.getDeletedNodes).toHaveBeenCalled(); }); + it('should emit error when fetch trashcan fails', (done) => { + spyOn(apiService.nodesApi, 'getDeletedNodes').and.returnValue(Promise.reject('error')); + + documentList.error.subscribe(val => { + expect(val).toBe('error'); + done(); + }); + + documentList.loadFolderByNodeId('-trashcan-'); + }); + it('should fetch shared links', () => { const sharedlinksApi = apiService.getInstance().core.sharedlinksApi; spyOn(sharedlinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(null)); @@ -924,6 +935,18 @@ describe('DocumentList', () => { expect(sharedlinksApi.findSharedLinks).toHaveBeenCalled(); }); + it('should emit error when fetch shared links fails', (done) => { + spyOn(apiService.getInstance().core.sharedlinksApi, 'findSharedLinks') + .and.returnValue(Promise.reject('error')); + + documentList.error.subscribe(val => { + expect(val).toBe('error'); + done(); + }); + + documentList.loadFolderByNodeId('-sharedlinks-'); + }); + it('should fetch sites', () => { const sitesApi = apiService.getInstance().core.sitesApi; spyOn(sitesApi, 'getSites').and.returnValue(Promise.resolve(null)); @@ -932,6 +955,18 @@ describe('DocumentList', () => { expect(sitesApi.getSites).toHaveBeenCalled(); }); + it('should emit error when fetch sites fails', (done) => { + spyOn(apiService.getInstance().core.sitesApi, 'getSites') + .and.returnValue(Promise.reject('error')); + + documentList.error.subscribe(val => { + expect(val).toBe('error'); + done(); + }); + + documentList.loadFolderByNodeId('-sites-'); + }); + it('should fetch user membership sites', () => { const peopleApi = apiService.getInstance().core.peopleApi; spyOn(peopleApi, 'getSiteMembership').and.returnValue(Promise.resolve()); @@ -940,6 +975,18 @@ describe('DocumentList', () => { expect(peopleApi.getSiteMembership).toHaveBeenCalled(); }); + it('should emit error when fetch membership sites fails', (done) => { + spyOn(apiService.getInstance().core.peopleApi, 'getSiteMembership') + .and.returnValue(Promise.reject('error')); + + documentList.error.subscribe(val => { + expect(val).toBe('error'); + done(); + }); + + documentList.loadFolderByNodeId('-mysites-'); + }); + it('should fetch favorites', () => { const favoritesApi = apiService.getInstance().core.favoritesApi; spyOn(favoritesApi, 'getFavorites').and.returnValue(Promise.resolve(null)); @@ -948,6 +995,18 @@ describe('DocumentList', () => { expect(favoritesApi.getFavorites).toHaveBeenCalled(); }); + it('should emit error when fetch favorites fails', (done) => { + spyOn(apiService.getInstance().core.favoritesApi, 'getFavorites') + .and.returnValue(Promise.reject('error')); + + documentList.error.subscribe(val => { + expect(val).toBe('error'); + done(); + }); + + documentList.loadFolderByNodeId('-favorites-'); + }); + it('should fetch recent', (done) => { const person = { entry: { id: 'person '} }; @@ -963,6 +1022,30 @@ describe('DocumentList', () => { }, 100); }); + it('should emit error when fetch recent fails on getPerson call', (done) => { + spyOn(apiService.peopleApi, 'getPerson').and.returnValue(Promise.reject('error')); + + documentList.error.subscribe(val => { + expect(val).toBe('error'); + done(); + }); + + documentList.loadFolderByNodeId('-recent-'); + }); + + it('should emit error when fetch recent fails on search call', (done) => { + const person = { entry: { id: 'person '} }; + spyOn(apiService.peopleApi, 'getPerson').and.returnValue(Promise.resolve(person)); + spyOn(apiService.searchApi, 'search').and.returnValue(Promise.reject('error')); + + documentList.error.subscribe(val => { + expect(val).toBe('error'); + done(); + }); + + documentList.loadFolderByNodeId('-recent-'); + }); + it('should switch to another page', () => { spyOn(documentList, 'reload').and.stub(); diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts index d0864d3276..5b34a7c32c 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts @@ -499,9 +499,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni maxItems: this.pageSize, skipCount: this.skipCount }; - this.apiService.nodesApi.getDeletedNodes(options).then((page: DeletedNodesPaging) => { - this.onPageLoaded(page); - }); + this.apiService.nodesApi.getDeletedNodes(options) + .then((page: DeletedNodesPaging) => this.onPageLoaded(page)) + .catch(error => this.error.emit(error)); } private loadSharedLinks(): void { @@ -510,9 +510,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni maxItems: this.pageSize, skipCount: this.skipCount }; - this.apiService.sharedLinksApi.findSharedLinks(options).then((page: NodePaging) => { - this.onPageLoaded(page); - }); + this.apiService.sharedLinksApi.findSharedLinks(options) + .then((page: NodePaging) => this.onPageLoaded(page)) + .catch(error => this.error.emit(error)); } private loadSites(): void { @@ -522,9 +522,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni skipCount: this.skipCount }; - this.apiService.sitesApi.getSites(options).then((page: NodePaging) => { - this.onPageLoaded(page); - }); + this.apiService.sitesApi.getSites(options) + .then((page: NodePaging) => this.onPageLoaded(page)) + .catch(error => this.error.emit(error)); } private loadMemberSites(): void { @@ -534,19 +534,21 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni skipCount: this.skipCount }; - this.apiService.peopleApi.getSiteMembership('-me-', options).then((result: SitePaging) => { - let page: NodePaging = { - list: { - entries: result.list.entries - .map(({ entry: { site }}: any) => ({ - entry: site - })), - pagination: result.list.pagination - } - }; + this.apiService.peopleApi.getSiteMembership('-me-', options) + .then((result: SitePaging) => { + let page: NodePaging = { + list: { + entries: result.list.entries + .map(({ entry: { site }}: any) => ({ + entry: site + })), + pagination: result.list.pagination + } + }; - this.onPageLoaded(page); - }); + this.onPageLoaded(page); + }) + .catch(error => this.error.emit(error)); } private loadFavorites(): void { @@ -557,54 +559,59 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni include: [ 'properties', 'allowableOperations', 'path' ] }; - this.apiService.favoritesApi.getFavorites('-me-', options).then((result: NodePaging) => { - let page: NodePaging = { - list: { - entries: result.list.entries - .map(({ entry: { target }}: any) => ({ - entry: target.file || target.folder - })) - .map(({ entry }: any) => { - entry.properties = { - 'cm:title': entry.title, - 'cm:description': entry.description - }; - return { entry }; - }), - pagination: result.list.pagination - } - }; - this.onPageLoaded(page); - }); + this.apiService.favoritesApi.getFavorites('-me-', options) + .then((result: NodePaging) => { + let page: NodePaging = { + list: { + entries: result.list.entries + .map(({ entry: { target }}: any) => ({ + entry: target.file || target.folder + })) + .map(({ entry }: any) => { + entry.properties = { + 'cm:title': entry.title, + 'cm:description': entry.description + }; + return { entry }; + }), + pagination: result.list.pagination + } + }; + this.onPageLoaded(page); + }) + .catch(error => this.error.emit(error)); } private loadRecent(): void { - this.apiService.peopleApi.getPerson('-me-').then((person: PersonEntry) => { - const username = person.entry.id; - const query = { - query: { - query: '*', - language: 'afts' - }, - filterQueries: [ - { query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` }, - { query: `cm:modifier:${username} OR cm:creator:${username}` }, - { query: `TYPE:"content" AND -TYPE:"app:filelink" AND -TYPE:"fm:post"` } - ], - include: [ 'path', 'properties', 'allowableOperations' ], - sort: [{ - type: 'FIELD', - field: 'cm:modified', - ascending: false - }], - paging: { - maxItems: this.pageSize, - skipCount: this.skipCount - } - }; + this.apiService.peopleApi.getPerson('-me-') + .then((person: PersonEntry) => { + const username = person.entry.id; + const query = { + query: { + query: '*', + language: 'afts' + }, + filterQueries: [ + { query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` }, + { query: `cm:modifier:${username} OR cm:creator:${username}` }, + { query: `TYPE:"content" AND -TYPE:"app:filelink" AND -TYPE:"fm:post"` } + ], + include: [ 'path', 'properties', 'allowableOperations' ], + sort: [{ + type: 'FIELD', + field: 'cm:modified', + ascending: false + }], + paging: { + maxItems: this.pageSize, + skipCount: this.skipCount + } + }; - this.apiService.searchApi.search(query).then(page => this.onPageLoaded(page)); - }); + return this.apiService.searchApi.search(query); + }) + .then((page: NodePaging) => this.onPageLoaded(page)) + .catch(error => this.error.emit(error)); } private onPageLoaded(page: NodePaging) {