emit errors (#2593)

This commit is contained in:
Cilibiu Bogdan
2017-11-02 12:32:54 +02:00
committed by Eugenio Romano
parent 1a01b67e7c
commit 75b0267f0b
2 changed files with 155 additions and 65 deletions

View File

@@ -916,6 +916,17 @@ describe('DocumentList', () => {
expect(apiService.nodesApi.getDeletedNodes).toHaveBeenCalled(); 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', () => { it('should fetch shared links', () => {
const sharedlinksApi = apiService.getInstance().core.sharedlinksApi; const sharedlinksApi = apiService.getInstance().core.sharedlinksApi;
spyOn(sharedlinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(null)); spyOn(sharedlinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(null));
@@ -924,6 +935,18 @@ describe('DocumentList', () => {
expect(sharedlinksApi.findSharedLinks).toHaveBeenCalled(); 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', () => { it('should fetch sites', () => {
const sitesApi = apiService.getInstance().core.sitesApi; const sitesApi = apiService.getInstance().core.sitesApi;
spyOn(sitesApi, 'getSites').and.returnValue(Promise.resolve(null)); spyOn(sitesApi, 'getSites').and.returnValue(Promise.resolve(null));
@@ -932,6 +955,18 @@ describe('DocumentList', () => {
expect(sitesApi.getSites).toHaveBeenCalled(); 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', () => { it('should fetch user membership sites', () => {
const peopleApi = apiService.getInstance().core.peopleApi; const peopleApi = apiService.getInstance().core.peopleApi;
spyOn(peopleApi, 'getSiteMembership').and.returnValue(Promise.resolve()); spyOn(peopleApi, 'getSiteMembership').and.returnValue(Promise.resolve());
@@ -940,6 +975,18 @@ describe('DocumentList', () => {
expect(peopleApi.getSiteMembership).toHaveBeenCalled(); 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', () => { it('should fetch favorites', () => {
const favoritesApi = apiService.getInstance().core.favoritesApi; const favoritesApi = apiService.getInstance().core.favoritesApi;
spyOn(favoritesApi, 'getFavorites').and.returnValue(Promise.resolve(null)); spyOn(favoritesApi, 'getFavorites').and.returnValue(Promise.resolve(null));
@@ -948,6 +995,18 @@ describe('DocumentList', () => {
expect(favoritesApi.getFavorites).toHaveBeenCalled(); 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) => { it('should fetch recent', (done) => {
const person = { entry: { id: 'person '} }; const person = { entry: { id: 'person '} };
@@ -963,6 +1022,30 @@ describe('DocumentList', () => {
}, 100); }, 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', () => { it('should switch to another page', () => {
spyOn(documentList, 'reload').and.stub(); spyOn(documentList, 'reload').and.stub();

View File

@@ -499,9 +499,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
maxItems: this.pageSize, maxItems: this.pageSize,
skipCount: this.skipCount skipCount: this.skipCount
}; };
this.apiService.nodesApi.getDeletedNodes(options).then((page: DeletedNodesPaging) => { this.apiService.nodesApi.getDeletedNodes(options)
this.onPageLoaded(page); .then((page: DeletedNodesPaging) => this.onPageLoaded(page))
}); .catch(error => this.error.emit(error));
} }
private loadSharedLinks(): void { private loadSharedLinks(): void {
@@ -510,9 +510,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
maxItems: this.pageSize, maxItems: this.pageSize,
skipCount: this.skipCount skipCount: this.skipCount
}; };
this.apiService.sharedLinksApi.findSharedLinks(options).then((page: NodePaging) => { this.apiService.sharedLinksApi.findSharedLinks(options)
this.onPageLoaded(page); .then((page: NodePaging) => this.onPageLoaded(page))
}); .catch(error => this.error.emit(error));
} }
private loadSites(): void { private loadSites(): void {
@@ -522,9 +522,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
skipCount: this.skipCount skipCount: this.skipCount
}; };
this.apiService.sitesApi.getSites(options).then((page: NodePaging) => { this.apiService.sitesApi.getSites(options)
this.onPageLoaded(page); .then((page: NodePaging) => this.onPageLoaded(page))
}); .catch(error => this.error.emit(error));
} }
private loadMemberSites(): void { private loadMemberSites(): void {
@@ -534,19 +534,21 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
skipCount: this.skipCount skipCount: this.skipCount
}; };
this.apiService.peopleApi.getSiteMembership('-me-', options).then((result: SitePaging) => { this.apiService.peopleApi.getSiteMembership('-me-', options)
let page: NodePaging = { .then((result: SitePaging) => {
list: { let page: NodePaging = {
entries: result.list.entries list: {
.map(({ entry: { site }}: any) => ({ entries: result.list.entries
entry: site .map(({ entry: { site }}: any) => ({
})), entry: site
pagination: result.list.pagination })),
} pagination: result.list.pagination
}; }
};
this.onPageLoaded(page); this.onPageLoaded(page);
}); })
.catch(error => this.error.emit(error));
} }
private loadFavorites(): void { private loadFavorites(): void {
@@ -557,54 +559,59 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
include: [ 'properties', 'allowableOperations', 'path' ] include: [ 'properties', 'allowableOperations', 'path' ]
}; };
this.apiService.favoritesApi.getFavorites('-me-', options).then((result: NodePaging) => { this.apiService.favoritesApi.getFavorites('-me-', options)
let page: NodePaging = { .then((result: NodePaging) => {
list: { let page: NodePaging = {
entries: result.list.entries list: {
.map(({ entry: { target }}: any) => ({ entries: result.list.entries
entry: target.file || target.folder .map(({ entry: { target }}: any) => ({
})) entry: target.file || target.folder
.map(({ entry }: any) => { }))
entry.properties = { .map(({ entry }: any) => {
'cm:title': entry.title, entry.properties = {
'cm:description': entry.description 'cm:title': entry.title,
}; 'cm:description': entry.description
return { entry }; };
}), return { entry };
pagination: result.list.pagination }),
} pagination: result.list.pagination
}; }
this.onPageLoaded(page); };
}); this.onPageLoaded(page);
})
.catch(error => this.error.emit(error));
} }
private loadRecent(): void { private loadRecent(): void {
this.apiService.peopleApi.getPerson('-me-').then((person: PersonEntry) => { this.apiService.peopleApi.getPerson('-me-')
const username = person.entry.id; .then((person: PersonEntry) => {
const query = { const username = person.entry.id;
query: { const query = {
query: '*', query: {
language: 'afts' query: '*',
}, language: 'afts'
filterQueries: [ },
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` }, filterQueries: [
{ query: `cm:modifier:${username} OR cm:creator:${username}` }, { query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
{ query: `TYPE:"content" AND -TYPE:"app:filelink" AND -TYPE:"fm:post"` } { query: `cm:modifier:${username} OR cm:creator:${username}` },
], { query: `TYPE:"content" AND -TYPE:"app:filelink" AND -TYPE:"fm:post"` }
include: [ 'path', 'properties', 'allowableOperations' ], ],
sort: [{ include: [ 'path', 'properties', 'allowableOperations' ],
type: 'FIELD', sort: [{
field: 'cm:modified', type: 'FIELD',
ascending: false field: 'cm:modified',
}], ascending: false
paging: { }],
maxItems: this.pageSize, paging: {
skipCount: this.skipCount 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) { private onPageLoaded(page: NodePaging) {