mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
- expose ‘error’ event - change path only on successful navigation - extend demo shell with error handling and reporting - additional unit tests for document-list
This commit is contained in:
committed by
Eugenio Romano
parent
da70a72bba
commit
7eab89c5ef
@@ -85,15 +85,18 @@ describe('DocumentListBreadcrumb', () => {
|
||||
component.onRoutePathClick(node, null);
|
||||
});
|
||||
|
||||
it('should update document list on click', () => {
|
||||
it('should update document list on click', (done) => {
|
||||
let documentList = new DocumentList(null, null, null);
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
spyOn(documentList, 'displayFolderContent').and.returnValue(Promise.resolve());
|
||||
|
||||
let node = <PathNode> { name: 'name', path: '/path' };
|
||||
component.target = documentList;
|
||||
|
||||
component.onRoutePathClick(node, null);
|
||||
expect(documentList.currentFolderPath).toBe(node.path);
|
||||
setTimeout(() => {
|
||||
expect(documentList.currentFolderPath).toBe(node.path);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should do nothing for same path', () => {
|
||||
|
@@ -15,13 +15,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NgZone } from '@angular/core';
|
||||
import { DataColumn } from 'ng2-alfresco-datatable';
|
||||
import { NgZone, TemplateRef } from '@angular/core';
|
||||
import { DataTableComponent, DataColumn, DataRowEvent } from 'ng2-alfresco-datatable';
|
||||
import { DocumentList } from './document-list';
|
||||
import { DocumentListServiceMock } from './../assets/document-list.service.mock';
|
||||
import { ContentActionModel } from '../models/content-action.model';
|
||||
import { FileNode, FolderNode } from '../assets/document-library.model.mock';
|
||||
import { NodeMinimalEntry } from '../models/document-library.model';
|
||||
import { ShareDataRow, RowFilter, ImageResolver } from './../data/share-datatable-adapter';
|
||||
|
||||
describe('DocumentList', () => {
|
||||
|
||||
@@ -204,23 +205,14 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should display folder content for new folder path', () => {
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
spyOn(documentList, 'displayFolderContent').and.returnValue(Promise.resolve());
|
||||
let newPath = '/some/new/path';
|
||||
documentList.currentFolderPath = newPath;
|
||||
expect(documentList.displayFolderContent).toHaveBeenCalledWith(newPath);
|
||||
});
|
||||
|
||||
it('should not display folder content for same path', () => {
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
documentList.currentFolderPath = '/test';
|
||||
expect(documentList.displayFolderContent).toHaveBeenCalledTimes(1);
|
||||
|
||||
documentList.currentFolderPath = '/test';
|
||||
expect(documentList.displayFolderContent).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should reset to default path', () => {
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
spyOn(documentList, 'displayFolderContent').and.returnValue(Promise.resolve());
|
||||
documentList.currentFolderPath = null;
|
||||
|
||||
expect(documentList.currentFolderPath).toBe(documentList.DEFAULT_ROOT_FOLDER);
|
||||
@@ -228,7 +220,7 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should emit folder changed event', (done) => {
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
spyOn(documentList, 'displayFolderContent').and.returnValue(Promise.resolve());
|
||||
documentList.folderChange.subscribe(e => {
|
||||
done();
|
||||
});
|
||||
@@ -237,7 +229,7 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should emit folder changed event with folder details', (done) => {
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
spyOn(documentList, 'displayFolderContent').and.returnValue(Promise.resolve());
|
||||
|
||||
let path = '/path';
|
||||
|
||||
@@ -249,20 +241,6 @@ describe('DocumentList', () => {
|
||||
documentList.currentFolderPath = path;
|
||||
});
|
||||
|
||||
it('should emit folder changed event only once', () => {
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
let path = '/new/path';
|
||||
let calls = 0;
|
||||
documentList.folderChange.subscribe(e => {
|
||||
calls++;
|
||||
});
|
||||
|
||||
documentList.currentFolderPath = path;
|
||||
documentList.currentFolderPath = path;
|
||||
documentList.currentFolderPath = path;
|
||||
expect(calls).toBe(1);
|
||||
});
|
||||
|
||||
it('should execute context action on callback', () => {
|
||||
let action = {
|
||||
node: {},
|
||||
@@ -500,4 +478,87 @@ describe('DocumentList', () => {
|
||||
expect(documentList.isMobile).toHaveBeenCalled();
|
||||
expect(documentList.navigationMode).toBe(DocumentList.SINGLE_CLICK_NAVIGATION);
|
||||
});
|
||||
|
||||
it('should emit error on wrong path', (done) => {
|
||||
let raised = false;
|
||||
documentList.error.subscribe(err => raised = true);
|
||||
spyOn(documentList, 'displayFolderContent').and.returnValue(Promise.reject(false));
|
||||
|
||||
documentList.currentFolderPath = 'wrong-path';
|
||||
setTimeout(() => {
|
||||
expect(raised).toBeTruthy();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should require dataTable to check empty template', () => {
|
||||
documentList.dataTable = null;
|
||||
expect(documentList.isEmptyTemplateDefined()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should check [empty folder] template ', () => {
|
||||
documentList.emptyFolderTemplate = <TemplateRef<any>> {};
|
||||
documentList.dataTable = new DataTableComponent();
|
||||
expect(documentList.dataTable).toBeDefined();
|
||||
expect(documentList.isEmptyTemplateDefined()).toBeTruthy();
|
||||
|
||||
documentList.emptyFolderTemplate = null;
|
||||
expect(documentList.isEmptyTemplateDefined()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should set root path for underlying adapter', () => {
|
||||
documentList.rootPath = 'test';
|
||||
expect(documentList.data.rootPath).toBe('test');
|
||||
});
|
||||
|
||||
it('should set default root path for underlying adapter', () => {
|
||||
documentList.rootPath = null;
|
||||
expect(documentList.data.rootPath).toBe(documentList.data.DEFAULT_ROOT_PATH);
|
||||
});
|
||||
|
||||
it('should fetch root path from underlying adapter', () => {
|
||||
documentList.data.rootPath = 'test';
|
||||
expect(documentList.rootPath).toBe('test');
|
||||
});
|
||||
|
||||
it('should not fetch root path when adapter missing', () => {
|
||||
documentList.data = null;
|
||||
expect(documentList.rootPath).toBeNull();
|
||||
});
|
||||
|
||||
it('should set row filter for underlying adapter', () => {
|
||||
let filter = <RowFilter> {};
|
||||
spyOn(documentList.data, 'setFilter').and.callThrough();
|
||||
|
||||
documentList.rowFilter = filter;
|
||||
expect(documentList.data.setFilter).toHaveBeenCalledWith(filter);
|
||||
});
|
||||
|
||||
it('should set image resolver for underlying adapter', () => {
|
||||
let resolver = <ImageResolver> {};
|
||||
spyOn(documentList.data, 'setImageResolver').and.callThrough();
|
||||
|
||||
documentList.imageResolver = resolver;
|
||||
expect(documentList.data.setImageResolver).toHaveBeenCalledWith(resolver);
|
||||
});
|
||||
|
||||
it('should emit [nodeClick] event on row click', () => {
|
||||
let node = new NodeMinimalEntry();
|
||||
let row = new ShareDataRow(node);
|
||||
let event = <DataRowEvent> { value: row };
|
||||
|
||||
spyOn(documentList, 'onNodeClick').and.callThrough();
|
||||
documentList.onRowClick(event);
|
||||
expect(documentList.onNodeClick).toHaveBeenCalledWith(node);
|
||||
});
|
||||
|
||||
it('should emit [nodeDblClick] event on row double-click', () => {
|
||||
let node = new NodeMinimalEntry();
|
||||
let row = new ShareDataRow(node);
|
||||
let event = <DataRowEvent> { value: row };
|
||||
|
||||
spyOn(documentList, 'onNodeDblClick').and.callThrough();
|
||||
documentList.onRowDblClick(event);
|
||||
expect(documentList.onNodeDblClick).toHaveBeenCalledWith(node);
|
||||
});
|
||||
});
|
||||
|
@@ -118,6 +118,9 @@ export class DocumentList implements OnInit, AfterContentInit {
|
||||
@Output()
|
||||
preview: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
@ViewChild(DataTableComponent)
|
||||
dataTable: DataTableComponent;
|
||||
|
||||
@@ -130,11 +133,15 @@ export class DocumentList implements OnInit, AfterContentInit {
|
||||
@Input()
|
||||
set currentFolderPath(value: string) {
|
||||
if (value !== this._path) {
|
||||
this._path = value || this.DEFAULT_ROOT_FOLDER;
|
||||
this.displayFolderContent(this._path);
|
||||
this.folderChange.emit({
|
||||
path: this.currentFolderPath
|
||||
});
|
||||
const path = value || this.DEFAULT_ROOT_FOLDER;
|
||||
this.displayFolderContent(path)
|
||||
.then(() => {
|
||||
this._path = path;
|
||||
this.folderChange.emit({ path: path });
|
||||
})
|
||||
.catch(err => {
|
||||
this.error.emit(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,14 +267,17 @@ export class DocumentList implements OnInit, AfterContentInit {
|
||||
}
|
||||
}
|
||||
|
||||
displayFolderContent(path: string) {
|
||||
this.data.loadPath(path);
|
||||
displayFolderContent(path: string): Promise<any> {
|
||||
return this.data.loadPath(path);
|
||||
}
|
||||
|
||||
reload() {
|
||||
this.ngZone.run(() => {
|
||||
if (this.currentFolderPath) {
|
||||
this.displayFolderContent(this.currentFolderPath);
|
||||
this.displayFolderContent(this.currentFolderPath)
|
||||
.catch(err => {
|
||||
this.error.emit(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user