Skip to content

Commit

Permalink
Navigation Toggle unit test: unmount synchronously to cancel popover …
Browse files Browse the repository at this point in the history
…positioning (#45726)
  • Loading branch information
jsnajdr authored Nov 13, 2022
1 parent 4394e9b commit f463286
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 65 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,51 @@ import NavigationToggle from '..';

jest.mock( '@wordpress/data/src/components/use-select', () => {
// This allows us to tweak the returned value on each test.
const mock = jest.fn();
return mock;
return jest.fn();
} );
jest.mock( '@wordpress/data/src/components/use-dispatch', () => ( {
useDispatch: () => ( { setNavigationPanelActiveMenu: jest.fn() } ),
} ) );

jest.mock( '@wordpress/core-data' );

describe( 'NavigationToggle', () => {
describe( 'when in full screen mode', () => {
it( 'should display a user uploaded site icon if it exists', () => {
useSelect.mockImplementation( ( cb ) => {
return cb( () => ( {
getCurrentTemplateNavigationPanelSubMenu: () => 'root',
useSelect.mockImplementation( ( cb ) =>
cb( () => ( {
getEntityRecord: () => ( {
site_icon_url: 'https://fakeUrl.com',
} ),
isResolving: () => false,
isNavigationOpened: () => false,
} ) );
} );
} ) )
);

render( <NavigationToggle /> );
const { unmount } = render( <NavigationToggle /> );

const siteIcon = screen.getByAltText( 'Site Icon' );

expect( siteIcon ).toBeVisible();

// Unmount the UI synchronously so that any async effects, like the on-mount focus
// that shows and positions a tooltip, are cancelled right away and never run.
unmount();
} );

it( 'should display a default site icon if no user uploaded site icon exists', () => {
useSelect.mockImplementation( ( cb ) => {
return cb( () => ( {
getCurrentTemplateNavigationPanelSubMenu: () => 'root',
useSelect.mockImplementation( ( cb ) =>
cb( () => ( {
getEntityRecord: () => ( {
site_icon_url: '',
} ),
isResolving: () => false,
isNavigationOpened: () => false,
} ) );
} );
} ) )
);

const { container } = render( <NavigationToggle /> );
const { unmount } = render( <NavigationToggle /> );

expect(
screen.queryByAltText( 'Site Icon' )
).not.toBeInTheDocument();
const siteIcon = screen.queryByAltText( 'Site Icon' );
expect( siteIcon ).not.toBeInTheDocument();

expect( container ).toMatchSnapshot();
// Unmount the UI synchronously so that any async effects, like the on-mount focus
// that shows and positions a tooltip, are cancelled right away and never run.
unmount();
} );
} );
} );

0 comments on commit f463286

Please sign in to comment.