Skip to content

Commit

Permalink
Simplify toggleMoreMenu and clickOnMoreMenuItem e2e utils
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Mar 3, 2022
1 parent 0d04d86 commit 6088be3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 46 deletions.
4 changes: 4 additions & 0 deletions packages/e2e-test-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancement

- The `toggleMoreMenu` and `clickMoreMenuItem` utilities no longer require a second 'context' parameter.

## 6.0.0 (2022-01-27)

### Breaking Changes
Expand Down
2 changes: 0 additions & 2 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ Clicks on More Menu item, searches for the button with the text provided and cli
_Parameters_

- _buttonLabel_ `string`: The label to search the button for.
- _context_ `[GutenbergContext]`: Whether to click the button in the post editor or site editor context.

### clickSiteEditorMenuItem

Expand Down Expand Up @@ -832,7 +831,6 @@ Toggles the More Menu.
_Parameters_

- _waitFor_ `['open' | 'close']`: Whether it should wait for the menu to open or close. If `undefined` it won't wait for anything.
- _context_ `[GutenbergContext]`: Whether it's toggling in the context of the site editor or post editor.

### toggleOfflineMode

Expand Down
25 changes: 4 additions & 21 deletions packages/e2e-test-utils/src/click-on-more-menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,15 @@ import { first } from 'lodash';
*/
import { toggleMoreMenu } from './toggle-more-menu';

/**
* @typedef {import("./shared/types").GutenbergContext} GutenbergContext
*/

const SELECTORS = {
postEditorMenuContainer:
'//*[contains(concat(" ", @class, " "), " interface-more-menu-dropdown__content ")]',
siteEditorMenuContainer:
'//*[contains(concat(" ", @class, " "), " edit-site-more-menu__content ")]',
};

/**
* Clicks on More Menu item, searches for the button with the text provided and clicks it.
*
* @param {string} buttonLabel The label to search the button for.
* @param {GutenbergContext} [context='post-editor'] Whether to click the button in the post editor or site editor context.
* @param {string} buttonLabel The label to search the button for.
*/
export async function clickOnMoreMenuItem(
buttonLabel,
context = 'post-editor'
) {
await toggleMoreMenu( 'open', context );
export async function clickOnMoreMenuItem( buttonLabel ) {
await toggleMoreMenu( 'open' );
const moreMenuContainerSelector =
context === 'post-editor'
? SELECTORS.postEditorMenuContainer
: SELECTORS.siteEditorMenuContainer;
'//*[contains(concat(" ", @class, " "), " interface-more-menu-dropdown__content ")]';

const elementToClick = first(
await page.$x(
Expand Down
27 changes: 4 additions & 23 deletions packages/e2e-test-utils/src/toggle-more-menu.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
/**
* @typedef {import("./shared/types").GutenbergContext} GutenbergContext
*/

const SELECTORS = {
postEditorMenuContent: '.interface-more-menu-dropdown__content',
siteEditorMenuContent: '.edit-site-more-menu__content',
postEditorMenu: '.interface-more-menu-dropdown [aria-label="Options"]',
siteEditorMenu: '.edit-site-more-menu [aria-label="More tools & options"]',
};

/**
* Toggles the More Menu.
*
* @param {'open' | 'close'} [waitFor] Whether it should wait for the menu to open or close. If `undefined` it won't wait for anything.
* @param {GutenbergContext} [context='post-editor'] Whether it's toggling in the context of the site editor or post editor.
* @param {'open' | 'close'} [waitFor] Whether it should wait for the menu to open or close. If `undefined` it won't wait for anything.
*/
export async function toggleMoreMenu( waitFor, context = 'post-editor' ) {
const menuSelector =
context === 'post-editor'
? SELECTORS.postEditorMenu
: SELECTORS.siteEditorMenu;
export async function toggleMoreMenu( waitFor ) {
const menuSelector = '.interface-more-menu-dropdown [aria-label="Options"]';

await page.click( menuSelector );

if ( waitFor ) {
const opts = waitFor === 'close' ? { hidden: true } : {};
const menuContentSelector =
context === 'post-editor'
? SELECTORS.postEditorMenuContent
: SELECTORS.siteEditorMenuContent;

const menuContentSelector = '.interface-more-menu-dropdown__content';
await page.waitForSelector( menuContentSelector, opts );
}
}

0 comments on commit 6088be3

Please sign in to comment.