2023-06-07 03:39:38 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-08-15 11:26:37 +00:00
|
|
|
import { findComponentMeta } from '../find-component';
|
|
|
|
|
|
|
|
type ComponentProps = {
|
|
|
|
context: string;
|
|
|
|
};
|
2023-06-07 03:39:38 +00:00
|
|
|
|
|
|
|
describe( 'findComponentMeta', () => {
|
|
|
|
it( 'should return the whole object once "component" key is found in a nested object', () => {
|
|
|
|
const obj: Record< string, unknown > = {
|
|
|
|
'coreProfiler.skipGuidedSetup.skipFlowBusinessLocation': {
|
|
|
|
component: ( props: ComponentProps ) => (
|
|
|
|
<div>{ props.context }</div>
|
|
|
|
),
|
|
|
|
progress: 50,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = findComponentMeta( obj );
|
|
|
|
expect( result ).toEqual( {
|
|
|
|
component: expect.any( Function ),
|
|
|
|
progress: 50,
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return undefined if no "component" key is present', () => {
|
|
|
|
const obj: Record< string, unknown > = {
|
|
|
|
a: 1,
|
|
|
|
b: {
|
|
|
|
key: 'value',
|
|
|
|
},
|
|
|
|
c: 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = findComponentMeta( obj );
|
|
|
|
expect( result ).toBeUndefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should handle deeply nested objects', () => {
|
|
|
|
const obj: Record< string, unknown > = {
|
|
|
|
a: 1,
|
|
|
|
b: {
|
|
|
|
key: 'value',
|
|
|
|
nested: {
|
|
|
|
anotherKey: 'anotherValue',
|
|
|
|
component: ( props: ComponentProps ) => (
|
|
|
|
<div>{ props.context }</div>
|
|
|
|
),
|
|
|
|
progress: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
c: 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
const result = findComponentMeta( obj );
|
|
|
|
expect( result ).toEqual( {
|
|
|
|
anotherKey: 'anotherValue',
|
|
|
|
component: expect.any( Function ),
|
|
|
|
progress: 100,
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|