From 0fcb3fbfad7dac9e87683779b4902ce12d08f3ea Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Fri, 2 Sep 2022 15:49:04 +0300 Subject: [PATCH] Block Editor: Refactor Warning tests to @testing-library/react --- .../warning/test/__snapshots__/index.js.snap | 25 ++++---- .../src/components/warning/test/index.js | 61 ++++++++++--------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/packages/block-editor/src/components/warning/test/__snapshots__/index.js.snap b/packages/block-editor/src/components/warning/test/__snapshots__/index.js.snap index dae4cd686b3c64..dbaba10e18efe6 100644 --- a/packages/block-editor/src/components/warning/test/__snapshots__/index.js.snap +++ b/packages/block-editor/src/components/warning/test/__snapshots__/index.js.snap @@ -1,25 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Warning should match snapshot 1`] = ` -
+
-

- error -

+

+ error +

+
diff --git a/packages/block-editor/src/components/warning/test/index.js b/packages/block-editor/src/components/warning/test/index.js index d829a5b931fad1..88c9006b8ace9d 100644 --- a/packages/block-editor/src/components/warning/test/index.js +++ b/packages/block-editor/src/components/warning/test/index.js @@ -1,7 +1,8 @@ /** * External dependencies */ -import { shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; /** * Internal dependencies @@ -10,47 +11,49 @@ import Warning from '../index'; describe( 'Warning', () => { it( 'should match snapshot', () => { - const wrapper = shallow( error ); + const { container } = render( error ); - expect( wrapper ).toMatchSnapshot(); + expect( container ).toMatchSnapshot(); } ); - it( 'should have valid class', () => { - const wrapper = shallow( ); - - expect( wrapper.find( '.block-editor-warning' ) ).toHaveLength( 1 ); - expect( wrapper.find( '.block-editor-warning__actions' ) ).toHaveLength( - 0 - ); - expect( wrapper.find( '.block-editor-warning__hidden' ) ).toHaveLength( - 0 - ); - } ); - - it( 'should show child error message element', () => { - const wrapper = shallow( - }>Message + it( 'should show primary actions', () => { + render( + Click me }>Message ); - const actions = wrapper.find( '.block-editor-warning__actions' ); - const action = actions.childAt( 0 ); + expect( + screen.getByRole( 'button', { name: 'Click me' } ) + ).toBeVisible(); - expect( actions ).toHaveLength( 1 ); - expect( action.hasClass( 'block-editor-warning__action' ) ).toBe( - true - ); - expect( action.childAt( 0 ).type() ).toBe( 'button' ); + expect( + screen.queryByRole( 'button', { name: 'More options' } ) + ).not.toBeInTheDocument(); } ); - it( 'should show hidden actions', () => { - const wrapper = shallow( + it( 'should show hidden secondary actions', async () => { + const user = userEvent.setup( { + advanceTimers: jest.advanceTimersByTime, + } ); + + render( Message ); - const actions = wrapper.find( '.block-editor-warning__secondary' ); + const secondaryActionsBtn = screen.getByRole( 'button', { + name: 'More options', + } ); + + expect( secondaryActionsBtn ).toBeVisible(); + expect( + screen.queryByRole( 'menuitem', { name: 'test' } ) + ).not.toBeInTheDocument(); + + await user.click( secondaryActionsBtn ); - expect( actions ).toHaveLength( 1 ); + expect( + screen.getByRole( 'menuitem', { name: 'test' } ) + ).toBeInTheDocument(); } ); } );