-
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.
Block Editor: Refactor BlockModeToggle tests to RTL (#45071)
- Loading branch information
Showing
1 changed file
with
17 additions
and
17 deletions.
There are no files selected for viewing
34 changes: 17 additions & 17 deletions
34
packages/block-editor/src/components/block-settings-menu/test/block-mode-toggle.js
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 |
---|---|---|
@@ -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(); | ||
} ); | ||
} ); |