11import { type Page } from '@playwright/test' ;
2- import SiteForm from './site-form' ;
2+ import { expect } from '@playwright/test' ;
3+ import AddSiteModal from './add-site-modal' ;
4+ import MainSidebar from './main-sidebar' ;
35
46export default class Onboarding {
57 constructor ( private page : Page ) { }
@@ -8,27 +10,63 @@ export default class Onboarding {
810 return this . page . getByTestId ( 'onboarding' ) ;
911 }
1012
11- private get siteForm ( ) {
12- return new SiteForm ( this . page ) ;
13- }
14-
1513 get heading ( ) {
16- return this . locator . getByRole ( 'heading' , { name : 'Add your first site' } ) ;
14+ return this . locator . getByRole ( 'heading' , {
15+ name : / C o n n e c t t o y o u r W o r d P r e s s .c o m a c c o u n t | A d d y o u r f i r s t s i t e / ,
16+ } ) ;
1717 }
1818
19- get siteNameInput ( ) {
20- return this . siteForm . siteNameInput ;
21- }
19+ async completeOnboarding ( options ?: { customSiteName ?: string ; customFolderName ?: string } ) {
20+ const { customSiteName, customFolderName } = options ?? { } ;
2221
23- get localPathInput ( ) {
24- return this . siteForm . localPathInput ;
25- }
22+ await expect ( this . heading ) . toBeVisible ( ) ;
2623
27- get continueButton ( ) {
28- return this . locator . getByRole ( 'button' , { name : / C o n t i n u e | A d d s i t e / } ) ;
29- }
24+ if (
25+ await this . locator
26+ . getByRole ( 'heading' , { name : 'Connect to your WordPress.com account' } )
27+ . isVisible ( )
28+ ) {
29+ await this . locator . getByRole ( 'button' , { name : 'Skip →' } ) . click ( ) ;
30+ const sidebar = new MainSidebar ( this . page ) ;
31+ const modal = await sidebar . openAddSiteModal ( ) ;
32+ await modal . createSiteButton . click ( ) ;
33+
34+ if ( customSiteName ) {
35+ await modal . siteNameInput . fill ( customSiteName ) ;
36+ }
37+ await expect ( modal . siteNameInput ) . toHaveValue ( / \S + / , { timeout : 5000 } ) ;
38+ const siteName = await modal . siteNameInput . inputValue ( ) ;
39+
40+ if ( customFolderName ) {
41+ await modal . selectLocalPathForTesting ( customFolderName ) ;
42+ }
43+ const localPath = await modal . localPathInput . inputValue ( ) ;
44+
45+ await modal . continueButton . click ( ) ;
46+
47+ return {
48+ siteName,
49+ localPath,
50+ } ;
51+ } else {
52+ const modal = new AddSiteModal ( this . page ) ;
53+ if ( customSiteName ) {
54+ await modal . siteNameInput . fill ( customSiteName ) ;
55+ }
56+ await expect ( modal . siteNameInput ) . toHaveValue ( / \S + / , { timeout : 5000 } ) ;
57+ const siteName = await modal . siteNameInput . inputValue ( ) ;
58+
59+ if ( customFolderName ) {
60+ await modal . selectLocalPathForTesting ( customFolderName ) ;
61+ }
62+ const localPath = await modal . localPathInput . inputValue ( ) ;
63+
64+ await this . page . getByRole ( 'button' , { name : 'Continue' } ) . click ( ) ;
3065
31- async selectLocalPathForTesting ( partialExpectedPath : string ) {
32- await this . siteForm . clickLocalPathButtonAndSelectFromEnv ( partialExpectedPath ) ;
66+ return {
67+ siteName,
68+ localPath,
69+ } ;
70+ }
3371 }
3472}
0 commit comments