-
Notifications
You must be signed in to change notification settings - Fork 403
feat(testing): Add checkout and pricingTable page objects #5776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2251685
26eef5d
602987c
e32ad06
19a137d
c852a00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/testing': patch | ||
| --- | ||
|
|
||
| Add `checkout` and `pricingTable` page objects. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import type { EnhancedPage } from './app'; | ||
| import { common } from './common'; | ||
|
|
||
| export const createCheckoutPageObject = (testArgs: { page: EnhancedPage }) => { | ||
| const { page } = testArgs; | ||
| const self = { | ||
| ...common(testArgs), | ||
| waitForMounted: (selector = '.cl-checkout-root') => { | ||
| return page.waitForSelector(selector, { state: 'attached' }); | ||
| }, | ||
| fillTestCard: async () => { | ||
| await self.fillCard({ | ||
| number: '4242424242424242', | ||
| expiration: '1234', | ||
| cvc: '123', | ||
| country: 'United States', | ||
| zip: '12345', | ||
| }); | ||
| }, | ||
| fillCard: async (card: { number: string; expiration: string; cvc: string; country: string; zip: string }) => { | ||
| const frame = page.frameLocator('iframe[src*="elements-inner-payment"]'); | ||
| await frame.getByLabel('Card number').fill(card.number); | ||
| await frame.getByLabel('Expiration date').fill(card.expiration); | ||
| await frame.getByLabel('Security code').fill(card.cvc); | ||
| await frame.getByLabel('Country').selectOption(card.country); | ||
| await frame.getByLabel('ZIP code').fill(card.zip); | ||
| }, | ||
| clickPayOrSubscribe: async () => { | ||
| await page.getByRole('button', { name: /subscribe|pay\s/i }).click(); | ||
| }, | ||
| clickAddPaymentMethod: async () => { | ||
| await page.getByRole('radio', { name: 'Add payment method' }).click(); | ||
| }, | ||
| clickPaymentMethods: async () => { | ||
| await page.getByRole('radio', { name: 'Payment Methods' }).click(); | ||
| }, | ||
| }; | ||
| return self; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import type { Page } from '@playwright/test'; | ||
|
|
||
| import { createAppPageObject } from './app'; | ||
| import { createCheckoutPageObject } from './checkout'; | ||
| import { createClerkPageObject } from './clerk'; | ||
| import { createExpectPageObject } from './expect'; | ||
| import { createImpersonationPageObject } from './impersonation'; | ||
| import { createKeylessPopoverPageObject } from './keylessPopover'; | ||
| import { createOrganizationSwitcherComponentPageObject } from './organizationSwitcher'; | ||
| import { createPricingTablePageObject } from './pricingTable'; | ||
| import { createSessionTaskComponentPageObject } from './sessionTask'; | ||
| import { createSignInComponentPageObject } from './signIn'; | ||
| import { createSignUpComponentPageObject } from './signUp'; | ||
|
|
@@ -30,10 +32,12 @@ export const createPageObjects = ({ | |
| return { | ||
| page: app, | ||
| clerk: createClerkPageObject(testArgs), | ||
| checkout: createCheckoutPageObject(testArgs), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dstaley since we only expose checkout as an internal component currently, shall we follow the pattern here as well ? We can drop the internal prefix later once, checkout is a standalone component.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think given that Checkout is intended to be a public component in the near future we're fine to leave this as just |
||
| expect: createExpectPageObject(testArgs), | ||
| impersonation: createImpersonationPageObject(testArgs), | ||
| keylessPopover: createKeylessPopoverPageObject(testArgs), | ||
| organizationSwitcher: createOrganizationSwitcherComponentPageObject(testArgs), | ||
| pricingTable: createPricingTablePageObject(testArgs), | ||
| sessionTask: createSessionTaskComponentPageObject(testArgs), | ||
| signIn: createSignInComponentPageObject(testArgs), | ||
| signUp: createSignUpComponentPageObject(testArgs), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { EnhancedPage } from './app'; | ||
| import { common } from './common'; | ||
|
|
||
| export const createPricingTablePageObject = (testArgs: { page: EnhancedPage }) => { | ||
| const { page } = testArgs; | ||
| const self = { | ||
| ...common(testArgs), | ||
| waitForMounted: (selector = '.cl-pricingTable-root') => { | ||
| return page.waitForSelector(selector, { state: 'attached' }); | ||
| }, | ||
| clickManageSubscription: async () => { | ||
| await page.getByText('Manage subscription').click(); | ||
| }, | ||
| clickResubscribe: async () => { | ||
| await page.getByText('Re-subscribe').click(); | ||
| }, | ||
| startCheckout: async ({ planSlug, shouldSwitch }: { planSlug: string; shouldSwitch?: boolean }) => { | ||
| const targetButtonName = | ||
| shouldSwitch === true ? 'Switch to this plan' : shouldSwitch === false ? 'Get started' : /get|switch/i; | ||
| await page.locator(`.cl-pricingTableCard__${planSlug}`).getByRole('button', { name: targetButtonName }).click(); | ||
| }, | ||
| }; | ||
| return self; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a super strong opinion, but shouldSwitch is not super obvious.
switchPlansmaybe? Again not super strong opinion here.