|
|
import { Page } from 'playwright'; |
|
|
|
|
|
export type SourceService = ( typeof SiteImportPage.services )[ number ]; |
|
|
|
|
|
const selectors = { |
|
|
|
|
|
service: ( name: SourceService ) => `h1:text("${ name }")`, |
|
|
|
|
|
|
|
|
backButton: 'a:text("Back")', |
|
|
cancelButton: 'button:text("Cancel")', |
|
|
continueButton: 'button:text("Continue")', |
|
|
|
|
|
|
|
|
siteInput: '[placeholder="example.com"]', |
|
|
fileInput: 'input[name="exportFile"]', |
|
|
fileInputText: 'text=Drag a file here, or click to upload a file', |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class SiteImportPage { |
|
|
static services = [ |
|
|
'WordPress', |
|
|
|
|
|
|
|
|
'Medium', |
|
|
'Squarespace', |
|
|
'Wix', |
|
|
] as const; |
|
|
private page: Page; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page ) { |
|
|
this.page = page; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectService( service: SourceService ): Promise< void > { |
|
|
await Promise.all( [ |
|
|
this.page.waitForLoadState( 'load' ), |
|
|
this.page.click( selectors.service( service ) ), |
|
|
] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async verifyImporter( service: SourceService ): Promise< void > { |
|
|
|
|
|
if ( [ 'WordPress', 'Wix' ].includes( service ) ) { |
|
|
await this.page.waitForSelector( selectors.siteInput ); |
|
|
await this.page.waitForSelector( selectors.continueButton ); |
|
|
} else { |
|
|
await this.page.waitForSelector( selectors.fileInputText ); |
|
|
|
|
|
await this.page.waitForSelector( `:has-text("from a ${ service } export file")` ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async cancel(): Promise< void > { |
|
|
if ( await this.page.isVisible( selectors.backButton ) ) { |
|
|
await this.page.click( selectors.backButton ); |
|
|
} else { |
|
|
await this.page.click( selectors.cancelButton ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|