Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Allow for proper nesting for getting data for lists and grids (#671)
Browse files Browse the repository at this point in the history
* Changed the list helper getData function to set the result to null if the final part was undefined so that nesting works correctly.

* Added unit tests
  • Loading branch information
Blackbaud-TrevorBurch authored and Blackbaud-PatrickOFriel committed May 11, 2017
1 parent cc24103 commit 49d5a99
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/modules/list/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 2 additions & 4 deletions src/modules/list/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 49d5a99

Please sign in to comment.