Skip to content

Commit 8129a30

Browse files
committed
chore(e2e): Add test cases for billing buttons
1 parent 6c6f154 commit 8129a30

File tree

10 files changed

+117
-3
lines changed

10 files changed

+117
-3
lines changed

.changeset/legal-ants-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Add class `cl-planDetails-root` to the parent div element that containes the plan details drawer.

.changeset/little-seals-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/testing': patch
3+
---
4+
5+
Add `planDetails` to the page details object.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { SignedIn } from '@clerk/nextjs';
2+
import { CheckoutButton } from '@clerk/nextjs/experimental';
3+
4+
export default function Home() {
5+
return (
6+
<main>
7+
<SignedIn>
8+
<CheckoutButton
9+
planId='cplan_2wMjqdlza0hTJc4HLCoBwAiExhF'
10+
planPeriod='month'
11+
>
12+
Checkout Now
13+
</CheckoutButton>
14+
</SignedIn>
15+
</main>
16+
);
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PlanDetailsButton } from '@clerk/nextjs/experimental';
2+
3+
export default function Home() {
4+
return (
5+
<main>
6+
<PlanDetailsButton planId='cplan_2wMjqdlza0hTJc4HLCoBwAiExhF'>Plan details</PlanDetailsButton>
7+
</main>
8+
);
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { SubscriptionDetailsButton } from '@clerk/nextjs/experimental';
2+
3+
export default function Home() {
4+
return (
5+
<main>
6+
<SubscriptionDetailsButton>Subscription details</SubscriptionDetailsButton>
7+
</main>
8+
);
9+
}

integration/tests/pricing-table.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
2828
await expect(u.po.page.getByRole('heading', { name: 'Pro' })).toBeVisible();
2929
});
3030

31+
test('renders pricing details of a specific plan', async ({ page, context }) => {
32+
const u = createTestUtils({ app, page, context });
33+
await u.po.page.goToRelative('/billing/plan-details-btn');
34+
35+
await u.po.page.getByRole('button', { name: 'Plan details' }).click();
36+
37+
await u.po.planDetails.waitForMounted();
38+
const { root } = u.po.planDetails;
39+
await expect(root.getByRole('heading', { name: 'Plus' })).toBeVisible();
40+
await expect(root.getByText('$9.99')).toBeVisible();
41+
await expect(root.getByText('This is the Plus plan!')).toBeVisible();
42+
await expect(root.getByText('Feature One')).toBeVisible();
43+
await expect(root.getByText('First feature')).toBeVisible();
44+
await expect(root.getByText('Feature Two')).toBeVisible();
45+
await expect(root.getByText('Second feature')).toBeVisible();
46+
await expect(root.getByText('Feature Three')).toBeVisible();
47+
await expect(root.getByText('Third feature')).toBeVisible();
48+
});
49+
3150
test('when signed out, clicking subscribe button navigates to sign in page', async ({ page, context }) => {
3251
const u = createTestUtils({ app, page, context });
3352
await u.po.page.goToRelative('/pricing-table');
@@ -64,6 +83,18 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
6483
await expect(u.po.page.getByText('Checkout')).toBeVisible();
6584
});
6685

86+
test('when signed in, clicking checkout button open checkout drawer', async ({ page, context }) => {
87+
const u = createTestUtils({ app, page, context });
88+
await u.po.signIn.goTo();
89+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
90+
await u.po.page.goToRelative('/billing/checkout-btn');
91+
92+
await u.po.page.getByRole('button', { name: 'Checkout Now' }).click();
93+
await u.po.checkout.waitForMounted();
94+
await u.po.page.getByText(/^Checkout$/).click();
95+
await u.po.checkout.fillTestCard();
96+
});
97+
6798
test('can subscribe to a plan', async ({ page, context }) => {
6899
const u = createTestUtils({ app, page, context });
69100
await u.po.signIn.goTo();
@@ -86,6 +117,22 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
86117
}
87118
});
88119

120+
test('Displays subscription details drawer', async ({ page, context }) => {
121+
const u = createTestUtils({ app, page, context });
122+
await u.po.signIn.goTo();
123+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
124+
await u.po.page.goToRelative('/billing/subscription-details-btn');
125+
126+
await u.po.page.getByRole('button', { name: 'Subscription details' }).click();
127+
128+
await u.po.subscriptionDetails.waitForMounted();
129+
await expect(u.po.page.getByText('Plus')).toBeVisible();
130+
await expect(u.po.page.getByText('Subscription details')).toBeVisible();
131+
await expect(u.po.page.getByText('Current billing cycle')).toBeVisible();
132+
await expect(u.po.page.getByText('Next payment on')).toBeVisible();
133+
await expect(u.po.page.getByText('Next payment amount')).toBeVisible();
134+
});
135+
89136
test('can upgrade to a new plan with saved card', async ({ page, context }) => {
90137
const u = createTestUtils({ app, page, context });
91138
await u.po.signIn.goTo();

packages/clerk-js/src/ui/components/Plans/PlanDetails.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
Col,
2121
descriptors,
2222
Flex,
23+
Flow,
2324
Heading,
2425
localizationKeys,
2526
Span,
@@ -30,9 +31,13 @@ import {
3031

3132
export const PlanDetails = (props: __internal_PlanDetailsProps) => {
3233
return (
33-
<Drawer.Content>
34-
<PlanDetailsInternal {...props} />
35-
</Drawer.Content>
34+
<Flow.Root flow='planDetails'>
35+
<Flow.Part>
36+
<Drawer.Content>
37+
<PlanDetailsInternal {...props} />
38+
</Drawer.Content>
39+
</Flow.Part>
40+
</Flow.Root>
3641
);
3742
};
3843

packages/clerk-js/src/ui/elements/contexts/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export type FlowMetadata = {
100100
| 'apiKeys'
101101
| 'oauthConsent'
102102
| 'subscriptionDetails'
103+
| 'subscriptionDetails'
103104
| 'taskChooseOrganization';
104105
part?:
105106
| 'start'

packages/testing/src/playwright/unstable/page-objects/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createExpectPageObject } from './expect';
88
import { createImpersonationPageObject } from './impersonation';
99
import { createKeylessPopoverPageObject } from './keylessPopover';
1010
import { createOrganizationSwitcherComponentPageObject } from './organizationSwitcher';
11+
import { createPlanDetailsPageObject } from './planDetails';
1112
import { createPricingTablePageObject } from './pricingTable';
1213
import { createSessionTaskComponentPageObject } from './sessionTask';
1314
import { createSignInComponentPageObject } from './signIn';
@@ -50,5 +51,6 @@ export const createPageObjects = ({
5051
waitlist: createWaitlistComponentPageObject(testArgs),
5152
apiKeys: createAPIKeysComponentPageObject(testArgs),
5253
subscriptionDetails: createSubscriptionDetailsPageObject(testArgs),
54+
planDetails: createPlanDetailsPageObject(testArgs),
5355
};
5456
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { EnhancedPage } from './app';
2+
import { common } from './common';
3+
4+
export const createPlanDetailsPageObject = (testArgs: { page: EnhancedPage }) => {
5+
const { page } = testArgs;
6+
const self = {
7+
...common(testArgs),
8+
waitForMounted: (selector = '.cl-planDetails-root') => {
9+
return page.waitForSelector(selector, { state: 'attached' });
10+
},
11+
root: page.locator('.cl-planDetails-root'),
12+
};
13+
return self;
14+
};

0 commit comments

Comments
 (0)