Skip to content

Commit

Permalink
Adjust test.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Apr 15, 2024
1 parent b42f4b3 commit b5e3604
Showing 1 changed file with 22 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const classicMenusFixture = [

describe( 'NavigationMenuSelector', () => {
describe( 'Toggle', () => {
it( 'should show dropdown toggle with loading message when menus have not resolved', async () => {
it( 'should show paragraph with loading message when menus have not resolved', async () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: [],
isResolvingNavigationMenus: true,
Expand All @@ -82,14 +82,10 @@ describe( 'NavigationMenuSelector', () => {

render( <NavigationMenuSelector /> );

expect(
screen.getByRole( 'button', {
name: /Loading/,
} )
).toBeInTheDocument();
expect( screen.getByText( /Loading/ ) ).toBeVisible();
} );

it( 'should show correct dropdown toggle prompt to choose a menu when Navigation Menus have resolved', async () => {
it( 'should show correct paragraph message to choose a menu when Navigation Menus have resolved', async () => {
useNavigationMenu.mockReturnValue( {
navigationMenus: [],
hasResolvedNavigationMenus: true,
Expand All @@ -98,12 +94,9 @@ describe( 'NavigationMenuSelector', () => {
} );

render( <NavigationMenuSelector /> );

expect(
screen.getByRole( 'button', {
name: 'Choose or create a Navigation Menu',
} )
).toBeInTheDocument();
screen.getByText( 'Choose or create a Navigation Menu' )
).toBeVisible();
} );
} );

Expand All @@ -126,12 +119,14 @@ describe( 'NavigationMenuSelector', () => {

expect(
screen.getByRole( 'menu', {
name: /Loading/,
name: 'Actions',
} )
).toBeInTheDocument();

// Check that all the option groups are *not* present.
const menusGroup = screen.queryByRole( 'group', { name: 'Menus' } );
const menusGroup = screen.queryByRole( 'group', {
name: 'Available Menus',
} );
expect( menusGroup ).not.toBeInTheDocument();

const classicMenusGroup = screen.queryByRole( 'group', {
Expand Down Expand Up @@ -159,23 +154,22 @@ describe( 'NavigationMenuSelector', () => {
render( <NavigationMenuSelector /> );

const toggleButton = screen.getByRole( 'button', {
name: 'Choose or create a Navigation Menu',
name: 'Actions',
} );

await user.click( toggleButton );
expect(
screen.getByText( 'Choose or create a Navigation Menu' )
).toBeVisible();

const menuPopover = screen.getByRole( 'menu' );
await user.click( toggleButton );

expect( menuPopover ).toHaveAttribute(
'aria-label',
expect.stringContaining(
'Choose or create a Navigation Menu'
)
);
expect(
screen.getByText( 'Choose or create a Navigation Menu' )
).toBeVisible();

// Check that all the option groups are *not* present.
const menusGroup = screen.queryByRole( 'group', {
name: 'Menus',
name: 'Available Menus',
} );
expect( menusGroup ).not.toBeInTheDocument();

Expand Down Expand Up @@ -341,7 +335,7 @@ describe( 'NavigationMenuSelector', () => {
await user.click( toggleButton );

const menusGroup = screen.queryByRole( 'group', {
name: 'Menus',
name: 'Available Menus',
} );
expect( menusGroup ).not.toBeInTheDocument();
} );
Expand All @@ -362,7 +356,7 @@ describe( 'NavigationMenuSelector', () => {
await user.click( toggleButton );

const menusGroup = screen.queryByRole( 'group', {
name: 'Menus',
name: 'Available Menus',
} );
expect( menusGroup ).toBeInTheDocument();

Expand Down Expand Up @@ -401,7 +395,7 @@ describe( 'NavigationMenuSelector', () => {
await user.click( toggleButton );

const menusGroup = screen.queryByRole( 'group', {
name: 'Menus',
name: 'Available Menus',
} );
expect( menusGroup ).toBeInTheDocument();

Expand Down Expand Up @@ -612,7 +606,7 @@ describe( 'NavigationMenuSelector', () => {
// Check the dropdown is open and is in the "loading" state.
expect(
screen.getByRole( 'menu', {
name: /Loading/,
name: 'Actions',
} )
).toBeInTheDocument();

Expand Down Expand Up @@ -642,13 +636,6 @@ describe( 'NavigationMenuSelector', () => {
/>
);

// Todo: fix bug where aria label is not updated.
// expect(
// screen.getByRole( 'menu', {
// name: `You are currently editing ${ classicMenusFixture[ 0 ].name }`,
// } )
// ).toBeInTheDocument();

// Check all menu items are re-enabled.
screen.getAllByRole( 'menuitem' ).forEach( ( item ) => {
// // Check all menu items are present but disabled.
Expand Down

0 comments on commit b5e3604

Please sign in to comment.