Skip to content

Commit

Permalink
Editor: Refactor ThemeSupportCheck tests to @testing-library/react (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Aug 24, 2022
1 parent e9b4be2 commit 69d8360
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/editor/src/components/theme-support-check/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { shallow } from 'enzyme';
import { render, screen } from '@testing-library/react';

/**
* Internal dependencies
Expand All @@ -10,34 +10,32 @@ import { ThemeSupportCheck } from '../index';

describe( 'ThemeSupportCheck', () => {
it( "should not render if there's no support check provided", () => {
const wrapper = shallow(
<ThemeSupportCheck>foobar</ThemeSupportCheck>
);
expect( wrapper.type() ).toBe( null );
render( <ThemeSupportCheck>foobar</ThemeSupportCheck> );
expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
} );

it( 'should render if post-thumbnails are supported', () => {
const themeSupports = {
'post-thumbnails': true,
};
const supportKeys = 'post-thumbnails';
const wrapper = shallow(
render(
<ThemeSupportCheck
supportKeys={ supportKeys }
themeSupports={ themeSupports }
>
foobar
</ThemeSupportCheck>
);
expect( wrapper.type() ).not.toBe( null );
expect( screen.getByText( 'foobar' ) ).toBeVisible();
} );

it( 'should render if post-thumbnails are supported for the post type', () => {
const themeSupports = {
'post-thumbnails': [ 'post' ],
};
const supportKeys = 'post-thumbnails';
const wrapper = shallow(
render(
<ThemeSupportCheck
supportKeys={ supportKeys }
postType={ 'post' }
Expand All @@ -46,15 +44,15 @@ describe( 'ThemeSupportCheck', () => {
foobar
</ThemeSupportCheck>
);
expect( wrapper.type() ).not.toBe( null );
expect( screen.getByText( 'foobar' ) ).toBeVisible();
} );

it( "should not render if post-thumbnails aren't supported for the post type", () => {
const themeSupports = {
'post-thumbnails': [ 'post' ],
};
const supportKeys = 'post-thumbnails';
const wrapper = shallow(
render(
<ThemeSupportCheck
supportKeys={ supportKeys }
postType={ 'page' }
Expand All @@ -63,15 +61,15 @@ describe( 'ThemeSupportCheck', () => {
foobar
</ThemeSupportCheck>
);
expect( wrapper.type() ).toBe( null );
expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
} );

it( 'should not render if post-thumbnails is limited and false is passed for postType', () => {
const themeSupports = {
'post-thumbnails': [ 'post' ],
};
const supportKeys = 'post-thumbnails';
const wrapper = shallow(
render(
<ThemeSupportCheck
supportKeys={ supportKeys }
postType={ false }
Expand All @@ -80,22 +78,22 @@ describe( 'ThemeSupportCheck', () => {
foobar
</ThemeSupportCheck>
);
expect( wrapper.type() ).toBe( null );
expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
} );

it( "should not render if theme doesn't support post-thumbnails", () => {
const themeSupports = {
'post-thumbnails': false,
};
const supportKeys = 'post-thumbnails';
const wrapper = shallow(
render(
<ThemeSupportCheck
supportKeys={ supportKeys }
themeSupports={ themeSupports }
>
foobar
</ThemeSupportCheck>
);
expect( wrapper.type() ).toBe( null );
expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
} );
} );

0 comments on commit 69d8360

Please sign in to comment.