-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<CategorySelect> support post_tags and hierarchical = false taxonomy. (…
- Loading branch information
1 parent
7eac2d0
commit 18da4d9
Showing
4 changed files
with
95 additions
and
5 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,61 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { buildTermsTree } from '../terms'; | ||
|
||
describe( 'buildTermsTree()', () => { | ||
it( 'Should return same array as input with null parent and empty children added if parent is never specified.', () => { | ||
const input = Object.freeze( [ | ||
{ id: 2232, dummy: true }, | ||
{ id: 2245, dummy: true }, | ||
] ); | ||
const output = Object.freeze( [ | ||
{ id: 2232, parent: null, children: [], dummy: true }, | ||
{ id: 2245, parent: null, children: [], dummy: true }, | ||
] ); | ||
const termsTreem = buildTermsTree( input ); | ||
expect( termsTreem ).toEqual( output ); | ||
} ); | ||
it( 'Should return same array as input with empty children added if all the elements are top level', () => { | ||
const input = Object.freeze( [ | ||
{ id: 2232, parent: 0, dummy: true }, | ||
{ id: 2245, parent: 0, dummy: false }, | ||
] ); | ||
const output = [ | ||
{ id: 2232, parent: 0, children: [], dummy: true }, | ||
{ id: 2245, parent: 0, children: [], dummy: false }, | ||
]; | ||
const termsTreem = buildTermsTree( input ); | ||
expect( termsTreem ).toEqual( output ); | ||
} ); | ||
it( 'Should return element with its child if a child exists', () => { | ||
const input = Object.freeze( [ | ||
{ id: 2232, parent: 0 }, | ||
{ id: 2245, parent: 2232 }, | ||
] ); | ||
const output = [ | ||
{ id: 2232, parent: 0, children: [ | ||
{ id: 2245, parent: 2232, children: [] }, | ||
] }, | ||
]; | ||
const termsTreem = buildTermsTree( input ); | ||
expect( termsTreem ).toEqual( output ); | ||
} ); | ||
it( 'Should return elements with multiple children and elements with no children', () => { | ||
const input = Object.freeze( [ | ||
{ id: 2232, parent: 0 }, | ||
{ id: 2245, parent: 2232 }, | ||
{ id: 2249, parent: 0 }, | ||
{ id: 2246, parent: 2232 }, | ||
] ); | ||
const output = [ | ||
{ id: 2232, parent: 0, children: [ | ||
{ id: 2245, parent: 2232, children: [] }, | ||
{ id: 2246, parent: 2232, children: [] }, | ||
] }, | ||
{ id: 2249, parent: 0, children: [] }, | ||
]; | ||
const termsTreem = buildTermsTree( input ); | ||
expect( termsTreem ).toEqual( output ); | ||
} ); | ||
} ); |
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