Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Jun 22, 2020
1 parent ba4eaf9 commit 40846c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
9 changes: 6 additions & 3 deletions packages/block-library/src/navigation/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,12 @@ function NavigationPlaceholder( { onCreate }, ref ) {
>
<>
<CustomSelectControl
className={ classnames( {
'has-menus': hasMenus,
} ) }
className={ classnames(
'wp-block-navigation-placeholder__select-control',
{
'has-menus': hasMenus,
}
) }
label={
! isLoading
? getPlaceholderInstructions(
Expand Down
49 changes: 20 additions & 29 deletions packages/e2e-tests/specs/experiments/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,12 @@ async function updateActiveNavigationLink( { url, label, type } ) {
}

async function selectDropDownOption( optionText ) {
const buttonText = 'Select where to start from…';
await page.waitForXPath(
`//button[text()="${ buttonText }"][not(@disabled)]`
await page.waitForSelector(
'.wp-block-navigation-placeholder__select-control button'
);
const [ dropdownToggle ] = await page.$x(
`//button[text()="${ buttonText }"][not(@disabled)]`
await page.click(
'.wp-block-navigation-placeholder__select-control button'
);
await dropdownToggle.click();

const [ theOption ] = await page.$x( `//li[text()="${ optionText }"]` );

Expand All @@ -248,7 +246,7 @@ async function clickCreateButton() {
}

async function createEmptyNavBlock() {
await selectDropDownOption( 'Create empty menu' );
await selectDropDownOption( 'Create empty Navigation' );
await clickCreateButton();
}

Expand Down Expand Up @@ -282,7 +280,7 @@ describe( 'Navigation', () => {
// Add the navigation block.
await insertBlock( 'Navigation' );

await selectDropDownOption( 'New from all top-level pages' );
await selectDropDownOption( 'Create from all top-level pages' );

await clickCreateButton();

Expand All @@ -297,27 +295,23 @@ describe( 'Navigation', () => {
// Add the navigation block.
await insertBlock( 'Navigation' );

const dropdownButtonText = 'Select where to start from…';
await page.waitForXPath(
`//button[text()="${ dropdownButtonText }"][not(@disabled)]`
await page.waitForSelector(
'.wp-block-navigation-placeholder__select-control button'
);
const [ dropdownToggle ] = await page.$x(
`//button[text()="${ dropdownButtonText }"][not(@disabled)]`
await page.click(
'.wp-block-navigation-placeholder__select-control button'
);

await dropdownToggle.click();

const dropDownItemsLength = await page.$$eval(
'ul[role="listbox"] li[role="option"]',
( els ) => els.length
);

// Should only be showing
// 1. Placeholder value.
// 2. Create empty menu.
expect( dropDownItemsLength ).toEqual( 2 );
// 1. Create empty menu.
expect( dropDownItemsLength ).toEqual( 1 );

await page.waitForXPath( '//li[text()="Create empty menu"]' );
await page.waitForXPath( '//li[text()="Create empty Navigation"]' );

// Snapshot should contain the mocked menu items.
expect( await getEditedPostContent() ).toMatchSnapshot();
Expand Down Expand Up @@ -385,26 +379,23 @@ describe( 'Navigation', () => {
// Add the navigation block.
await insertBlock( 'Navigation' );

const dropdownButtonText = 'Select where to start from…';
await page.waitForXPath(
`//button[text()="${ dropdownButtonText }"][not(@disabled)]`
await page.waitForSelector(
'.wp-block-navigation-placeholder__select-control button'
);
const [ dropdownToggle ] = await page.$x(
`//button[text()="${ dropdownButtonText }"][not(@disabled)]`
await page.click(
'.wp-block-navigation-placeholder__select-control button'
);
await dropdownToggle.click();

const dropDownItemsLength = await page.$$eval(
'ul[role="listbox"] li[role="option"]',
( els ) => els.length
);

// Should only be showing
// 1. Placeholder.
// 2. Create from Empty.
expect( dropDownItemsLength ).toEqual( 2 );
// 1. Create empty menu.
expect( dropDownItemsLength ).toEqual( 1 );

await page.waitForXPath( '//li[text()="Create empty menu"]' );
await page.waitForXPath( '//li[text()="Create empty Navigation"]' );

// Snapshot should contain the mocked menu items.
expect( await getEditedPostContent() ).toMatchSnapshot();
Expand Down

0 comments on commit 40846c1

Please sign in to comment.