2019-08-27 12:22:24 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
const flows = require( './flows' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click a tab (on post type edit screen).
|
|
|
|
*
|
|
|
|
* @param {string} tabName Tab label.
|
|
|
|
*/
|
|
|
|
const clickTab = async ( tabName ) => {
|
|
|
|
await expect( page ).toClick( '.wc-tabs > li > a', { text: tabName } );
|
|
|
|
};
|
|
|
|
|
2019-08-30 11:03:57 +00:00
|
|
|
/**
|
|
|
|
* Save changes on a WooCommerce settings page.
|
|
|
|
*/
|
|
|
|
const settingsPageSaveChanges = async () => {
|
|
|
|
await page.focus( 'button.woocommerce-save-button' );
|
|
|
|
await Promise.all( [
|
|
|
|
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
|
|
|
page.click( 'button.woocommerce-save-button' ),
|
|
|
|
] );
|
|
|
|
};
|
|
|
|
|
2019-09-04 12:12:37 +00:00
|
|
|
/**
|
|
|
|
* Set checkbox.
|
|
|
|
*
|
|
|
|
* @param {string} selector
|
|
|
|
*/
|
|
|
|
const setCheckbox = async( selector ) => {
|
|
|
|
await page.focus( selector );
|
|
|
|
const checkbox = await page.$( selector );
|
|
|
|
const checkboxStatus = ( await ( await checkbox.getProperty( 'checked' ) ).jsonValue() );
|
|
|
|
if ( checkboxStatus !== true ) {
|
|
|
|
await page.click( selector );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unset checkbox.
|
|
|
|
*
|
|
|
|
* @param {string} selector
|
|
|
|
*/
|
|
|
|
const unsetCheckbox = async( selector ) => {
|
|
|
|
await page.focus( selector );
|
|
|
|
const checkbox = await page.$( selector );
|
|
|
|
const checkboxStatus = ( await ( await checkbox.getProperty( 'checked' ) ).jsonValue() );
|
|
|
|
if ( checkboxStatus === true ) {
|
|
|
|
await page.click( selector );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-27 12:22:24 +00:00
|
|
|
/**
|
|
|
|
* Wait for UI blocking to end.
|
|
|
|
*/
|
|
|
|
const uiUnblocked = async () => {
|
|
|
|
await page.waitForFunction( () => ! Boolean( document.querySelector( '.blockUI' ) ) );
|
|
|
|
};
|
|
|
|
|
2019-09-04 12:12:37 +00:00
|
|
|
/**
|
|
|
|
* Verify that checkbox is set.
|
|
|
|
*
|
|
|
|
* @param {string} selector Selector of the checkbox that needs to be verified.
|
|
|
|
*/
|
|
|
|
const verifyCheckboxIsSet = async( selector ) => {
|
|
|
|
await page.focus( selector );
|
|
|
|
const checkbox = await page.$( selector );
|
|
|
|
const checkboxStatus = ( await ( await checkbox.getProperty( 'checked' ) ).jsonValue() );
|
2019-09-04 16:34:33 +00:00
|
|
|
await expect( checkboxStatus ).toBe( true );
|
2019-09-04 12:12:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that checkbox is unset.
|
|
|
|
*
|
|
|
|
* @param {string} selector Selector of the checkbox that needs to be verified.
|
|
|
|
*/
|
|
|
|
const verifyCheckboxIsUnset = async( selector ) => {
|
|
|
|
await page.focus( selector );
|
|
|
|
const checkbox = await page.$( selector );
|
|
|
|
const checkboxStatus = ( await ( await checkbox.getProperty( 'checked' ) ).jsonValue() );
|
2019-09-04 16:34:33 +00:00
|
|
|
await expect( checkboxStatus ).not.toBe( true );
|
2019-09-04 12:12:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-09-04 16:34:33 +00:00
|
|
|
* Verify the value of input field once it was saved (can be used for radio buttons verification as well).
|
2019-09-04 12:12:37 +00:00
|
|
|
*
|
|
|
|
* @param {string} selector Selector of the input field that needs to be verified.
|
|
|
|
* @param {string} value Value of the input field that needs to be verified.
|
|
|
|
*/
|
|
|
|
const verifyValueOfInputField = async( selector, value ) => {
|
|
|
|
await page.focus( selector );
|
|
|
|
const field = await page.$( selector );
|
|
|
|
const fieldValue = ( await ( await field.getProperty( 'value' ) ).jsonValue() );
|
2019-09-04 16:34:33 +00:00
|
|
|
await expect( fieldValue ).toBe( value );
|
2019-09-04 12:12:37 +00:00
|
|
|
};
|
|
|
|
|
2019-08-27 12:22:24 +00:00
|
|
|
module.exports = {
|
|
|
|
...flows,
|
|
|
|
clickTab,
|
2019-08-30 11:03:57 +00:00
|
|
|
settingsPageSaveChanges,
|
2019-09-04 12:12:37 +00:00
|
|
|
setCheckbox,
|
|
|
|
unsetCheckbox,
|
2019-08-27 12:22:24 +00:00
|
|
|
uiUnblocked,
|
2019-09-04 12:12:37 +00:00
|
|
|
verifyCheckboxIsSet,
|
|
|
|
verifyCheckboxIsUnset,
|
|
|
|
verifyValueOfInputField,
|
2019-08-27 12:22:24 +00:00
|
|
|
};
|