woocommerce/plugins/woocommerce-admin/tests/e2e/specs/activate-and-setup/complete-store-details-sect...

88 lines
2.8 KiB
JavaScript

/**
* @format
*/
/**
* Internal dependencies
*/
import { verifyCheckboxIsUnset } from '../../utils/actions';
const config = require( 'config' );
export async function completeStoreDetailsSection( storeDetails = {} ) {
// Fill store's address - first line
await expect( page ).toFill(
'#inspector-text-control-0',
storeDetails.addressLine1 ||
config.get( 'addresses.admin.store.addressfirstline' )
);
// Fill store's address - second line
await expect( page ).toFill(
'#inspector-text-control-1',
storeDetails.addressLine2 ||
config.get( 'addresses.admin.store.addresssecondline' )
);
// Type the requested country/region substring or 'cali' in the
// country/region select, then select the requested country/region
// substring or 'US:CA'.
await expect( page ).toFill(
'#woocommerce-select-control-0__control-input',
storeDetails.countryRegionSubstring || 'cali'
);
await expect( page ).toClick(
`#woocommerce-select-control__option-0-${
storeDetails.countryRegionSelector || 'US\\:CA'
}`
);
// Make sure the country/region gets selected correctly, using either the
// requested country/region or US - California.
await expect( page ).toMatchElement(
'#woocommerce-select-control-0__control-input',
{
value:
storeDetails.countryRegion || 'United State (US) - California',
}
);
// Fill the city where the store is located
await expect( page ).toFill(
'#inspector-text-control-2',
storeDetails.city || config.get( 'addresses.admin.store.city' )
);
// Fill postcode of the store
await expect( page ).toFill(
'#inspector-text-control-3',
storeDetails.postcode || config.get( 'addresses.admin.store.postcode' )
);
// Verify that checkbox next to "I'm setting up a store for a client" is not selected
await verifyCheckboxIsUnset( '.components-checkbox-control__input' );
// Wait for "Continue" button to become active
await page.waitForSelector( 'button.is-primary:not(:disabled)' );
// Click on "Continue" button to move to the next step
await page.click( 'button.is-primary', { text: 'Continue' } );
// Wait for usage tracking pop-up window to appear
await page.waitForSelector( '.components-modal__header-heading' );
await expect( page ).toMatchElement( '.components-modal__header-heading', {
text: 'Build a better WooCommerce',
} );
// Query for primary buttons: "Continue" and "Yes, count me in"
const primaryButtons = await page.$$( 'button.is-primary' );
expect( primaryButtons ).toHaveLength( 2 );
await Promise.all( [
// Click on "No thanks" button of the usage pop-up window to move to the next step
await page.click( 'button.is-secondary', { text: 'No thanks' } ),
// Wait for "In which industry does the store operate?" section to load
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
] );
}