2020-09-04 02:31:09 +00:00
|
|
|
/**
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-01-06 22:08:57 +00:00
|
|
|
import {
|
|
|
|
clickContinue,
|
|
|
|
getElementByText,
|
|
|
|
getPreviousSibling,
|
|
|
|
setCheckboxToChecked,
|
|
|
|
setCheckboxToUnchecked,
|
|
|
|
} from './utils';
|
2020-09-04 02:31:09 +00:00
|
|
|
import { waitForElementCount } from '../../utils/lib';
|
|
|
|
const config = require( 'config' );
|
|
|
|
|
2020-09-22 12:20:42 +00:00
|
|
|
export async function completeIndustrySection( expectedIndustryCount = 8 ) {
|
2020-09-04 02:31:09 +00:00
|
|
|
// Query for the industries checkboxes
|
|
|
|
await waitForElementCount(
|
|
|
|
page,
|
|
|
|
'.components-checkbox-control__input',
|
|
|
|
expectedIndustryCount
|
|
|
|
);
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
await uncheckAllExistingIndustries();
|
|
|
|
|
|
|
|
// Select just "fashion" and "health/beauty" to get the single checkbox business section when
|
|
|
|
// filling out details for a US store.
|
|
|
|
const fashionLabel = await getElementByText(
|
|
|
|
'label',
|
|
|
|
'Fashion, apparel, and accessories'
|
2020-09-04 02:31:09 +00:00
|
|
|
);
|
2021-01-06 22:08:57 +00:00
|
|
|
// get sibling checkbox
|
|
|
|
const fashionCheckboxContainer = await getPreviousSibling( fashionLabel );
|
|
|
|
const fashionCheckbox = await fashionCheckboxContainer.$( 'input' );
|
|
|
|
|
|
|
|
await setCheckboxToChecked( fashionCheckbox );
|
2020-09-04 02:31:09 +00:00
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
const healthBeautyLabel = await getElementByText(
|
|
|
|
'label',
|
|
|
|
'Health and beauty'
|
|
|
|
);
|
|
|
|
const healthBeautyCheckboxContainer = await getPreviousSibling(
|
|
|
|
healthBeautyLabel
|
|
|
|
);
|
|
|
|
const healthBeautyCheckbox = await healthBeautyCheckboxContainer.$(
|
|
|
|
'input'
|
2020-09-04 02:31:09 +00:00
|
|
|
);
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
await setCheckboxToChecked( healthBeautyCheckbox );
|
|
|
|
await clickContinue();
|
|
|
|
}
|
2020-09-04 02:31:09 +00:00
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
// Check industry checkboxes based on industryLabels passed in. Note each label must match
|
|
|
|
// the text contents of the label.
|
|
|
|
export async function chooseIndustries( industryLabels = [] ) {
|
|
|
|
await uncheckAllExistingIndustries();
|
|
|
|
|
|
|
|
for ( const labelText of industryLabels ) {
|
|
|
|
const label = await getElementByText( 'label', labelText );
|
|
|
|
const checkboxContainer = await getPreviousSibling( label );
|
|
|
|
const checkbox = await checkboxContainer.$( 'input' );
|
|
|
|
|
|
|
|
await setCheckboxToChecked( checkbox );
|
|
|
|
await clickContinue();
|
2020-09-04 02:31:09 +00:00
|
|
|
}
|
2021-01-06 22:08:57 +00:00
|
|
|
}
|
2020-09-04 02:31:09 +00:00
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
// Utility to uncheck all the industry checkboxes, ensuring no state crosses over
|
|
|
|
// between tests.
|
|
|
|
async function uncheckAllExistingIndustries() {
|
|
|
|
const industryCheckboxes = await page.$$(
|
|
|
|
'.components-checkbox-control__input'
|
2020-09-04 02:31:09 +00:00
|
|
|
);
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
for ( const checkbox of industryCheckboxes ) {
|
|
|
|
await setCheckboxToUnchecked( checkbox );
|
|
|
|
}
|
2020-09-04 02:31:09 +00:00
|
|
|
}
|