New 'core:/utils/ObjectUtils', additional unit tests

This commit is contained in:
Denys Vuika
2016-07-07 14:30:15 +01:00
parent 3881faec42
commit acfcd19af0
7 changed files with 203 additions and 71 deletions

View File

@@ -347,11 +347,6 @@ describe('ObjectDataRow', () => {
expect(row.getValue('some.missing.property')).toBeUndefined();
});
it('should return undefined when getting value for missing target', () => {
let row = new ObjectDataRow({});
expect(row.getObjectValue(null, 'id')).toBeUndefined();
});
it('should check top level value exists', () => {
let row = new ObjectDataRow({ id: 1 });

View File

@@ -16,6 +16,7 @@
*/
import { DatePipe } from '@angular/common';
import { ObjectUtils } from 'ng2-alfresco-core';
import {
DataTableAdapter,
@@ -147,40 +148,8 @@ export class ObjectDataRow implements DataRow {
}
}
/**
* Gets a value from an object by composed key
* documentList.getObjectValue({ item: { nodeType: 'cm:folder' }}, 'item.nodeType') ==> 'cm:folder'
* @param target
* @param key
* @returns {string}
*/
getObjectValue(target: any, key: string): any {
if (!target) {
return undefined;
}
let keys = key.split('.');
key = '';
do {
key += keys.shift();
let value = target[key];
if (value !== undefined && (typeof value === 'object' || !keys.length)) {
target = value;
key = '';
} else if (!keys.length) {
target = undefined;
} else {
key += '.';
}
} while (keys.length);
return target;
}
getValue(key: string): any {
return this.getObjectValue(this.obj, key);
return ObjectUtils.getValue(this.obj, key);
}
hasValue(key: string): boolean {