#9 Unit tests

This commit is contained in:
Denys Vuika
2016-05-10 16:57:19 +01:00
parent 7c7e5d52b7
commit 6af4054931
3 changed files with 29 additions and 2 deletions

View File

@@ -56,6 +56,6 @@ export declare class DocumentList implements OnInit, AfterViewChecked, AfterCont
* @param key
* @returns {string}
*/
getObjectValue(target: any, key: string): string;
getObjectValue(target: any, key: string): any;
setupDefaultColumns(): void;
}

View File

@@ -204,7 +204,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
* @param key
* @returns {string}
*/
getObjectValue(target: any, key: string): string {
getObjectValue(target: any, key: string): any {
let keys = key.split('.');
key = '';

View File

@@ -316,4 +316,31 @@ describe('DocumentList', () => {
expect(documentList.getNodePath(node)).toBe('swsdp/documentLibrary/fileName');
});
it('should return root object value', () => {
var target = {
key1: 'value1'
};
expect(documentList.getObjectValue(target, 'key1')).toBe('value1');
});
it('should return no object value when key is missing', () => {
var target = {
key1: 'value1'
};
expect(documentList.getObjectValue(target, 'missing')).toBeUndefined();
});
it('should return nested object value', () => {
var target = {
key1: {
key2: {
key3: 'value1'
}
}
};
expect(documentList.getObjectValue(target, 'key1.key2.key3')).toBe('value1');
});
});