mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Unit tests for document list
- unit tests - component code improvements refs #9
This commit is contained in:
@@ -42,12 +42,12 @@ export declare class DocumentList implements OnInit, AfterViewChecked, AfterCont
|
||||
ngAfterViewChecked(): void;
|
||||
getContentActions(target: string, type: string): ContentActionModel[];
|
||||
onNavigateParentClick($event: any): void;
|
||||
onItemClick(item: DocumentEntity, $event: any): void;
|
||||
onItemClick(item: DocumentEntity, $event?: any): void;
|
||||
goToRoute(r: any, $event: any): void;
|
||||
getContentUrl(document: DocumentEntity): string;
|
||||
getDocumentThumbnailUrl(document: DocumentEntity): string;
|
||||
getContentUrl(node: DocumentEntity): string;
|
||||
getDocumentThumbnailUrl(node: DocumentEntity): string;
|
||||
executeContentAction(node: DocumentEntity, action: ContentActionModel): void;
|
||||
displayFolderContent(path: any): void;
|
||||
private _getItemPath(item);
|
||||
private _setupDefaultColumns();
|
||||
getNodePath(node: DocumentEntity): string;
|
||||
setupDefaultColumns(): void;
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ System.register(['angular2/core', './../services/alfresco.service', './../models
|
||||
};
|
||||
DocumentList.prototype.ngAfterContentInit = function () {
|
||||
if (!this.columns || this.columns.length === 0) {
|
||||
this._setupDefaultColumns();
|
||||
this.setupDefaultColumns();
|
||||
}
|
||||
};
|
||||
DocumentList.prototype.ngAfterViewChecked = function () {
|
||||
@@ -98,6 +98,7 @@ System.register(['angular2/core', './../services/alfresco.service', './../models
|
||||
}
|
||||
};
|
||||
DocumentList.prototype.onItemClick = function (item, $event) {
|
||||
if ($event === void 0) { $event = null; }
|
||||
if ($event) {
|
||||
$event.preventDefault();
|
||||
}
|
||||
@@ -106,7 +107,7 @@ System.register(['angular2/core', './../services/alfresco.service', './../models
|
||||
});
|
||||
if (this.navigate && item) {
|
||||
if (item.isFolder) {
|
||||
var path = this._getItemPath(item);
|
||||
var path = this.getNodePath(item);
|
||||
this.route.push({
|
||||
name: item.displayName,
|
||||
path: path
|
||||
@@ -127,11 +128,17 @@ System.register(['angular2/core', './../services/alfresco.service', './../models
|
||||
}
|
||||
}
|
||||
};
|
||||
DocumentList.prototype.getContentUrl = function (document) {
|
||||
return this._alfrescoService.getContentUrl(document);
|
||||
DocumentList.prototype.getContentUrl = function (node) {
|
||||
if (this._alfrescoService) {
|
||||
return this._alfrescoService.getContentUrl(node);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
DocumentList.prototype.getDocumentThumbnailUrl = function (document) {
|
||||
return this._alfrescoService.getDocumentThumbnailUrl(document);
|
||||
DocumentList.prototype.getDocumentThumbnailUrl = function (node) {
|
||||
if (this._alfrescoService) {
|
||||
return this._alfrescoService.getDocumentThumbnailUrl(node);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
DocumentList.prototype.executeContentAction = function (node, action) {
|
||||
if (action) {
|
||||
@@ -147,13 +154,16 @@ System.register(['angular2/core', './../services/alfresco.service', './../models
|
||||
.subscribe(function (folder) { return _this.folder = folder; }, function (error) { return _this.errorMessage = error; });
|
||||
}
|
||||
};
|
||||
DocumentList.prototype._getItemPath = function (item) {
|
||||
var container = item.location.container;
|
||||
var path = item.location.path !== '/' ? (item.location.path + '/') : '/';
|
||||
var relativePath = container + path + item.fileName;
|
||||
return item.location.site + '/' + relativePath;
|
||||
DocumentList.prototype.getNodePath = function (node) {
|
||||
if (node) {
|
||||
var container = node.location.container;
|
||||
var path = node.location.path !== '/' ? (node.location.path + '/') : '/';
|
||||
var relativePath = container + path + node.fileName;
|
||||
return node.location.site + '/' + relativePath;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
DocumentList.prototype._setupDefaultColumns = function () {
|
||||
DocumentList.prototype.setupDefaultColumns = function () {
|
||||
var thumbnailCol = new content_column_model_1.ContentColumnModel();
|
||||
thumbnailCol.source = '$thumbnail';
|
||||
var nameCol = new content_column_model_1.ContentColumnModel();
|
||||
|
File diff suppressed because one or more lines are too long
@@ -81,7 +81,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
|
||||
ngAfterContentInit() {
|
||||
if (!this.columns || this.columns.length === 0) {
|
||||
this._setupDefaultColumns();
|
||||
this.setupDefaultColumns();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
}
|
||||
}
|
||||
|
||||
onItemClick(item: DocumentEntity, $event) {
|
||||
onItemClick(item: DocumentEntity, $event = null) {
|
||||
if ($event) {
|
||||
$event.preventDefault();
|
||||
}
|
||||
@@ -131,7 +131,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
|
||||
if (this.navigate && item) {
|
||||
if (item.isFolder) {
|
||||
let path = this._getItemPath(item);
|
||||
let path = this.getNodePath(item);
|
||||
this.route.push({
|
||||
name: item.displayName,
|
||||
path: path
|
||||
@@ -155,12 +155,18 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
}
|
||||
}
|
||||
|
||||
getContentUrl(document: DocumentEntity) {
|
||||
return this._alfrescoService.getContentUrl(document);
|
||||
getContentUrl(node: DocumentEntity) {
|
||||
if (this._alfrescoService) {
|
||||
return this._alfrescoService.getContentUrl(node);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getDocumentThumbnailUrl(document: DocumentEntity) {
|
||||
return this._alfrescoService.getDocumentThumbnailUrl(document);
|
||||
getDocumentThumbnailUrl(node: DocumentEntity) {
|
||||
if (this._alfrescoService) {
|
||||
return this._alfrescoService.getDocumentThumbnailUrl(node);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
executeContentAction(node: DocumentEntity, action: ContentActionModel) {
|
||||
@@ -181,14 +187,17 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
}
|
||||
}
|
||||
|
||||
private _getItemPath(item: DocumentEntity): string {
|
||||
let container = item.location.container;
|
||||
let path = item.location.path !== '/' ? (item.location.path + '/' ) : '/';
|
||||
let relativePath = container + path + item.fileName;
|
||||
return item.location.site + '/' + relativePath;
|
||||
getNodePath(node: DocumentEntity): string {
|
||||
if (node) {
|
||||
let container = node.location.container;
|
||||
let path = node.location.path !== '/' ? (node.location.path + '/' ) : '/';
|
||||
let relativePath = container + path + node.fileName;
|
||||
return node.location.site + '/' + relativePath;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private _setupDefaultColumns() {
|
||||
setupDefaultColumns(): void {
|
||||
let thumbnailCol = new ContentColumnModel();
|
||||
thumbnailCol.source = '$thumbnail';
|
||||
|
||||
|
@@ -30,14 +30,23 @@ describe('document-list', () => {
|
||||
|
||||
let alfrescoServiceMock: AlfrescoServiceMock;
|
||||
let documentList: DocumentList;
|
||||
let eventMock: any;
|
||||
|
||||
beforeEach(() => {
|
||||
alfrescoServiceMock = new AlfrescoServiceMock();
|
||||
documentList = new DocumentList(alfrescoServiceMock);
|
||||
|
||||
eventMock = {
|
||||
preventDefault: function() {}
|
||||
};
|
||||
});
|
||||
|
||||
it('should setup default columns', () => {
|
||||
spyOn(documentList, 'setupDefaultColumns').and.callThrough();
|
||||
|
||||
documentList.ngAfterContentInit();
|
||||
|
||||
expect(documentList.setupDefaultColumns).toHaveBeenCalled();
|
||||
expect(documentList.columns.length).not.toBe(0);
|
||||
});
|
||||
|
||||
@@ -93,6 +102,12 @@ describe('document-list', () => {
|
||||
expect(alfrescoServiceMock.getContentUrl).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return no content url without service', () => {
|
||||
let list = new DocumentList(null);
|
||||
let node = new DocumentEntity();
|
||||
expect(list.getContentUrl(node)).toBeNull();
|
||||
});
|
||||
|
||||
it('should get thumbnail url', () => {
|
||||
let url = 'URL';
|
||||
spyOn(alfrescoServiceMock, 'getDocumentThumbnailUrl').and.returnValue(url);
|
||||
@@ -102,6 +117,12 @@ describe('document-list', () => {
|
||||
expect(result).toBe(url);
|
||||
expect(alfrescoServiceMock.getDocumentThumbnailUrl).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should get no thumbnail url without service', () => {
|
||||
let list = new DocumentList(null);
|
||||
let node = new DocumentEntity();
|
||||
expect(list.getDocumentThumbnailUrl(node)).toBeNull();
|
||||
});
|
||||
|
||||
it('should execute action with node', () => {
|
||||
let node = new DocumentEntity();
|
||||
@@ -207,4 +228,90 @@ describe('document-list', () => {
|
||||
expect(actions.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should emit itemClick event', (done) => {
|
||||
let node: DocumentEntity = new DocumentEntity();
|
||||
documentList.itemClick.subscribe(e => {
|
||||
expect(e.value).toBe(node);
|
||||
done();
|
||||
});
|
||||
documentList.onItemClick(node);
|
||||
});
|
||||
|
||||
it('should prevent default events for item click', () => {
|
||||
spyOn(eventMock, 'preventDefault').and.stub();
|
||||
|
||||
documentList.onItemClick(null, eventMock);
|
||||
expect(eventMock.preventDefault).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should display folder content on click', () => {
|
||||
let path = '/';
|
||||
|
||||
let node = new DocumentEntity();
|
||||
node.isFolder = true;
|
||||
node.displayName = '<display name>';
|
||||
|
||||
spyOn(documentList, 'getNodePath').and.returnValue(path);
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
|
||||
documentList.onItemClick(node);
|
||||
|
||||
expect(documentList.displayFolderContent).toHaveBeenCalledWith(path);
|
||||
|
||||
var routeEntry = documentList.route.pop();
|
||||
expect(routeEntry.name).toBe(node.displayName);
|
||||
expect(routeEntry.path).toBe(path);
|
||||
});
|
||||
|
||||
it('should not display folder content when no target node provided', () => {
|
||||
expect(documentList.navigate).toBe(true);
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
|
||||
documentList.onItemClick(null);
|
||||
expect(documentList.displayFolderContent).not.toHaveBeenCalled();
|
||||
|
||||
});
|
||||
|
||||
it('should display folder content only on folder node click', () => {
|
||||
expect(documentList.navigate).toBe(true);
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
|
||||
let node = new DocumentEntity();
|
||||
node.isFolder = false;
|
||||
|
||||
documentList.onItemClick(node);
|
||||
|
||||
expect(documentList.displayFolderContent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not display folder content on click when navigation is off', () => {
|
||||
spyOn(documentList, 'displayFolderContent').and.stub();
|
||||
|
||||
let node = new DocumentEntity();
|
||||
node.isFolder = true;
|
||||
node.displayName = '<display name>';
|
||||
|
||||
documentList.navigate = false;
|
||||
documentList.onItemClick(node);
|
||||
|
||||
expect(documentList.displayFolderContent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should require node to get path', () => {
|
||||
expect(documentList.getNodePath(null)).toBe(null);
|
||||
});
|
||||
|
||||
it('should get node path', () => {
|
||||
let node = {
|
||||
fileName: 'fileName',
|
||||
location: {
|
||||
site: 'swsdp',
|
||||
container: 'documentLibrary',
|
||||
path: '\/'
|
||||
}
|
||||
};
|
||||
|
||||
expect(documentList.getNodePath(node)).toBe('swsdp/documentLibrary/fileName');
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user