-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wpDataSelect WordPress end 2 end test util
- Loading branch information
1 parent
5f793fb
commit 748f17a
Showing
4 changed files
with
38 additions
and
12 deletions.
There are no files selected for viewing
11 changes: 7 additions & 4 deletions
11
packages/e2e-test-utils/src/are-pre-publish-checks-enabled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |