@wordpress/e2e-test-utils
Version:
End-To-End (E2E) test utils for WordPress.
25 lines (24 loc) • 933 B
JavaScript
/**
* Internal dependencies
*/
import { showBlockToolbar } from './show-block-toolbar';
/**
* Clicks a block toolbar button.
*
* @param {string} label The text string of the button label.
* @param {string} [type] The type of button label: 'ariaLabel' or 'content'.
*/
export async function clickBlockToolbarButton(label, type = 'ariaLabel') {
await showBlockToolbar();
const BLOCK_TOOLBAR_SELECTOR = 'block-editor-block-toolbar';
let button;
if (type === 'ariaLabel') {
button = await page.waitForSelector(`.${BLOCK_TOOLBAR_SELECTOR} button[aria-label="${label}"]`);
}
if (type === 'content') {
button = await page.waitForXPath(`//*[contains(concat(' ', normalize-space(@class), ' '), ' ${BLOCK_TOOLBAR_SELECTOR} ')]//button[contains(text(), '${label}')]`);
}
await button.evaluate(element => element.scrollIntoView());
await button.click();
}
//# sourceMappingURL=click-block-toolbar-button.js.map