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(
|
2021-04-27 15:23:34 +00:00
|
|
|
|
'.woocommerce-task-card .woocommerce-task-list__item-title'
|
2021-03-17 19:22:09 +00:00
|
|
|
|
);
|
|
|
|
|
await waitForElementByText( 'p', 'Get ready to start selling' );
|
|
|
|
|
const list = await this.page.$$eval(
|
2021-04-27 15:23:34 +00:00
|
|
|
|
'.woocommerce-task-card .woocommerce-task-list__item-title',
|
2021-03-17 19:22:09 +00:00
|
|
|
|
( 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
|
|
|
|
}
|
|
|
|
|
}
|