Skip to content

Commit

Permalink
Editor: Refactor PostSlug tests to @testing-library/react (#43973)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Sep 8, 2022
1 parent 52bcad9 commit 6d6fe48
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions packages/editor/src/components/post-slug/test/index.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
/**
* External dependencies
*/
import { shallow } from 'enzyme';

/**
* WordPress dependencies
*/
import { TextControl } from '@wordpress/components';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

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

describe( 'PostSlug', () => {
describe( '#render()', () => {
it( 'should update internal slug', () => {
const wrapper = shallow( <PostSlug postSlug="index" /> );

wrapper.find( TextControl ).prop( 'onChange' )( 'single' );

expect( wrapper.state().editedSlug ).toEqual( 'single' );
it( 'should update slug with sanitized input', async () => {
const user = userEvent.setup( {
advanceTimers: jest.advanceTimersByTime,
} );
const onUpdateSlug = jest.fn();

it( 'should update slug', () => {
const onUpdateSlug = jest.fn();
const wrapper = shallow(
<PostSlug postSlug="index" onUpdateSlug={ onUpdateSlug } />
);
render( <PostSlug postSlug="index" onUpdateSlug={ onUpdateSlug } /> );

wrapper.find( TextControl ).prop( 'onBlur' )( {
target: {
value: 'single',
},
} );
const input = screen.getByRole( 'textbox', { name: 'Slug' } );
await user.clear( input );
await user.type( input, 'Foo Bar-Baz 9!' );
input.blur();

expect( onUpdateSlug ).toHaveBeenCalledWith( 'single' );
} );
expect( onUpdateSlug ).toHaveBeenCalledWith( 'foo-bar-baz-9' );
} );
} );

0 comments on commit 6d6fe48

Please sign in to comment.