Create util function for toggling product editor tour

This commit is contained in:
Rodel Calasagsag 2023-08-30 14:50:57 +08:00
parent 906d501688
commit 8b152bcecf
2 changed files with 35 additions and 1 deletions

View File

@ -3,10 +3,13 @@ const api = require( './api' );
const site = require( './site' );
const variableProducts = require( './variable-products' );
const features = require( './features' );
const tours = require( './tours' );
module.exports = {
onboarding,
api,
site,
variableProducts,
features
features,
tours,
};

View File

@ -0,0 +1,31 @@
const { admin } = require( '../test-data/data' );
const base64String = Buffer.from(
`${ admin.username }:${ admin.password }`
).toString( 'base64' );
const headers = {
Authorization: `Basic ${ base64String }`,
cookie: '',
};
/**
* Enables or disables the product editor tour.
*
* @param {import('@playwright/test').APIRequestContext} request Request context from calling function.
* @param {boolean} enable Set to `true` if you want to enable the block product tour. `false` if otherwise.
*/
const toggleBlockProductTour = async ( request, enable ) => {
const url = '/wp-json/wc-admin/options';
const params = { _locale: 'user' };
const toggleValue = enable ? 'no' : 'yes';
const data = { woocommerce_block_product_tour_shown: toggleValue };
await request.post( url, {
data,
params,
headers,
} );
};
module.exports = { toggleBlockProductTour };