2021-03-17 19:22:09 +00:00
|
|
|
|
import { getElementByText, waitForElementByText } from '../utils/actions';
|
2021-04-05 00:09:36 +00:00
|
|
|
|
import { BasePage } from './BasePage';
|
2021-03-17 19:22:09 +00:00
|
|
|
|
|
2021-04-05 00:09:36 +00:00
|
|
|
|
export class WcHomescreen extends BasePage {
|
|
|
|
|
url = 'wp-admin/admin.php?page=wc-admin';
|
2021-03-17 19:22:09 +00:00
|
|
|
|
|
|
|
|
|
async isDisplayed() {
|
|
|
|
|
// Wait for Benefits section to appear
|
|
|
|
|
await waitForElementByText( 'h1', 'Home' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async possiblyDismissWelcomeModal() {
|
|
|
|
|
// Wait for Benefits section to appear
|
|
|
|
|
const modal = await getElementByText(
|
|
|
|
|
'h2',
|
|
|
|
|
'Welcome to your WooCommerce store’s online HQ!'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( modal ) {
|
2021-04-05 00:09:36 +00:00
|
|
|
|
await this.clickButtonWithText( 'Next' );
|
|
|
|
|
await this.clickButtonWithText( 'Next' );
|
|
|
|
|
await this.click( '.components-guide__finish-button' );
|
2021-03-17 19:22:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getTaskList() {
|
|
|
|
|
await page.waitForSelector(
|
|
|
|
|
'.woocommerce-task-card .woocommerce-list__item-title'
|
|
|
|
|
);
|
|
|
|
|
await waitForElementByText( 'p', 'Get ready to start selling' );
|
|
|
|
|
const list = await this.page.$$eval(
|
|
|
|
|
'.woocommerce-task-card .woocommerce-list__item-title',
|
|
|
|
|
( items ) => items.map( ( item ) => item.textContent )
|
|
|
|
|
);
|
|
|
|
|
return list.map( ( item: string | null ) => {
|
|
|
|
|
const match = item?.match( /(.+)[0-9] minute/ );
|
|
|
|
|
if ( match && match.length > 1 ) {
|
|
|
|
|
return match[ 1 ];
|
|
|
|
|
}
|
|
|
|
|
return item;
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async clickOnTaskList( taskTitle: string ) {
|
2021-04-05 00:09:36 +00:00
|
|
|
|
const item = await waitForElementByText( 'div', taskTitle );
|
|
|
|
|
|
|
|
|
|
if ( ! item ) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Could not find task list item with title: ${ taskTitle }`
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
await item.click();
|
|
|
|
|
await waitForElementByText( 'h1', taskTitle );
|
|
|
|
|
}
|
2021-03-17 19:22:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|