|
|
import { Page } from 'playwright'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type StepName = |
|
|
| 'goals' |
|
|
| 'vertical' |
|
|
| 'intent' |
|
|
| 'design-setup' |
|
|
| 'options' |
|
|
| 'designChoices'; |
|
|
type WriteActions = 'Start writing' | 'Start learning' | 'View designs'; |
|
|
|
|
|
const selectors = { |
|
|
|
|
|
button: ( text: string ) => `button:text("${ text }")`, |
|
|
backLink: 'button:text("Back")', |
|
|
|
|
|
|
|
|
blogNameInput: 'input[name="siteTitle"]:not(:disabled)', |
|
|
taglineInput: 'input[name="tagline"]:not(:disabled)', |
|
|
|
|
|
|
|
|
individualThemeContainer: ( name: string ) => `.design-button-container:has-text("${ name }")`, |
|
|
|
|
|
|
|
|
goalButton: ( goal: string ) => |
|
|
`.select-card-checkbox__container:has-text("${ goal.toLowerCase() }")`, |
|
|
selectedGoalButton: ( goal: string ) => |
|
|
`.select-card-checkbox__container:has(:checked):has-text("${ goal }")`, |
|
|
|
|
|
|
|
|
contentAgnosticContainer: '.step-container', |
|
|
themePickerContainer: '.design-picker', |
|
|
goalsStepContainer: '.goals-step', |
|
|
verticalsStepContainer: '.site-vertical', |
|
|
intentStepContainer: '.intent-step', |
|
|
optionsStepContainer: '.is-step-write', |
|
|
designChoicesStepContainer: '.design-choices', |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class StartSiteFlow { |
|
|
private page: Page; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page ) { |
|
|
this.page = page; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickButton( text: string ): Promise< void > { |
|
|
await this.page.getByRole( 'button', { name: text } ).click(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getCurrentStep(): Promise< StepName > { |
|
|
|
|
|
await this.page.waitForSelector( selectors.contentAgnosticContainer ); |
|
|
if ( ( await this.page.locator( selectors.goalsStepContainer ).count() ) > 0 ) { |
|
|
return 'goals'; |
|
|
} |
|
|
if ( ( await this.page.locator( selectors.intentStepContainer ).count() ) > 0 ) { |
|
|
return 'intent'; |
|
|
} |
|
|
if ( ( await this.page.locator( selectors.themePickerContainer ).count() ) > 0 ) { |
|
|
return 'design-setup'; |
|
|
} |
|
|
if ( ( await this.page.locator( selectors.optionsStepContainer ).count() ) > 0 ) { |
|
|
return 'options'; |
|
|
} |
|
|
if ( ( await this.page.locator( selectors.designChoicesStepContainer ).count() ) > 0 ) { |
|
|
return 'designChoices'; |
|
|
} |
|
|
throw new Error( 'Unknown or invalid step' ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectGoal( goal: string ): Promise< void > { |
|
|
await this.page.click( selectors.goalButton( goal ) ); |
|
|
await this.page.waitForSelector( selectors.selectedGoalButton( goal ) ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickDesignChoice( choice: 'theme' | 'ai' ): Promise< void > { |
|
|
|
|
|
const choiceLabel = choice === 'theme' ? 'Start with a theme' : 'Create with AI (BETA)'; |
|
|
|
|
|
await this.page.getByRole( 'button', { name: choiceLabel } ).click(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async enterBlogName( name: string ): Promise< void > { |
|
|
const defaultInputlocator = this.page.locator( selectors.blogNameInput ); |
|
|
|
|
|
await defaultInputlocator.fill( name ); |
|
|
|
|
|
|
|
|
const filledInputLocator = this.page.locator( selectors.blogNameInput ); |
|
|
const readBack = await filledInputLocator.inputValue(); |
|
|
if ( readBack !== name ) { |
|
|
throw new Error( `Failed to set blog name: expected ${ name }, got ${ readBack }` ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async enterTagline( tagline: string ): Promise< void > { |
|
|
const locator = this.page.locator( selectors.taglineInput ); |
|
|
await locator.fill( tagline ); |
|
|
|
|
|
|
|
|
const readBack = await locator.inputValue(); |
|
|
if ( readBack !== tagline ) { |
|
|
throw new Error( `Failed to set blog tagline: expected ${ tagline }, got ${ readBack }` ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickWriteAction( action: WriteActions ) { |
|
|
await this.page.getByRole( 'button', { name: action } ).click(); |
|
|
|
|
|
if ( action === 'Start writing' ) { |
|
|
|
|
|
|
|
|
await this.page.waitForURL( /setup\/site-setup\/processing/, { timeout: 20 * 1000 } ); |
|
|
} |
|
|
if ( action === 'Start learning' ) { |
|
|
await this.page.waitForURL( /setup\/site-setup\/courses/ ); |
|
|
} |
|
|
if ( action === 'View designs' ) { |
|
|
await this.page.waitForURL( /setup\/site-setup\/design-setup/ ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async validateOnDesignPickerScreen(): Promise< void > { |
|
|
await this.page.waitForSelector( selectors.themePickerContainer ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async goBackOneScreen(): Promise< void > { |
|
|
await this.page.click( selectors.backLink ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectTheme( themeName: string ): Promise< void > { |
|
|
await this.page.getByRole( 'link', { name: themeName } ).first().click(); |
|
|
} |
|
|
} |
|
|
|