ensure parameter node id is a folder instance (#166)

This commit is contained in:
Cilibiu Bogdan
2017-12-18 16:19:31 +02:00
committed by Denys Vuika
parent 92c147fae3
commit 9428913900
2 changed files with 19 additions and 2 deletions

View File

@@ -77,7 +77,7 @@ describe('FilesComponent', () => {
})); }));
beforeEach(() => { beforeEach(() => {
node = { id: 'node-id' }; node = { id: 'node-id', isFolder: true };
page = { page = {
list: { list: {
entries: ['a', 'b', 'c'], entries: ['a', 'b', 'c'],
@@ -134,6 +134,17 @@ describe('FilesComponent', () => {
expect(component.onFetchError).toHaveBeenCalled(); expect(component.onFetchError).toHaveBeenCalled();
}); });
it('if should navigate to parent if node is not a folder', () => {
node.isFolder = false;
node.parentId = 'parent-id';
spyOn(component, 'fetchNode').and.returnValue(Observable.of(node));
spyOn(router, 'navigate');
fixture.detectChanges();
expect(router.navigate).toHaveBeenCalledWith([ '/personal-files', 'parent-id' ]);
});
}); });
describe('refresh on events', () => { describe('refresh on events', () => {

View File

@@ -76,7 +76,13 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
this.isLoading = true; this.isLoading = true;
this.fetchNode(nodeId) this.fetchNode(nodeId)
.do((node) => this.updateCurrentNode(node)) .do((node) => {
if (node.isFolder) {
this.updateCurrentNode(node);
} else {
this.router.navigate(['/personal-files', node.parentId]);
}
})
.flatMap((node) => this.fetchNodes(node.id)) .flatMap((node) => this.fetchNodes(node.id))
.subscribe( .subscribe(
(page) => { (page) => {