| import { Page } from 'playwright'; |
| import { DataHelper } from '../..'; |
|
|
| const selectors = { |
| |
| button: ( text: string ) => `button:text("${ text }")`, |
| backLink: '.navigation-link:text("Back"), button:text-matches("Back")', |
| dontHaveASiteButton: 'button:text-matches("choose a content platform", "i")', |
| migrationModalCancel: 'button.action-buttons__cancel', |
| |
| urlInput: 'input.capture__input', |
| goalsCaptureUrlInput: 'input.form-text-input[value]', |
|
|
| |
| importerDrag: ( text: string ) => `div.importer-wrapper__${ text }`, |
|
|
| |
| analyzeError: ( text: string ) => `:text("${ text }")`, |
|
|
| |
| setupHeader: 'h1:text("Themes")', |
| startBuildingHeader: ( text: string ) => |
| `h1:text("${ text }"), h1.onboarding-title:text("${ text }")`, |
|
|
| importModal: 'div.import__confirm-modal', |
|
|
| |
| checkUrlButton: 'form.capture__input-wrapper button.action-buttons__next', |
| startBuildingButton: 'div.import__onboarding-page button.action-buttons__next', |
| startImportButton: 'button:text("Import your site content")', |
| startImportGoalButton: 'span:has-text("Import my existing website content")', |
| |
| importerListButton: ( index: number ) => |
| `div.list__importers-primary button:nth-child(${ index + 1 })`, |
| }; |
|
|
| |
| |
| |
| export class StartImportFlow { |
| |
| |
| |
| |
| |
| constructor( private page: Page ) {} |
|
|
| |
| |
| |
| |
| |
| async clickButton( text: string ): Promise< void > { |
| const selector = selectors.button( text ); |
|
|
| await this.page.locator( selector ).click(); |
| } |
|
|
| |
| |
| |
| async validateSetupPage(): Promise< void > { |
| await this.page.locator( |
| `${ selectors.startImportButton }, ${ selectors.startImportGoalButton }` |
| ); |
| } |
|
|
| |
| |
| |
| async validateImportModal(): Promise< void > { |
| await this.page.locator( `${ selectors.importModal }` ).waitFor(); |
| } |
|
|
| |
| |
| |
| async validateURLCapturePage(): Promise< void > { |
| await this.page.waitForURL( /.*setup\/site-setup\/import.*/ ); |
| } |
|
|
| |
| |
| |
| async validateURLMigrationFlow(): Promise< void > { |
| await this.page.waitForURL( /.*setup\/site-migration.*/ ); |
| } |
|
|
| |
| |
| |
| async validateErrorCapturePage( error: string ): Promise< void > { |
| await this.page.locator( selectors.analyzeError( error ) ).waitFor(); |
| } |
|
|
| |
| |
| |
| async validateImportPage(): Promise< void > { |
| await this.page |
| .locator( selectors.startBuildingHeader( 'Your content is ready for its brand new home' ) ) |
| .waitFor(); |
| } |
|
|
| |
| |
| |
| async validateUpgradePlanPage(): Promise< void > { |
| await this.page |
| .locator( selectors.startBuildingHeader( 'Take your site to the next level' ) ) |
| .waitFor(); |
| } |
|
|
| |
| |
| |
| async validateInstallJetpackPage(): Promise< void > { |
| await this.page.locator( selectors.startBuildingHeader( 'Install Jetpack' ) ).waitFor(); |
| } |
|
|
| |
| |
| |
| async validateCheckoutPage(): Promise< void > { |
| await this.page.getByText( 'Secure checkout' ).waitFor(); |
| } |
|
|
| |
| |
| |
| async validateSitePickerPage(): Promise< void > { |
| await this.page.getByText( 'Pick your destination' ).waitFor(); |
| } |
|
|
| |
| |
| |
| async validateMigrationReadyPage(): Promise< void > { |
| await this.page.getByText( 'Your site is ready for its brand new home' ).waitFor(); |
| } |
|
|
| |
| |
| |
| |
| |
| async validateBuildingPage( reason: string ): Promise< void > { |
| await this.page.locator( selectors.startBuildingHeader( reason ) ).waitFor(); |
| } |
|
|
| |
| |
| |
| async validateDesignPage(): Promise< void > { |
| await this.page.locator( selectors.setupHeader ).waitFor(); |
| } |
|
|
| |
| |
| |
| async validateImporterDragPage( importer: string ): Promise< void > { |
| await this.page.locator( selectors.importerDrag( importer ) ).waitFor(); |
| } |
|
|
| |
| |
| |
| async validateImporterListPage(): Promise< void > { |
| await this.page |
| .locator( selectors.startBuildingHeader( 'Import content from another platform or file' ) ) |
| .waitFor(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| async enterURL( url: string ): Promise< void > { |
| await this.page.waitForLoadState( 'load' ); |
|
|
| const legacyURLInputLocator = this.page.locator( selectors.urlInput ); |
| const goalsCaptureURLInputLocator = this.page.locator( selectors.goalsCaptureUrlInput ); |
|
|
| |
| |
| |
| const element = await Promise.race( [ |
| legacyURLInputLocator.elementHandle(), |
| goalsCaptureURLInputLocator.elementHandle(), |
| ] ); |
|
|
| if ( ! element ) { |
| throw new Error( 'No matching URL input found at Site Importer.' ); |
| } |
| await element.fill( url ); |
| const continueLocator = this.page.locator( |
| `${ selectors.checkUrlButton }, ${ selectors.button( 'Continue' ) }` |
| ); |
|
|
| await continueLocator.click(); |
| } |
|
|
| |
| |
| |
| |
| |
| async startImport( siteSlug: string ): Promise< void > { |
| const route = '/setup/setup-site'; |
|
|
| await this.page.goto( DataHelper.getCalypsoURL( route, { siteSlug } ) ); |
| } |
|
|
| |
| |
| |
| |
| |
| async startSetup( siteSlug: string ): Promise< void > { |
| const route = '/setup/site-setup/intent'; |
|
|
| await this.page.goto( DataHelper.getCalypsoURL( route, { siteSlug } ) ); |
| await this.validateSetupPage(); |
| await this.page.click( selectors.startImportButton ); |
| } |
|
|
| |
| |
| |
| async startBuilding(): Promise< void > { |
| await this.page.click( selectors.startBuildingButton ); |
| } |
|
|
| |
| |
| |
| async startImporterList(): Promise< void > { |
| await this.page.click( selectors.dontHaveASiteButton ); |
| } |
|
|
| |
| |
| |
| |
| |
| async selectImporterFromList( index: number ): Promise< void > { |
| await this.page.click( selectors.importerListButton( index ) ); |
| await this.page |
| .locator( selectors.startBuildingHeader( 'Import content from WordPress' ) ) |
| .waitFor(); |
| } |
|
|
| |
| |
| |
| async clickBack(): Promise< void > { |
| await this.page.click( selectors.backLink ); |
| } |
|
|
| |
| |
| |
| async clickMigrationModalCancel(): Promise< void > { |
| await this.page.click( selectors.migrationModalCancel ); |
| } |
|
|
| |
| |
| |
| async goBackOneScreen(): Promise< void > { |
| await this.clickBack(); |
| await this.page.waitForNavigation(); |
| } |
| } |
|
|