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

Make the block grouping test more stable #23266

Merged
merged 1 commit into from
Jun 18, 2020
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
17 changes: 10 additions & 7 deletions packages/e2e-test-utils/src/click-block-toolbar-button.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/**
* Internal dependencies
*/
import { showBlockToolbar } from './show-block-toolbar';

/**
* Clicks a block toolbar button.
*
* @param {string} buttonAriaLabel The aria label of the button to click.
*/
export async function clickBlockToolbarButton( buttonAriaLabel ) {
await showBlockToolbar();

const BLOCK_TOOLBAR_SELECTOR = '.block-editor-block-toolbar';
const BUTTON_SELECTOR = `${ BLOCK_TOOLBAR_SELECTOR } button[aria-label="${ buttonAriaLabel }"]`;
if ( ( await page.$( BLOCK_TOOLBAR_SELECTOR ) ) === null ) {
// Move the mouse to show the block toolbar
await page.mouse.move( 0, 0 );
await page.mouse.move( 10, 10 );
}

// Hover the block switcher to show the movers
const switcher = await page.$(
Expand All @@ -20,6 +22,7 @@ export async function clickBlockToolbarButton( buttonAriaLabel ) {
await switcher.hover();
}

await page.waitForSelector( BUTTON_SELECTOR );
await page.click( BUTTON_SELECTOR );
const button = await page.waitForSelector( BUTTON_SELECTOR );
await button.evaluate( ( element ) => element.scrollIntoView() );
await button.click();
}
5 changes: 5 additions & 0 deletions packages/e2e-test-utils/src/show-block-toolbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function showBlockToolbar() {
// Move the mouse to disable the isTyping mode
await page.mouse.move( 50, 50 );
await page.mouse.move( 100, 100 );
}
9 changes: 7 additions & 2 deletions packages/e2e-test-utils/src/transform-block-to.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/**
* Internal dependencies
*/
import { showBlockToolbar } from './show-block-toolbar';

/**
* Converts editor's block type.
*
* @param {string} name Block name.
*/
export async function transformBlockTo( name ) {
await page.mouse.move( 0, 0 );
await page.mouse.move( 10, 10 );
await showBlockToolbar();

const switcherToggle = await page.waitForSelector(
'.block-editor-block-switcher__toggle'
);
Expand Down
18 changes: 14 additions & 4 deletions packages/e2e-tests/specs/editor/various/block-grouping.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,24 @@ describe( 'Block Grouping', () => {
// Full width image.
await insertBlock( 'Image' );
await clickBlockToolbarButton( 'Change alignment' );
const FULL_WIDTH_BUTTON_XPATH = `//button[contains(@class,'components-dropdown-menu__menu-item') and contains(text(), 'Full width')]`;
await ( await page.$x( FULL_WIDTH_BUTTON_XPATH ) )[ 0 ].click();
const fullButton = await page.waitForXPath(
`//button[contains(@class,'components-dropdown-menu__menu-item') and contains(text(), 'Full width')]`
);
await fullButton.evaluate( ( element ) =>
element.scrollIntoView()
);
await fullButton.click();

// Wide width image.
await insertBlock( 'Image' );
await clickBlockToolbarButton( 'Change alignment' );
const WIDE_BUTTON_XPATH = `//button[contains(@class,'components-dropdown-menu__menu-item') and contains(text(), 'Wide width')]`;
await ( await page.$x( WIDE_BUTTON_XPATH ) )[ 0 ].click();
const wideButton = await page.waitForXPath(
`//button[contains(@class,'components-dropdown-menu__menu-item') and contains(text(), 'Wide width')]`
);
await wideButton.evaluate( ( element ) =>
element.scrollIntoView()
);
await wideButton.click();

await insertBlock( 'Paragraph' );
await page.keyboard.type( 'Some paragraph' );
Expand Down