|
|
import { Page } from 'playwright'; |
|
|
import { getCalypsoURL } from '../../data-helper'; |
|
|
import { clickNavTab } from '../../element-helper'; |
|
|
import envVariables from '../../env-variables'; |
|
|
|
|
|
|
|
|
export type Plans = |
|
|
| 'Free' |
|
|
| 'Personal' |
|
|
| 'Premium' |
|
|
| 'Business' |
|
|
| 'eCommerce' |
|
|
| 'Starter' |
|
|
| 'Explorer' |
|
|
| 'Creator' |
|
|
| 'Entrepreneur'; |
|
|
export type PlansPageTab = 'My Plan' | 'Plans'; |
|
|
export type PlanActionButton = 'Manage plan' | 'Upgrade'; |
|
|
|
|
|
const selectors = { |
|
|
|
|
|
placeholder: '.is-placeholder', |
|
|
managePlanButton: 'a:has-text("Manage plan")', |
|
|
addOnCombobox: ( name: Plans ) => { |
|
|
return `.plans-grid-next-plan-storage[data-plan-title="${ name }"]`; |
|
|
}, |
|
|
addOnComboboxButton: 'button[role="combobox"]', |
|
|
addOnComboboxOption: ( addOn: string ) => `[role="option"]:has-text("${ addOn }")`, |
|
|
selectPlanButton: ( name: Plans ) => { |
|
|
if ( name === 'Free' ) { |
|
|
|
|
|
|
|
|
return `button:text-matches("${ name }", "i"):visible`; |
|
|
} |
|
|
return `button.is-${ name.toLowerCase() }-plan:visible`; |
|
|
}, |
|
|
selectModalUpsellPlanButton: ( name: 'Free' | 'Personal' ) => { |
|
|
if ( name === 'Free' ) { |
|
|
return 'button.is-upsell-modal-free-plan:visible'; |
|
|
} |
|
|
return `button.is-upsell-modal-${ name.toLowerCase() }-plan:visible`; |
|
|
}, |
|
|
|
|
|
|
|
|
mobileNavTabsToggle: 'button.section-nav__mobile-header', |
|
|
navigationTab: ( tabName: PlansPageTab ) => `.section-nav-tab:has-text("${ tabName }")`, |
|
|
activeNavigationTab: ( tabName: PlansPageTab ) => |
|
|
`.is-selected.section-nav-tab:has-text("${ tabName }")`, |
|
|
|
|
|
|
|
|
PlansGrid: '.plans-features-main', |
|
|
actionButton: ( { plan, buttonText }: { plan: Plans; buttonText: PlanActionButton } ) => { |
|
|
const viewportSuffix = envVariables.VIEWPORT_NAME === 'mobile' ? 'mobile' : 'table'; |
|
|
return `.plan-features__${ viewportSuffix } >> .plan-features__actions-button.is-${ plan.toLowerCase() }-plan:has-text("${ buttonText }")`; |
|
|
}, |
|
|
activePlan: ( plan: Plans ) => `a.is-${ plan.toLowerCase() }-plan.is-current-plan:visible`, |
|
|
spotlightPlan: '.plan-features-2023-grid__plan-spotlight', |
|
|
|
|
|
myPlanTitle: ( planName: Plans ) => `.my-plan-card__title:has-text("${ planName }")`, |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class PlansPage { |
|
|
private page: Page; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page ) { |
|
|
this.page = page; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async visit( target: PlansPageTab, siteSlug: string ): Promise< void > { |
|
|
const sanitized = target.toLowerCase().replace( ' ', '-' ); |
|
|
|
|
|
if ( target === 'My Plan' ) { |
|
|
await this.page.goto( getCalypsoURL( `plans/${ sanitized }/${ siteSlug }` ) ); |
|
|
} |
|
|
|
|
|
if ( target === 'Plans' ) { |
|
|
await this.page.goto( getCalypsoURL( `plans/${ siteSlug }` ) ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectAddOn( plan: Plans, addOn: string ): Promise< void > { |
|
|
const combobox = this.page.locator( selectors.addOnCombobox( plan ) ); |
|
|
|
|
|
const comboboxSelect = combobox.locator( selectors.addOnComboboxButton ); |
|
|
await comboboxSelect.first().click(); |
|
|
|
|
|
const comboboxOption = combobox.locator( |
|
|
selectors.addOnComboboxOption( `50 GB + ${ addOn }` ) |
|
|
); |
|
|
await comboboxOption.first().click(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectPlan( plan: Plans ): Promise< void > { |
|
|
const locator = this.page.locator( selectors.selectPlanButton( plan ) ); |
|
|
|
|
|
|
|
|
await locator.first().click(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectModalUpsellPlan( plan: Plans ): Promise< void > { |
|
|
if ( plan !== 'Free' && plan !== 'Personal' ) { |
|
|
throw Error( `Unsupported plan to be selected in modal upsell: ${ plan }` ); |
|
|
} |
|
|
|
|
|
const locator = this.page.locator( selectors.selectModalUpsellPlanButton( plan ) ); |
|
|
|
|
|
await locator.first().click(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async validateActivePlan( expectedPlan: Plans ): Promise< void > { |
|
|
await this.page.locator( selectors.spotlightPlan ).getByText( expectedPlan ).waitFor(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickManagePlan(): Promise< void > { |
|
|
await this.page.click( selectors.managePlanButton ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async validateActiveTab( expectedTab: PlansPageTab ): Promise< void > { |
|
|
|
|
|
|
|
|
|
|
|
const currentSelectedLocator = this.page.locator( |
|
|
selectors.activeNavigationTab( expectedTab ) |
|
|
); |
|
|
if ( envVariables.VIEWPORT_NAME === 'mobile' ) { |
|
|
await currentSelectedLocator.waitFor( { state: 'hidden' } ); |
|
|
} else { |
|
|
await currentSelectedLocator.waitFor(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickTab( targetTab: PlansPageTab ): Promise< void > { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Promise.all( [ |
|
|
this.page.waitForLoadState( 'networkidle', { timeout: 20 * 1000 } ), |
|
|
this.page.waitForResponse( /.*active-promotions.*/ ), |
|
|
] ); |
|
|
await clickNavTab( this.page, targetTab, { force: true } ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickPlanActionButton( { |
|
|
plan, |
|
|
buttonText, |
|
|
}: { |
|
|
plan: Plans; |
|
|
buttonText: PlanActionButton; |
|
|
} ): Promise< void > { |
|
|
const selector = selectors.actionButton( { |
|
|
plan: plan, |
|
|
buttonText: buttonText, |
|
|
} ); |
|
|
|
|
|
await Promise.all( [ this.page.waitForNavigation(), this.page.click( selector ) ] ); |
|
|
} |
|
|
} |
|
|
|