File size: 7,803 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
import { Page } from 'playwright';
import { DataHelper } from '../..';
const selectors = {
// Generic
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',
// Inputs
urlInput: 'input.capture__input',
goalsCaptureUrlInput: 'input.form-text-input[value]',
// ImporterDrag page
importerDrag: ( text: string ) => `div.importer-wrapper__${ text }`,
// Errors
analyzeError: ( text: string ) => `:text("${ text }")`,
// Headers
setupHeader: 'h1:text("Themes")',
startBuildingHeader: ( text: string ) =>
`h1:text("${ text }"), h1.onboarding-title:text("${ text }")`,
importModal: 'div.import__confirm-modal',
// Buttons
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")',
// And entry of the list of selectable importers
importerListButton: ( index: number ) =>
`div.list__importers-primary button:nth-child(${ index + 1 })`,
};
/**
* Class encapsulating the flow when starting a new start importer ('/start/importer')
*/
export class StartImportFlow {
/**
* Constructs an instance of the flow.
*
* @param {Page} page The underlying page.
*/
constructor( private page: Page ) {}
/**
* Given text, click on the button's first instance with the text.
*
* @param {string} text User-visible text on the button.
*/
async clickButton( text: string ): Promise< void > {
const selector = selectors.button( text );
await this.page.locator( selector ).click();
}
/**
* Validates that we've landed on the setup page.
*/
async validateSetupPage(): Promise< void > {
await this.page.locator(
`${ selectors.startImportButton }, ${ selectors.startImportGoalButton }`
);
}
/**
* Validates that we show migration modal.
*/
async validateImportModal(): Promise< void > {
await this.page.locator( `${ selectors.importModal }` ).waitFor();
}
/**
* Validates that we've landed on the URL capture page.
*/
async validateURLCapturePage(): Promise< void > {
await this.page.waitForURL( /.*setup\/site-setup\/import.*/ );
}
/**
* Validates that we've landed on the URL capture page.
*/
async validateURLMigrationFlow(): Promise< void > {
await this.page.waitForURL( /.*setup\/site-migration.*/ );
}
/**
* Validates that we've landed on the URL capture page with 'typo' error.
*/
async validateErrorCapturePage( error: string ): Promise< void > {
await this.page.locator( selectors.analyzeError( error ) ).waitFor();
}
/**
* Validates that we've landed on the import page.
*/
async validateImportPage(): Promise< void > {
await this.page
.locator( selectors.startBuildingHeader( 'Your content is ready for its brand new home' ) )
.waitFor();
}
/**
* Validates that we've landed on the upgrade plan page.
*/
async validateUpgradePlanPage(): Promise< void > {
await this.page
.locator( selectors.startBuildingHeader( 'Take your site to the next level' ) )
.waitFor();
}
/**
* Validates that we've landed on the "Install Jetpack" page.
*/
async validateInstallJetpackPage(): Promise< void > {
await this.page.locator( selectors.startBuildingHeader( 'Install Jetpack' ) ).waitFor();
}
/**
* Validates that we've landed on the checkout page.
*/
async validateCheckoutPage(): Promise< void > {
await this.page.getByText( 'Secure checkout' ).waitFor();
}
/**
* Validates that we've landed on the site picker page.
*/
async validateSitePickerPage(): Promise< void > {
await this.page.getByText( 'Pick your destination' ).waitFor();
}
/**
* Validates that we've landed on the migration ready page.
*/
async validateMigrationReadyPage(): Promise< void > {
await this.page.getByText( 'Your site is ready for its brand new home' ).waitFor();
}
/**
* Validates that we've landed on the building page.
*
* @param {string} reason The reason shown in main header.
*/
async validateBuildingPage( reason: string ): Promise< void > {
await this.page.locator( selectors.startBuildingHeader( reason ) ).waitFor();
}
/**
* Validates that we've landed on the design setup page.
*/
async validateDesignPage(): Promise< void > {
await this.page.locator( selectors.setupHeader ).waitFor();
}
/**
* Validates that we've landed on the importer drag page.
*/
async validateImporterDragPage( importer: string ): Promise< void > {
await this.page.locator( selectors.importerDrag( importer ) ).waitFor();
}
/**
* Validates that we've landed on the importer list page.
*/
async validateImporterListPage(): Promise< void > {
await this.page
.locator( selectors.startBuildingHeader( 'Import content from another platform or file' ) )
.waitFor();
}
/**
* Enter the URL to import from on the "Enter your site address" input form.
*
* @param {string} url The source URL.
* @throws {Error} If no URL input is found.
*/
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 );
// Support both Legacy and Goals Capture versions
// of the URL input for importer.
// See https://github.com/Automattic/wp-calypso/issues/65792
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();
}
/**
* Go to first import page.
*
* @param {string} siteSlug The site slug URL.
*/
async startImport( siteSlug: string ): Promise< void > {
const route = '/setup/setup-site';
await this.page.goto( DataHelper.getCalypsoURL( route, { siteSlug } ) );
}
/**
* Go to first setup page.
*
* @param {string} siteSlug The site slug URL.
*/
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 );
}
/**
* Start the building.
*/
async startBuilding(): Promise< void > {
await this.page.click( selectors.startBuildingButton );
}
/**
* Open the importer list page.
*/
async startImporterList(): Promise< void > {
await this.page.click( selectors.dontHaveASiteButton );
}
/**
* An entry from the list of importers.
*
* @param index the desired importer
*/
async selectImporterFromList( index: number ): Promise< void > {
await this.page.click( selectors.importerListButton( index ) );
await this.page
.locator( selectors.startBuildingHeader( 'Import content from WordPress' ) )
.waitFor();
}
/**
* Click back button of the flow.
*/
async clickBack(): Promise< void > {
await this.page.click( selectors.backLink );
}
/**
* Click migration modal cancel.
*/
async clickMigrationModalCancel(): Promise< void > {
await this.page.click( selectors.migrationModalCancel );
}
/**
* Navigate back one screen in the flow.
*/
async goBackOneScreen(): Promise< void > {
await this.clickBack();
await this.page.waitForNavigation();
}
}
|