mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Unit tests and api improvements for document list
This commit is contained in:
@@ -30,6 +30,7 @@ import { ContentAction } from './content-action';
|
|||||||
import { DocumentActionsService } from '../services/document-actions.service';
|
import { DocumentActionsService } from '../services/document-actions.service';
|
||||||
import { FolderActionsService } from '../services/folder-actions.service';
|
import { FolderActionsService } from '../services/folder-actions.service';
|
||||||
import { ContentActionHandler } from '../models/content-action.model';
|
import { ContentActionHandler } from '../models/content-action.model';
|
||||||
|
import { FileNode } from '../assets/document-library.model.mock';
|
||||||
|
|
||||||
describe('ContentAction', () => {
|
describe('ContentAction', () => {
|
||||||
|
|
||||||
@@ -225,4 +226,47 @@ describe('ContentAction', () => {
|
|||||||
expect(documentActions.getHandler).not.toHaveBeenCalled();
|
expect(documentActions.getHandler).not.toHaveBeenCalled();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should wire model with custom event handler', (done) => {
|
||||||
|
let action = new ContentAction(actionList, documentActions, folderActions);
|
||||||
|
let file = new FileNode();
|
||||||
|
|
||||||
|
let handler = new EventEmitter();
|
||||||
|
handler.subscribe((e) => {
|
||||||
|
expect(e.value).toBe(file);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
action.execute = handler;
|
||||||
|
|
||||||
|
action.ngOnInit();
|
||||||
|
action.model.handler(file);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow registering model without handler', () => {
|
||||||
|
let action = new ContentAction(actionList, documentActions, folderActions);
|
||||||
|
|
||||||
|
spyOn(actionList, 'registerAction').and.callThrough();
|
||||||
|
action.execute = null;
|
||||||
|
action.ngOnInit();
|
||||||
|
|
||||||
|
expect(action.model.handler).toBeUndefined();
|
||||||
|
expect(actionList.registerAction).toHaveBeenCalledWith(action.model);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should register on init', () => {
|
||||||
|
let action = new ContentAction(actionList, null, null);
|
||||||
|
spyOn(action, 'register').and.callThrough();
|
||||||
|
|
||||||
|
action.ngOnInit();
|
||||||
|
expect(action.register).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should require action list to register action with', () => {
|
||||||
|
let action = new ContentAction(actionList, null, null);
|
||||||
|
expect(action.register()).toBeTruthy();
|
||||||
|
|
||||||
|
action = new ContentAction(null, null, null);
|
||||||
|
expect(action.register()).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -73,7 +73,14 @@ export class ContentAction implements OnInit, OnChanges {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.list.registerAction(this.model);
|
this.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
register(): boolean {
|
||||||
|
if (this.list) {
|
||||||
|
return this.list.registerAction(this.model);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes) {
|
ngOnChanges(changes) {
|
||||||
|
@@ -93,4 +93,20 @@ describe('ContentColumn', () => {
|
|||||||
expect(column.model.title).toBe('title2');
|
expect(column.model.title).toBe('title2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should register on init', () => {
|
||||||
|
let column = new ContentColumn(columnList);
|
||||||
|
spyOn(column, 'register').and.callThrough();
|
||||||
|
|
||||||
|
column.ngOnInit();
|
||||||
|
expect(column.register).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should require action list to register action with', () => {
|
||||||
|
let column = new ContentColumn(columnList);
|
||||||
|
expect(column.register()).toBeTruthy();
|
||||||
|
|
||||||
|
column = new ContentColumn(null);
|
||||||
|
expect(column.register()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -66,9 +66,14 @@ export class ContentColumn implements OnInit, OnChanges {
|
|||||||
this.model.srTitle = 'Thumbnail';
|
this.model.srTitle = 'Thumbnail';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
register(): boolean {
|
||||||
if (this.list) {
|
if (this.list) {
|
||||||
this.list.registerColumn(this.model);
|
return this.list.registerColumn(this.model);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(change) {
|
ngOnChanges(change) {
|
||||||
|
@@ -106,4 +106,27 @@ describe('DocumentListBreadcrumb', () => {
|
|||||||
expect(documentList.currentFolderPath).toBe(node.path);
|
expect(documentList.currentFolderPath).toBe(node.path);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should do nothing for same path', () => {
|
||||||
|
let called = 0;
|
||||||
|
|
||||||
|
component.pathChanged.subscribe(() => called++);
|
||||||
|
|
||||||
|
component.currentFolderPath = '/';
|
||||||
|
component.currentFolderPath = '/';
|
||||||
|
|
||||||
|
expect(called).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit path changed event', (done) => {
|
||||||
|
let path = '/some/path';
|
||||||
|
|
||||||
|
component.pathChanged.subscribe(e => {
|
||||||
|
expect(e.value).toBe(path);
|
||||||
|
expect(e.route).toBe(component.route);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.currentFolderPath = path;
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -49,6 +49,10 @@ export class DocumentListBreadcrumb {
|
|||||||
this._currentFolderPath = this.rootFolder.path;
|
this._currentFolderPath = this.rootFolder.path;
|
||||||
this.route = [ this.rootFolder ];
|
this.route = [ this.rootFolder ];
|
||||||
}
|
}
|
||||||
|
this.pathChanged.emit({
|
||||||
|
value: this._currentFolderPath,
|
||||||
|
route: this.route
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +69,9 @@ export class DocumentListBreadcrumb {
|
|||||||
@Output()
|
@Output()
|
||||||
navigate: EventEmitter<any> = new EventEmitter();
|
navigate: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
pathChanged: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
onRoutePathClick(route: PathNode, e?: Event) {
|
onRoutePathClick(route: PathNode, e?: Event) {
|
||||||
if (e) {
|
if (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@@ -849,15 +849,29 @@ describe('DocumentList', () => {
|
|||||||
|
|
||||||
it('should put folders to top on sort', () => {
|
it('should put folders to top on sort', () => {
|
||||||
let folder = new FolderNode();
|
let folder = new FolderNode();
|
||||||
let file = new FileNode();
|
let file1 = new FileNode('file1');
|
||||||
let page = new PageNode([file, folder]);
|
let file2 = new FileNode('file2');
|
||||||
|
let page = new PageNode([file1, file2, folder]);
|
||||||
|
|
||||||
|
// asc
|
||||||
documentList.sort(page, new ColumnSortingModel({
|
documentList.sort(page, new ColumnSortingModel({
|
||||||
key: 'name'
|
key: 'name',
|
||||||
|
direction: 'asc'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(page.list.entries[0]).toBe(folder);
|
expect(page.list.entries[0]).toBe(folder);
|
||||||
expect(page.list.entries[1]).toBe(file);
|
expect(page.list.entries[1]).toBe(file1);
|
||||||
|
expect(page.list.entries[2]).toBe(file2);
|
||||||
|
|
||||||
|
// desc
|
||||||
|
documentList.sort(page, new ColumnSortingModel({
|
||||||
|
key: 'name',
|
||||||
|
direction: 'desc'
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(page.list.entries[0]).toBe(folder);
|
||||||
|
expect(page.list.entries[1]).toBe(file2);
|
||||||
|
expect(page.list.entries[2]).toBe(file1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should sort by dates up to ms', () => {
|
it('should sort by dates up to ms', () => {
|
||||||
@@ -868,6 +882,8 @@ describe('DocumentList', () => {
|
|||||||
file2.entry['dateProp'] = new Date(2016, 6, 30, 13, 14, 2);
|
file2.entry['dateProp'] = new Date(2016, 6, 30, 13, 14, 2);
|
||||||
|
|
||||||
let page = new PageNode([file1, file2]);
|
let page = new PageNode([file1, file2]);
|
||||||
|
|
||||||
|
// desc
|
||||||
documentList.sort(page, new ColumnSortingModel({
|
documentList.sort(page, new ColumnSortingModel({
|
||||||
key: 'dateProp',
|
key: 'dateProp',
|
||||||
direction: 'desc'
|
direction: 'desc'
|
||||||
@@ -875,6 +891,15 @@ describe('DocumentList', () => {
|
|||||||
|
|
||||||
expect(page.list.entries[0]).toBe(file2);
|
expect(page.list.entries[0]).toBe(file2);
|
||||||
expect(page.list.entries[1]).toBe(file1);
|
expect(page.list.entries[1]).toBe(file1);
|
||||||
|
|
||||||
|
// asc
|
||||||
|
documentList.sort(page, new ColumnSortingModel({
|
||||||
|
key: 'dateProp',
|
||||||
|
direction: 'asc'
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(page.list.entries[0]).toBe(file1);
|
||||||
|
expect(page.list.entries[1]).toBe(file2);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user