mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
update unit tests
This commit is contained in:
@@ -15,8 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PathElementEntity } from 'alfresco-js-api';
|
||||
import { DocumentListBreadcrumb } from './breadcrumb.component';
|
||||
// import { DocumentList } from '../document-list';
|
||||
import { DocumentList } from '../document-list';
|
||||
|
||||
describe('DocumentListBreadcrumb', () => {
|
||||
|
||||
@@ -32,98 +33,34 @@ describe('DocumentListBreadcrumb', () => {
|
||||
expect(component.currentFolderPath).toBe(path);
|
||||
});
|
||||
|
||||
it('should init with root folder by default', () => {
|
||||
expect(component.route.length).toBe(1);
|
||||
expect(component.route[0]).toEqual(
|
||||
jasmine.objectContaining({
|
||||
name: 'Root',
|
||||
path: '/'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should fallback to default root for invalid path', () => {
|
||||
component.currentFolderPath = null;
|
||||
expect(component.currentFolderPath).toBe('/');
|
||||
|
||||
expect(component.route.length).toBe(1);
|
||||
expect(component.route[0]).toEqual(
|
||||
jasmine.objectContaining({
|
||||
name: 'Root',
|
||||
path: '/'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should parse the route', () => {
|
||||
component.currentFolderPath = '/some/path';
|
||||
|
||||
expect(component.route.length).toBe(3);
|
||||
expect(component.route).toEqual(
|
||||
jasmine.objectContaining([
|
||||
{ name: 'Root', path: '/' },
|
||||
{ name: 'some', path: '/some' },
|
||||
{ name: 'path', path: '/some/path' }
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should prevent default click behavior', () => {
|
||||
let event = jasmine.createSpyObj('event', ['preventDefault']);
|
||||
component.onRoutePathClick(null, event);
|
||||
expect(event.preventDefault).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
/*
|
||||
it('should emit navigation event', (done) => {
|
||||
let node = <PathNode> { name: 'name', path: '/path' };
|
||||
let node = <PathElementEntity> { id: '-id-', name: 'name' };
|
||||
component.navigate.subscribe(val => {
|
||||
expect(val.value.name).toBe(node.name);
|
||||
expect(val.value.path).toBe(node.path);
|
||||
expect(val.value).toBe(node);
|
||||
done();
|
||||
});
|
||||
|
||||
component.onRoutePathClick(node, null);
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should update document list on click', (done) => {
|
||||
let documentList = new DocumentList(null, null, null);
|
||||
spyOn(documentList, 'loadFolderByPath').and.returnValue(Promise.resolve());
|
||||
spyOn(documentList, 'loadFolderByNodeId').and.stub();
|
||||
|
||||
let node = <PathNode> { name: 'name', path: '/path' };
|
||||
let node = <PathElementEntity> { id: '-id-', name: 'name' };
|
||||
component.target = documentList;
|
||||
|
||||
component.onRoutePathClick(node, null);
|
||||
setTimeout(() => {
|
||||
expect(documentList.currentFolderPath).toBe(node.path);
|
||||
expect(documentList.loadFolderByNodeId).toHaveBeenCalledWith(node.id);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
*/
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NgZone, /*SimpleChange, */TemplateRef } from '@angular/core';
|
||||
import { NgZone, SimpleChange, 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';
|
||||
@@ -48,16 +48,6 @@ describe('DocumentList', () => {
|
||||
window['componentHandler'] = componentHandler;
|
||||
});
|
||||
|
||||
/*
|
||||
it('should update root folder ID', () => {
|
||||
let adapter = documentList.data;
|
||||
expect(adapter.rootFolderId).toBe(adapter.DEFAULT_ROOT_ID);
|
||||
|
||||
documentList.rootFolderId = '-shared-';
|
||||
expect(adapter.rootFolderId).toBe('-shared-');
|
||||
});
|
||||
*/
|
||||
|
||||
it('should setup default columns', () => {
|
||||
spyOn(documentList, 'setupDefaultColumns').and.callThrough();
|
||||
|
||||
@@ -159,83 +149,45 @@ describe('DocumentList', () => {
|
||||
documentList.onNodeClick(node);
|
||||
});
|
||||
|
||||
/*
|
||||
it('should display folder content on click', () => {
|
||||
let path = '/';
|
||||
|
||||
let node = new FolderNode('<display name>');
|
||||
|
||||
spyOn(documentList, 'getNodePath').and.returnValue(path);
|
||||
spyOn(documentList, 'loadFolderByPath').and.returnValue(Promise.resolve(true));
|
||||
spyOn(documentList, 'loadFolder').and.returnValue(Promise.resolve(true));
|
||||
|
||||
documentList.navigationMode = DocumentList.SINGLE_CLICK_NAVIGATION;
|
||||
documentList.onNodeClick(node);
|
||||
|
||||
expect(documentList.currentFolderPath).toBe(path);
|
||||
expect(documentList.loadFolder).toHaveBeenCalled();
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should not display folder content when no target node provided', () => {
|
||||
expect(documentList.navigate).toBe(true);
|
||||
spyOn(documentList, 'loadFolderByPath').and.stub();
|
||||
spyOn(documentList, 'loadFolder').and.stub();
|
||||
|
||||
documentList.onNodeClick(null);
|
||||
expect(documentList.loadFolderByPath).not.toHaveBeenCalled();
|
||||
expect(documentList.loadFolder).not.toHaveBeenCalled();
|
||||
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should display folder content only on folder node click', () => {
|
||||
expect(documentList.navigate).toBe(true);
|
||||
spyOn(documentList, 'loadFolderByPath').and.stub();
|
||||
spyOn(documentList, 'loadFolder').and.stub();
|
||||
|
||||
let node = new FileNode();
|
||||
documentList.onNodeClick(node);
|
||||
|
||||
expect(documentList.loadFolderByPath).not.toHaveBeenCalled();
|
||||
expect(documentList.loadFolder).not.toHaveBeenCalled();
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should not display folder content on click when navigation is off', () => {
|
||||
spyOn(documentList, 'loadFolderByPath').and.stub();
|
||||
spyOn(documentList, 'loadFolder').and.stub();
|
||||
|
||||
let node = new FolderNode('<display name>');
|
||||
documentList.navigate = false;
|
||||
documentList.onNodeClick(node);
|
||||
|
||||
expect(documentList.loadFolderByPath).not.toHaveBeenCalled();
|
||||
expect(documentList.loadFolder).not.toHaveBeenCalled();
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should require node to get path', () => {
|
||||
expect(documentList.getNodePath(null)).toBe(null);
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should display folder content for new folder path', () => {
|
||||
spyOn(documentList, 'loadFolderByPath').and.returnValue(Promise.resolve());
|
||||
let newPath = '/some/new/path';
|
||||
documentList.currentFolderPath = newPath;
|
||||
documentList.ngOnChanges({currentFolderPath: new SimpleChange(null, newPath)});
|
||||
expect(documentList.loadFolderByPath).toHaveBeenCalledWith(newPath);
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should reset to default path', () => {
|
||||
spyOn(documentList, 'loadFolderByPath').and.returnValue(Promise.resolve());
|
||||
documentList.currentFolderPath = null;
|
||||
documentList.ngOnChanges({currentFolderPath: new SimpleChange('', null)});
|
||||
|
||||
expect(documentList.currentFolderPath).toBe(documentList.DEFAULT_FOLDER_PATH);
|
||||
expect(documentList.loadFolderByPath).toHaveBeenCalledWith(documentList.DEFAULT_FOLDER_PATH);
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should emit folder changed event', (done) => {
|
||||
@@ -284,7 +236,7 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should subscribe to context action handler', () => {
|
||||
spyOn(documentList, 'loadFolderByPath').and.returnValue(Promise.resolve(true));
|
||||
spyOn(documentList, 'loadFolder').and.stub();
|
||||
spyOn(documentList, 'contextActionCallback').and.stub();
|
||||
let value = {};
|
||||
documentList.ngOnInit();
|
||||
@@ -358,8 +310,6 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should perform navigation for folder node only', () => {
|
||||
spyOn(documentList, 'getNodePath').and.returnValue('/path');
|
||||
|
||||
let folder = new FolderNode();
|
||||
let file = new FileNode();
|
||||
|
||||
@@ -374,14 +324,6 @@ describe('DocumentList', () => {
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should trim company home from node path', () => {
|
||||
let file = new FileNode('file.txt');
|
||||
file.entry.path.name = '/Company Home/folder1';
|
||||
expect(documentList.getNodePath(file)).toBe('/folder1/file.txt');
|
||||
});
|
||||
*/
|
||||
|
||||
it('should require valid node for file preview', () => {
|
||||
let file = new FileNode();
|
||||
file.entry = null;
|
||||
@@ -412,24 +354,11 @@ describe('DocumentList', () => {
|
||||
expect(documentList.performNavigation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
/*
|
||||
it('should display folder content on reload', () => {
|
||||
spyOn(documentList, 'loadFolderByPath').and.callThrough();
|
||||
spyOn(documentList, 'loadFolder').and.callThrough();
|
||||
documentList.reload();
|
||||
expect(documentList.loadFolderByPath).toHaveBeenCalled();
|
||||
expect(documentList.loadFolder).toHaveBeenCalled();
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should require path to display folder content', () => {
|
||||
spyOn(documentListService, 'getFolder').and.callThrough();
|
||||
|
||||
documentList.loadFolderByPath(null);
|
||||
documentList.loadFolderByPath('');
|
||||
|
||||
expect(documentListService.getFolder).not.toHaveBeenCalled();
|
||||
});
|
||||
*/
|
||||
|
||||
it('should require node to resolve context menu actions', () => {
|
||||
expect(documentList.getContextActions(null)).toBeNull();
|
||||
@@ -489,23 +418,6 @@ describe('DocumentList', () => {
|
||||
expect(documentList.getNodeActions).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
/*
|
||||
it('should require current folder path to reload', () => {
|
||||
|
||||
// Redefine 'currentFolderPath' to disable native setter validation
|
||||
Object.defineProperty(documentList, 'currentFolderPath', {
|
||||
value: null
|
||||
});
|
||||
expect(documentList.currentFolderPath).toBeNull();
|
||||
|
||||
spyOn(documentList, 'loadFolderByPath').and.stub();
|
||||
|
||||
documentList.reload();
|
||||
|
||||
expect(documentList.loadFolderByPath).not.toHaveBeenCalled();
|
||||
});
|
||||
*/
|
||||
|
||||
it('should enforce single-click on mobile browser', () => {
|
||||
spyOn(documentList, 'isMobile').and.returnValue(true);
|
||||
documentList.navigationMode = DocumentList.DOUBLE_CLICK_NAVIGATION;
|
||||
@@ -514,20 +426,18 @@ describe('DocumentList', () => {
|
||||
expect(documentList.navigationMode).toBe(DocumentList.SINGLE_CLICK_NAVIGATION);
|
||||
});
|
||||
|
||||
/*
|
||||
it('should emit error on wrong path', (done) => {
|
||||
it('should emit error on wrong folder id', (done) => {
|
||||
let raised = false;
|
||||
documentList.error.subscribe(err => raised = true);
|
||||
spyOn(documentList, 'loadFolderByPath').and.returnValue(Promise.reject(false));
|
||||
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.reject(false));
|
||||
|
||||
documentList.currentFolderPath = 'wrong-path';
|
||||
documentList.ngOnChanges({currentFolderPath: new SimpleChange(null, documentList.currentFolderPath)});
|
||||
documentList.currentFolderId = 'wrong-id';
|
||||
documentList.ngOnChanges({currentFolderId: new SimpleChange(null, documentList.currentFolderId)});
|
||||
setTimeout(() => {
|
||||
expect(raised).toBeTruthy();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
*/
|
||||
|
||||
it('should require dataTable to check empty template', () => {
|
||||
documentList.dataTable = null;
|
||||
@@ -544,34 +454,6 @@ describe('DocumentList', () => {
|
||||
expect(documentList.isEmptyTemplateDefined()).toBeFalsy();
|
||||
});
|
||||
|
||||
/*
|
||||
it('should set root folder ID for underlying adapter', () => {
|
||||
documentList.rootFolderId = 'test';
|
||||
expect(documentList.data.rootFolderId).toBe('test');
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should set default root folder ID for underlying adapter', () => {
|
||||
documentList.rootFolderId = null;
|
||||
expect(documentList.data.rootFolderId).toBe(documentList.data.DEFAULT_ROOT_ID);
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should fetch root folder ID from underlying adapter', () => {
|
||||
documentList.data.rootFolderId = 'test';
|
||||
expect(documentList.rootFolderId).toBe('test');
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
it('should not fetch root folder ID when adapter missing', () => {
|
||||
documentList.data = null;
|
||||
expect(documentList.rootFolderId).toBeNull();
|
||||
});
|
||||
*/
|
||||
|
||||
it('should set row filter for underlying adapter', () => {
|
||||
let filter = <RowFilter> {};
|
||||
spyOn(documentList.data, 'setFilter').and.callThrough();
|
||||
@@ -608,52 +490,10 @@ describe('DocumentList', () => {
|
||||
expect(documentList.onNodeDblClick).toHaveBeenCalledWith(node);
|
||||
});
|
||||
|
||||
/*
|
||||
describe('navigate by folder ID', () => {
|
||||
|
||||
it('should load folder by ID on init', () => {
|
||||
|
||||
documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
|
||||
let loadbyIdSpy: jasmine.Spy = spyOn(documentList.data, 'loadById').and.returnValue(Promise.resolve());
|
||||
|
||||
documentList.ngOnInit();
|
||||
expect(loadbyIdSpy).toHaveBeenCalled();
|
||||
expect(documentList.currentFolderPath).toBe('/');
|
||||
});
|
||||
|
||||
it('should load folder by ID on changes', () => {
|
||||
|
||||
let newNodeId = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
|
||||
documentList.ngOnChanges({currentFolderId: new SimpleChange(null, newNodeId)});
|
||||
|
||||
let loadbyPathSpy: jasmine.Spy = spyOn(documentList.data, 'loadPath').and.returnValue(Promise.resolve());
|
||||
|
||||
documentList.ngOnInit();
|
||||
expect(loadbyPathSpy).toHaveBeenCalled();
|
||||
expect(documentList.currentFolderPath).toBe('/');
|
||||
});
|
||||
|
||||
it('should load folder by ID on init', () => {
|
||||
documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
spyOn(documentList.data, 'loadById').and.returnValue(Promise.resolve());
|
||||
documentList.ngOnInit();
|
||||
expect(documentList.data.loadById).toHaveBeenCalled();
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
describe('configure root folder', () => {
|
||||
|
||||
it('should re-load folder when rootFolderId changed', () => {
|
||||
|
||||
let newRootFolder = '-new-';
|
||||
|
||||
documentList.ngOnChanges({rootFolderId: new SimpleChange(null, newRootFolder)});
|
||||
|
||||
let loadbyPathSpy: jasmine.Spy = spyOn(documentList.data, 'loadPath').and.returnValue(Promise.resolve());
|
||||
|
||||
documentList.ngOnInit();
|
||||
expect(loadbyPathSpy).toHaveBeenCalled();
|
||||
expect(documentList.currentFolderPath).toBe('/');
|
||||
});
|
||||
|
||||
});
|
||||
*/
|
||||
});
|
||||
|
@@ -270,7 +270,8 @@ export class DocumentList implements OnInit, OnChanges, AfterContentInit {
|
||||
this.folderNode = node;
|
||||
this.currentFolderId = node.id;
|
||||
this.data.loadById(node.id).catch(err => this.error.emit(err));
|
||||
});
|
||||
})
|
||||
.catch(err => this.error.emit(err));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlfrescoContentService } from 'ng2-alfresco-core';
|
||||
import { ContentService } from 'ng2-alfresco-core';
|
||||
import { ContentActionHandler } from '../models/content-action.model';
|
||||
import { DocumentActionsService } from './document-actions.service';
|
||||
import { DocumentListServiceMock } from '../assets/document-list.service.mock';
|
||||
@@ -26,11 +26,11 @@ describe('DocumentActionsService', () => {
|
||||
|
||||
let service: DocumentActionsService;
|
||||
let documentListService: DocumentListService;
|
||||
let contentService: AlfrescoContentService;
|
||||
let contentService: ContentService;
|
||||
|
||||
beforeEach(() => {
|
||||
documentListService = new DocumentListServiceMock();
|
||||
contentService = new AlfrescoContentService(null, null);
|
||||
contentService = new ContentService(null, null);
|
||||
service = new DocumentActionsService(documentListService, contentService);
|
||||
});
|
||||
|
||||
|
@@ -18,16 +18,14 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ContentActionHandler } from '../models/content-action.model';
|
||||
import { DocumentListService } from './document-list.service';
|
||||
import { AlfrescoContentService } from 'ng2-alfresco-core';
|
||||
import { ContentService } from 'ng2-alfresco-core';
|
||||
|
||||
@Injectable()
|
||||
export class DocumentActionsService {
|
||||
private handlers: { [id: string]: ContentActionHandler; } = {};
|
||||
|
||||
constructor(
|
||||
private documentListService?: DocumentListService,
|
||||
private contentService?: AlfrescoContentService
|
||||
) {
|
||||
constructor(private documentListService?: DocumentListService,
|
||||
private contentService?: ContentService) {
|
||||
this.setupActionHandlers();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user