From 8ace98375ad1456f47458f6e09de58905207846f Mon Sep 17 00:00:00 2001 From: "BLACKBAUD\\Trevor.Burch" Date: Tue, 9 May 2017 16:17:17 -0400 Subject: [PATCH 1/2] Changed the list helper getData function to set the result to null if the final part was undefined so that nesting works correctly. --- src/modules/list/helpers.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/list/helpers.ts b/src/modules/list/helpers.ts index deb61a153..f911bcacd 100644 --- a/src/modules/list/helpers.ts +++ b/src/modules/list/helpers.ts @@ -11,11 +11,9 @@ export function getData(item: any, selector: string): any { if (resultFieldParts.length > 0) { for (let index = 0; index < resultFieldParts.length; index++) { let part = resultFieldParts[index]; - if (result[part] === undefined) { - break; - } /* tslint:disable */ - else if (result[part] === null) { + /* istanbul ignore else */ + if (result[part] === null || result[part] === undefined) { result = null; break; } From aff89c23dd9d2bee6bce79f9479e832c301e06a7 Mon Sep 17 00:00:00 2001 From: "BLACKBAUD\\Trevor.Burch" Date: Wed, 10 May 2017 10:42:24 -0400 Subject: [PATCH 2/2] Added unit tests --- src/modules/list/helpers.spec.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/modules/list/helpers.spec.ts b/src/modules/list/helpers.spec.ts index 785bdc987..257217c1a 100644 --- a/src/modules/list/helpers.spec.ts +++ b/src/modules/list/helpers.spec.ts @@ -32,6 +32,33 @@ describe('list helpers', () => { expect(result).toBeNull(); }); + it('returns property when selector is a nested selector', () => { + let data: any = { + myResults: { nestedValue: 'expected'}, + otherResult: 'nothing' + }; + let result = getData(data, 'myResults.nestedValue'); + expect(result).toBe('expected'); + }); + + it('returns property when selector is a nested selector that does not exits', () => { + let data: any = { + myResults: {}, + otherResult: 'nothing' + }; + let result = getData(data, 'myResults.nestedValue'); + expect(result).toBeNull(); + }); + + it('returns property when selector is a nested selector that is undefined', () => { + let data: any = { + myResults: { nestedValue: undefined }, + otherResult: 'nothing' + }; + let result = getData(data, 'myResults.nestedValue'); + expect(result).toBeNull(); + }); + it('returns null when empty string selector defined', () => { let data = { myResult: 'something',