Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Toggle unit test: unmount synchronously to cancel popover positioning #45726

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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();
} );
} );
} );