-
Notifications
You must be signed in to change notification settings - Fork 373
chore(clerk-js,types): Update PricingTable with trial info #6493
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
Merged
panteliselef
merged 8 commits into
main
from
elef/com-1121-update-pricingtable-plan-card-with-free-trial-info-status
Aug 12, 2025
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b228074
chore(clerk-js,types): Update PricingTable with trial info
panteliselef 0388c4a
respect fapi
panteliselef 11e6953
add tests
panteliselef 1cb9c20
Merge branch 'refs/heads/main' into elef/com-1121-update-pricingtable…
panteliselef 4b3d116
patch
panteliselef 13f3e53
add localizations
panteliselef eb68681
patch type in react test
panteliselef ae0d7e6
Merge branch 'main' into elef/com-1121-update-pricingtable-plan-card-…
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@clerk/clerk-js': minor | ||
'@clerk/types': minor | ||
--- | ||
|
||
Update billing resources with trial properties. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@clerk/localizations': minor | ||
'@clerk/clerk-js': minor | ||
'@clerk/types': minor | ||
--- | ||
|
||
Update PricingTable with trial info. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import { render, waitFor } from '../../../../testUtils'; | ||
import { bindCreateFixtures } from '../../../utils/test/createFixtures'; | ||
import { PricingTable } from '..'; | ||
|
||
const { createFixtures } = bindCreateFixtures('PricingTable'); | ||
|
||
describe('PricingTable - trial info', () => { | ||
const trialPlan = { | ||
id: 'plan_trial', | ||
name: 'Pro', | ||
amount: 2000, | ||
amountFormatted: '20.00', | ||
annualAmount: 20000, | ||
annualAmountFormatted: '200.00', | ||
annualMonthlyAmount: 1667, | ||
annualMonthlyAmountFormatted: '16.67', | ||
currencySymbol: '$', | ||
description: 'Pro plan with trial', | ||
hasBaseFee: true, | ||
isRecurring: true, | ||
currency: 'USD', | ||
isDefault: false, | ||
forPayerType: 'user', | ||
publiclyVisible: true, | ||
slug: 'pro', | ||
avatarUrl: '', | ||
features: [] as any[], | ||
freeTrialEnabled: true, | ||
freeTrialDays: 14, | ||
__internal_toSnapshot: jest.fn(), | ||
pathRoot: '', | ||
reload: jest.fn(), | ||
} as const; | ||
|
||
it('shows footer notice with trial end date when active subscription is in free trial', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(f => { | ||
f.withUser({ email_addresses: ['[email protected]'] }); | ||
}); | ||
|
||
// Provide empty props to the PricingTable context | ||
props.setProps({}); | ||
|
||
fixtures.clerk.billing.getPlans.mockResolvedValue({ data: [trialPlan as any], total_count: 1 }); | ||
fixtures.clerk.billing.getSubscription.mockResolvedValue({ | ||
id: 'sub_1', | ||
status: 'active', | ||
activeAt: new Date('2021-01-01'), | ||
createdAt: new Date('2021-01-01'), | ||
nextPayment: null, | ||
pastDueAt: null, | ||
updatedAt: null, | ||
subscriptionItems: [ | ||
{ | ||
id: 'si_1', | ||
plan: trialPlan, | ||
createdAt: new Date('2021-01-01'), | ||
paymentSourceId: 'src_1', | ||
pastDueAt: null, | ||
canceledAt: null, | ||
periodStart: new Date('2021-01-01'), | ||
periodEnd: new Date('2021-01-15'), | ||
planPeriod: 'month' as const, | ||
status: 'active' as const, | ||
isFreeTrial: true, | ||
cancel: jest.fn(), | ||
pathRoot: '', | ||
reload: jest.fn(), | ||
}, | ||
], | ||
pathRoot: '', | ||
reload: jest.fn(), | ||
}); | ||
|
||
const { findByRole, getByText, userEvent } = render(<PricingTable />, { wrapper }); | ||
|
||
// Wait for the plan to appear | ||
await findByRole('heading', { name: 'Pro' }); | ||
|
||
// Default period is annual in mounted mode; switch to monthly to match the subscription | ||
const periodSwitch = await findByRole('switch', { name: /billed annually/i }); | ||
await userEvent.click(periodSwitch); | ||
|
||
await waitFor(() => { | ||
// Trial footer notice uses badge__trialEndsAt localization (short date format) | ||
expect(getByText('Trial ends Jan 15, 2021')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
it('shows CTA "Start N-day free trial" when eligible and plan has trial', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(f => { | ||
f.withUser({ email_addresses: ['[email protected]'] }); | ||
}); | ||
|
||
// Provide empty props to the PricingTable context | ||
props.setProps({}); | ||
|
||
fixtures.clerk.billing.getPlans.mockResolvedValue({ data: [trialPlan as any], total_count: 1 }); | ||
fixtures.clerk.billing.getSubscription.mockResolvedValue({ | ||
id: 'sub_top', | ||
status: 'active', | ||
activeAt: new Date('2021-01-01'), | ||
createdAt: new Date('2021-01-01'), | ||
nextPayment: null, | ||
pastDueAt: null, | ||
updatedAt: null, | ||
eligibleForFreeTrial: true, | ||
// No subscription items for the trial plan yet | ||
subscriptionItems: [], | ||
pathRoot: '', | ||
reload: jest.fn(), | ||
}); | ||
|
||
const { getByRole, getByText } = render(<PricingTable />, { wrapper }); | ||
|
||
await waitFor(() => { | ||
expect(getByRole('heading', { name: 'Pro' })).toBeVisible(); | ||
// Button text from Plans.buttonPropsForPlan via freeTrialOr | ||
expect(getByText('Start 14-day free trial')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
it('shows CTA "Start N-day free trial" when user is signed out and plan has trial', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(); | ||
|
||
// Provide empty props to the PricingTable context | ||
props.setProps({}); | ||
|
||
fixtures.clerk.billing.getPlans.mockResolvedValue({ data: [trialPlan as any], total_count: 1 }); | ||
// When signed out, getSubscription should throw or return empty response | ||
fixtures.clerk.billing.getSubscription.mockRejectedValue(new Error('Unauthenticated')); | ||
|
||
const { getByRole, getByText } = render(<PricingTable />, { wrapper }); | ||
|
||
await waitFor(() => { | ||
expect(getByRole('heading', { name: 'Pro' })).toBeVisible(); | ||
// Signed out users should see free trial CTA when plan has trial enabled | ||
expect(getByText('Start 14-day free trial')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
it('shows CTA "Subscribe" when user is signed out and plan has no trial', async () => { | ||
const { wrapper, fixtures, props } = await createFixtures(); | ||
|
||
const nonTrialPlan = { | ||
...trialPlan, | ||
id: 'plan_no_trial', | ||
name: 'Basic', | ||
freeTrialEnabled: false, | ||
freeTrialDays: 0, | ||
}; | ||
|
||
// Provide empty props to the PricingTable context | ||
props.setProps({}); | ||
|
||
fixtures.clerk.billing.getPlans.mockResolvedValue({ data: [nonTrialPlan as any], total_count: 1 }); | ||
// When signed out, getSubscription should throw or return empty response | ||
fixtures.clerk.billing.getSubscription.mockRejectedValue(new Error('Unauthenticated')); | ||
|
||
const { getByRole, getByText } = render(<PricingTable />, { wrapper }); | ||
|
||
await waitFor(() => { | ||
expect(getByRole('heading', { name: 'Basic' })).toBeVisible(); | ||
// Signed out users should see regular "Subscribe" for non-trial plans | ||
expect(getByText('Subscribe')).toBeVisible(); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.