|
|
import { Page } from 'playwright'; |
|
|
|
|
|
type CancelReason = 'Another reason…'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function cancelSubscriptionFlow( page: Page ) { |
|
|
await page.getByRole( 'button', { name: 'Submit' } ).click(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function cancelPurchaseFlow( |
|
|
page: Page, |
|
|
feedback: { |
|
|
reason: CancelReason; |
|
|
customReasonText: string; |
|
|
} |
|
|
) { |
|
|
await page |
|
|
.getByRole( 'combobox', { name: 'Why would you like to cancel?' } ) |
|
|
.selectOption( feedback.reason ); |
|
|
|
|
|
await page |
|
|
.getByRole( 'textbox', { name: 'Can you please specify?' } ) |
|
|
.fill( feedback.customReasonText ); |
|
|
|
|
|
await page.getByRole( 'button', { name: 'Submit' } ).click(); |
|
|
|
|
|
await Promise.all( [ |
|
|
page.waitForNavigation( { timeout: 30 * 1000 } ), |
|
|
page.getByRole( 'button', { name: 'Submit' } ).click(), |
|
|
] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function cancelAtomicPurchaseFlow( |
|
|
page: Page, |
|
|
feedback: { |
|
|
reason: CancelReason; |
|
|
customReasonText: string; |
|
|
} |
|
|
) { |
|
|
await page |
|
|
.getByRole( 'combobox', { name: 'Why would you like to cancel?' } ) |
|
|
.selectOption( feedback.reason ); |
|
|
|
|
|
await page |
|
|
.getByRole( 'textbox', { name: 'Can you please specify?' } ) |
|
|
.fill( feedback.customReasonText ); |
|
|
|
|
|
|
|
|
const firstButton = page |
|
|
.getByRole( 'button', { name: 'Submit' } ) |
|
|
.or( page.getByRole( 'button', { name: 'Continue' } ) ); |
|
|
await firstButton.waitFor( { state: 'visible' } ); |
|
|
await firstButton.click(); |
|
|
|
|
|
|
|
|
await page |
|
|
.getByRole( 'combobox', { name: 'Where is your next adventure taking you?' } ) |
|
|
.selectOption( "I'm staying here and using the free plan." ); |
|
|
|
|
|
|
|
|
const secondButton = page |
|
|
.getByRole( 'button', { name: 'Submit' } ) |
|
|
.or( page.getByRole( 'button', { name: 'Continue' } ) ); |
|
|
await secondButton.waitFor( { state: 'visible' } ); |
|
|
await secondButton.click(); |
|
|
|
|
|
const finalButton = page |
|
|
.getByRole( 'button', { name: 'Submit' } ) |
|
|
.or( page.getByRole( 'button', { name: 'Continue' } ) ); |
|
|
|
|
|
await Promise.all( [ |
|
|
page.waitForNavigation( { timeout: 30 * 1000 } ), |
|
|
finalButton.waitFor( { state: 'visible' } ), |
|
|
|
|
|
page.waitForFunction( |
|
|
() => { |
|
|
const button = document.querySelector( 'button[class*="is-primary"]' ); |
|
|
return button && ! button.hasAttribute( 'disabled' ); |
|
|
}, |
|
|
{ timeout: 10000 } |
|
|
), |
|
|
] ); |
|
|
} |
|
|
|