Skip to content

Commit

Permalink
Block Editor: Refactor BlockModeToggle tests to RTL (#45071)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Oct 19, 2022
1 parent b4d463e commit c1ce510
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
/**
* External dependencies
*/
import ShallowRenderer from 'react-test-renderer/shallow';
import { render, screen } from '@testing-library/react';

/**
* Internal dependencies
*/
import { BlockModeToggle } from '../block-mode-toggle';

describe( 'BlockModeToggle', () => {
function getShallowRenderOutput( element ) {
const renderer = new ShallowRenderer();
renderer.render( element );
return renderer.getRenderOutput();
}

it( "should not render the HTML mode button if the block doesn't support it", () => {
const wrapper = getShallowRenderOutput(
render(
<BlockModeToggle blockType={ { supports: { html: false } } } />
);

expect( wrapper ).toBe( null );
expect(
screen.queryByRole( 'menuitem', { name: 'Edit as HTML' } )
).not.toBeInTheDocument();
} );

it( 'should render the HTML mode button', () => {
const wrapper = getShallowRenderOutput(
render(
<BlockModeToggle
blockType={ { supports: { html: true } } }
mode="visual"
/>
);
const text = wrapper.props.children;

expect( text ).toEqual( 'Edit as HTML' );
expect(
screen.getByRole( 'menuitem', { name: 'Edit as HTML' } )
).toBeVisible();
} );

it( 'should render the Visual mode button', () => {
const wrapper = getShallowRenderOutput(
render(
<BlockModeToggle
blockType={ { supports: { html: true } } }
mode="html"
/>
);
const text = wrapper.props.children;

expect( text ).toEqual( 'Edit visually' );
expect(
screen.getByRole( 'menuitem', { name: 'Edit visually' } )
).toBeVisible();
} );

it( 'should not render the Visual mode button if code editing is disabled', () => {
const wrapper = getShallowRenderOutput(
render(
<BlockModeToggle
blockType={ { supports: { html: true } } }
mode="html"
isCodeEditingEnabled={ false }
/>
);

expect( wrapper ).toBe( null );
expect(
screen.queryByRole( 'menuitem', { name: 'Edit visually' } )
).not.toBeInTheDocument();
} );
} );

0 comments on commit c1ce510

Please sign in to comment.