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() );
|
|
|
|
if ( checkboxStatus === true ) {
|
|
|
|
return checkboxStatus;
|
|
|
|
} else {
|
|
|
|
console.log( selector + ' checkbox is not set.' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() );
|
|
|
|
if ( checkboxStatus !== true ) {
|
|
|
|
return checkboxStatus;
|
|
|
|
} else {
|
|
|
|
console.log( selector + ' checkbox is not unset.' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify the value of input field once it was saved.
|
|
|
|
*
|
|
|
|
* @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() );
|
|
|
|
if ( fieldValue === value ) {
|
|
|
|
return fieldValue;
|
|
|
|
} else {
|
|
|
|
console.log( 'The value of ' + selector + ' does not equal to ' + value + ' .' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|