Skip to content
Closed
Prev Previous commit
Next Next commit
Update unit tests
  • Loading branch information
noisysocks committed Jul 14, 2022
commit 32d49ebe31aea513116f2e944c67b65c39aaf84a
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,7 @@ exports[`EditPostPreferencesModal should match snapshot when the modal is active
<WithSelect(PostTaxonomies)
taxonomyWrapper={[Function]}
/>
<PostFeaturedImageCheck>
<WithSelect(IfCondition(WithDispatch(BaseOption)))
label="Featured image"
panelName="featured-image"
/>
</PostFeaturedImageCheck>
<PostExcerptCheck>
<WithSelect(IfCondition(WithDispatch(BaseOption)))
label="Excerpt"
panelName="post-excerpt"
/>
</PostExcerptCheck>
<WithSelect(PostTypeSupportCheck)
<PostTypeSupportCheck
supportKeys={
Array [
"comments",
Expand All @@ -118,7 +106,7 @@ exports[`EditPostPreferencesModal should match snapshot when the modal is active
label="Discussion"
panelName="discussion-panel"
/>
</WithSelect(PostTypeSupportCheck)>
</PostTypeSupportCheck>
<PageAttributesCheck>
<WithSelect(IfCondition(WithDispatch(BaseOption)))
label="Page attributes"
Expand Down Expand Up @@ -225,19 +213,7 @@ exports[`EditPostPreferencesModal should match snapshot when the modal is active
<WithSelect(PostTaxonomies)
taxonomyWrapper={[Function]}
/>
<PostFeaturedImageCheck>
<WithSelect(IfCondition(WithDispatch(BaseOption)))
label="Featured image"
panelName="featured-image"
/>
</PostFeaturedImageCheck>
<PostExcerptCheck>
<WithSelect(IfCondition(WithDispatch(BaseOption)))
label="Excerpt"
panelName="post-excerpt"
/>
</PostExcerptCheck>
<WithSelect(PostTypeSupportCheck)
<PostTypeSupportCheck
supportKeys={
Array [
"comments",
Expand All @@ -249,7 +225,7 @@ exports[`EditPostPreferencesModal should match snapshot when the modal is active
label="Discussion"
panelName="discussion-panel"
/>
</WithSelect(PostTypeSupportCheck)>
</PostTypeSupportCheck>
<PageAttributesCheck>
<WithSelect(IfCondition(WithDispatch(BaseOption)))
label="Page attributes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,111 @@
*/
import { create } from 'react-test-renderer';

/**
* WordPress dependencies
*/
import { createRegistry, RegistryProvider } from '@wordpress/data';

/**
* Internal dependencies
*/
import { PostTypeSupportCheck } from '../';
import PostTypeSupportCheck from '../';

function createMockRegistry( postType ) {
return createRegistry( {
'core/editor': {
selectors: {
getEditedPostAttribute: () => 'post',
},
reducer: ( state = {} ) => state,
},
core: {
selectors: {
getPostType: () => postType,
},
reducer: ( state = {} ) => state,
},
} );
}

describe( 'PostTypeSupportCheck', () => {
it( 'renders its children when post type is not known', () => {
let postType;
const registry = createMockRegistry( null );

const tree = create(
<PostTypeSupportCheck postType={ postType } supportKeys="title">
Supported
</PostTypeSupportCheck>
<RegistryProvider value={ registry }>
<PostTypeSupportCheck supportKeys="title">
Supported
</PostTypeSupportCheck>
</RegistryProvider>
);

expect( tree.toJSON() ).toBe( 'Supported' );
} );

it( 'does not render its children when post type is known and not supports', () => {
const postType = {
const registry = createMockRegistry( {
supports: {},
};
} );

const tree = create(
<PostTypeSupportCheck postType={ postType } supportKeys="title">
Supported
</PostTypeSupportCheck>
<RegistryProvider value={ registry }>
<PostTypeSupportCheck supportKeys="title">
Supported
</PostTypeSupportCheck>
</RegistryProvider>
);

expect( tree.toJSON() ).toBe( null );
} );

it( 'renders its children when post type is known and supports', () => {
const postType = {
const registry = createMockRegistry( {
supports: {
title: true,
},
};
} );

const tree = create(
<PostTypeSupportCheck postType={ postType } supportKeys="title">
Supported
</PostTypeSupportCheck>
<RegistryProvider value={ registry }>
<PostTypeSupportCheck supportKeys="title">
Supported
</PostTypeSupportCheck>
</RegistryProvider>
);

expect( tree.toJSON() ).toBe( 'Supported' );
} );

it( 'renders its children if some of keys supported', () => {
const postType = {
const registry = createMockRegistry( {
supports: {
title: true,
},
};
} );

const tree = create(
<PostTypeSupportCheck
postType={ postType }
supportKeys={ [ 'title', 'thumbnail' ] }
>
Supported
</PostTypeSupportCheck>
<RegistryProvider value={ registry }>
<PostTypeSupportCheck supportKeys={ [ 'title', 'thumbnail' ] }>
Supported
</PostTypeSupportCheck>
</RegistryProvider>
);

expect( tree.toJSON() ).toBe( 'Supported' );
} );

it( 'does not render its children if none of keys supported', () => {
const postType = {
const registry = createMockRegistry( {
supports: {},
};
} );

const tree = create(
<PostTypeSupportCheck
postType={ postType }
supportKeys={ [ 'title', 'thumbnail' ] }
>
Supported
</PostTypeSupportCheck>
<RegistryProvider value={ registry }>
<PostTypeSupportCheck supportKeys={ [ 'title', 'thumbnail' ] }>
Supported
</PostTypeSupportCheck>
</RegistryProvider>
);

expect( tree.toJSON() ).toBe( null );
Expand Down