Skip to content

Commit

Permalink
Refactor findSidebarPanelWithTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jan 21, 2019
1 parent e0ce974 commit 21de46b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* External dependencies
*/
import { first } from 'lodash';

/**
* Finds a sidebar panel with the provided title.
*
* @param {string} panelTitle The name of sidebar panel.
*
* @return {?ElementHandle} Object that represents an in-page DOM element.
*/
export async function findSidebarPanelToggleButtonWithTitle( panelTitle ) {
return first( await page.$x( `//div[@class="edit-post-sidebar"]//button[@class="components-button components-panel__body-toggle"][contains(text(),"${ panelTitle }")]` ) );
}
5 changes: 4 additions & 1 deletion packages/e2e-test-utils/src/find-sidebar-panel-with-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ import { first } from 'lodash';
* @return {?ElementHandle} Object that represents an in-page DOM element.
*/
export async function findSidebarPanelWithTitle( panelTitle ) {
return first( await page.$x( `//div[@class="edit-post-sidebar"]//button[@class="components-button components-panel__body-toggle"][contains(text(),"${ panelTitle }")]` ) );
const classSelect = ( className ) => `[contains(concat(" ", @class, " "), " ${ className } ")]`;
const buttonSelector = `//div${ classSelect( 'edit-post-sidebar' ) }//button${ classSelect( 'components-button' ) }${ classSelect( 'components-panel__body-toggle' ) }[contains(text(),"${ panelTitle }")]`;
const panelSelector = `${ buttonSelector }/ancestor::*[contains(concat(" ", @class, " "), " components-panel__body ")]`;
return first( await await page.$x( panelSelector ) );
}
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { disablePrePublishChecks } from './disable-pre-publish-checks';
export { enablePageDialogAccept } from './enable-page-dialog-accept';
export { enablePrePublishChecks } from './enable-pre-publish-checks';
export { ensureSidebarOpened } from './ensure-sidebar-opened';
export { findSidebarPanelToggleButtonWithTitle } from './find-sidebar-panel-toggle-button-with-title';
export { findSidebarPanelWithTitle } from './find-sidebar-panel-with-title';
export { getAllBlocks } from './get-all-blocks';
export { getAvailableBlockTransforms } from './get-available-block-transforms';
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/specs/new-post-default-content.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
activatePlugin,
createNewPost,
deactivatePlugin,
findSidebarPanelWithTitle,
findSidebarPanelToggleButtonWithTitle,
getEditedPostContent,
openDocumentSettingsSidebar,
} from '@wordpress/e2e-test-utils';
Expand Down Expand Up @@ -33,7 +33,7 @@ describe( 'new editor filtered state', () => {

// open the sidebar, we want to see the excerpt.
await openDocumentSettingsSidebar();
const excerptButton = await findSidebarPanelWithTitle( 'Excerpt' );
const excerptButton = await findSidebarPanelToggleButtonWithTitle( 'Excerpt' );
if ( excerptButton ) {
await excerptButton.click( 'button' );
}
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/specs/plugins/meta-boxes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
activatePlugin,
createNewPost,
deactivatePlugin,
findSidebarPanelWithTitle,
findSidebarPanelToggleButtonWithTitle,
insertBlock,
openDocumentSettingsSidebar,
publishPost,
Expand Down Expand Up @@ -98,7 +98,7 @@ describe( 'Meta boxes', () => {

// Open the excerpt panel
await openDocumentSettingsSidebar();
const excerptButton = await findSidebarPanelWithTitle( 'Excerpt' );
const excerptButton = await findSidebarPanelToggleButtonWithTitle( 'Excerpt' );
if ( excerptButton ) {
await excerptButton.click( 'button' );
}
Expand Down
18 changes: 9 additions & 9 deletions packages/e2e-tests/specs/taxonomies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ describe( 'Taxonomies', () => {

const getCurrentTags = async () => {
const tagsPanel = await findSidebarPanelWithTitle( 'Tags' );
return tagsPanel.$eval( '*', ( node ) => {
return Array.from(
node.parentElement.parentElement.parentElement.querySelectorAll(
'.components-form-token-field__token-text span:not(.screen-reader-text)'
)
).map( ( spanNode ) => {
return spanNode.innerText;
return page.evaluate( ( node ) => {
return Array.from( node.querySelectorAll(
'.components-form-token-field__token-text span:not(.screen-reader-text)'
) ).map( ( field ) => {
return field.innerText;
} );
} );
}, tagsPanel );
};

it( 'should be able to open the categories panel and create a new main category if the user has the right capabilities', async () => {
Expand Down Expand Up @@ -113,6 +111,8 @@ describe( 'Taxonomies', () => {
await openDocumentSettingsSidebar();

const tagsPanel = await findSidebarPanelWithTitle( 'Tags' );

//expect( await page.evaluate( ( el ) => el.outerHTML, tagsPanel ) ).toEqual( 'tag1 ok' );
expect( tagsPanel ).toBeDefined();

// If the user has no permission to add a new category finish the test.
Expand All @@ -123,7 +123,7 @@ describe( 'Taxonomies', () => {
// Open the tags panel.
await tagsPanel.click( 'button' );

const tagInput = await page.$( '.components-form-token-field__input' );
const tagInput = await tagsPanel.$( '.components-form-token-field__input' );

// Click the tag input field.
await tagInput.click();
Expand Down

0 comments on commit 21de46b

Please sign in to comment.