forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataViews Fields API: default getValueFromId supports nested objects (W…
…ordPress#66890) Co-authored-by: oandregal <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: ntsekouras <[email protected]> Co-authored-by: cbravobernal <[email protected]>
- Loading branch information
1 parent
7eade84
commit 258164d
Showing
2 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { normalizeFields } from '../normalize-fields'; | ||
import type { Field } from '../types'; | ||
|
||
describe( 'normalizeFields: default getValue', () => { | ||
describe( 'getValue from ID', () => { | ||
it( 'user', () => { | ||
const item = { user: 'value' }; | ||
const fields: Field< {} >[] = [ | ||
{ | ||
id: 'user', | ||
}, | ||
]; | ||
const normalizedFields = normalizeFields( fields ); | ||
const result = normalizedFields[ 0 ].getValue( { item } ); | ||
expect( result ).toBe( 'value' ); | ||
} ); | ||
|
||
it( 'user.name', () => { | ||
const item = { user: { name: 'value' } }; | ||
const fields: Field< {} >[] = [ | ||
{ | ||
id: 'user.name', | ||
}, | ||
]; | ||
const normalizedFields = normalizeFields( fields ); | ||
const result = normalizedFields[ 0 ].getValue( { item } ); | ||
expect( result ).toBe( 'value' ); | ||
} ); | ||
|
||
it( 'user.name.first', () => { | ||
const item = { user: { name: { first: 'value' } } }; | ||
const fields: Field< {} >[] = [ | ||
{ | ||
id: 'user.name.first', | ||
}, | ||
]; | ||
const normalizedFields = normalizeFields( fields ); | ||
const result = normalizedFields[ 0 ].getValue( { item } ); | ||
expect( result ).toBe( 'value' ); | ||
} ); | ||
} ); | ||
} ); |