Skip to content

Commit

Permalink
Add wpDataSelect WordPress end 2 end test util
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Apr 19, 2019
1 parent 5f793fb commit 748f17a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
11 changes: 7 additions & 4 deletions packages/e2e-test-utils/src/are-pre-publish-checks-enabled.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/**
* Internal dependencies
*/
import { wpDataSelect } from './wp-data-select';

/**
* Verifies if publish checks are enabled.
* @return {boolean} Boolean which represents the state of prepublish checks.
*/
export async function arePrePublishChecksEnabled() {
return page.evaluate( () =>
window.wp.data.select( 'core/editor' ).isPublishSidebarEnabled()
);
export function arePrePublishChecksEnabled() {
return wpDataSelect( 'core/editor', 'isPublishSidebarEnabled' );
}
12 changes: 7 additions & 5 deletions packages/e2e-test-utils/src/get-all-blocks.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/**
* Internal dependencies
*/
import { wpDataSelect } from './wp-data-select';

/**
* Returns an array with all blocks; Equivalent to calling wp.data.select( 'core/editor' ).getBlocks();
*
* @return {Promise} Promise resolving with an array containing all blocks in the document.
*/
export async function getAllBlocks() {
return await page.evaluate( () => {
const { select } = window.wp.data;
return select( 'core/editor' ).getBlocks();
} );
export function getAllBlocks() {
return wpDataSelect( 'core/editor', 'getBlocks' );
}
9 changes: 6 additions & 3 deletions packages/e2e-test-utils/src/get-edited-post-content.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
* Internal dependencies
*/
import { wpDataSelect } from './wp-data-select';

/**
* Returns a promise which resolves with the edited post content (HTML string).
*
* @return {Promise} Promise resolving with post content markup.
*/
export async function getEditedPostContent() {
return await page.evaluate( () => {
return window.wp.data.select( 'core/editor' ).getEditedPostContent();
} );
return wpDataSelect( 'core/editor', 'getEditedPostContent' );
}
18 changes: 18 additions & 0 deletions packages/e2e-test-utils/src/wp-data-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Queries the wordpress data module.
* @param {string} store Store to query e.g: core/editor, core/blocks...
* @param {string} selector Selector to exectute e.g: getBlocks.
* @param {...Object} parameters Parameters to pass to the selector.
*
* @return {?Object} Result of querying.
*/
export function wpDataSelect( store, selector, ...parameters ) {
return page.evaluate(
( _store, _selector, ..._parameters ) => {
return window.wp.data.select( _store )[ _selector ]( ..._parameters );
},
store,
selector,
parameters
);
}

0 comments on commit 748f17a

Please sign in to comment.