-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: refactor and rename paidplancard #2367
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8578fd3
feat: refactor and rename paidplancard
adrian-codecov a917d7e
quick detail
adrian-codecov b2fb4c3
Merge branch 'main' into 727-team-card-for-paid-version
adrian-codecov b625004
Merge branch 'main' into 727-team-card-for-paid-version
adrian-codecov 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 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 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 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
231 changes: 231 additions & 0 deletions
231
...ages/PlanPage/subRoutes/CurrentOrgPlan/CurrentPlanCard/PaidPlanCard/PaidPlanCard.spec.jsx
This file contains 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,231 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen } from '@testing-library/react' | ||
import { graphql, rest } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
import { MemoryRouter, Route } from 'react-router-dom' | ||
|
||
import { TrialStatuses } from 'services/account' | ||
|
||
import PaidPlanCard from './PaidPlanCard' | ||
|
||
jest.mock( | ||
'../shared/ActionsBilling/ActionsBilling', | ||
() => () => 'Actions Billing' | ||
) | ||
jest.mock('../shared/PlanPricing', () => () => 'Plan Pricing') | ||
jest.mock('shared/plan/BenefitList', () => () => 'BenefitsList') | ||
jest.mock( | ||
'shared/plan/ScheduledPlanDetails', | ||
() => () => 'Scheduled Plan Details' | ||
) | ||
|
||
const mockProPlan = { | ||
marketingName: 'Pro', | ||
value: 'users-pr-inappm', | ||
billingRate: 'monthly', | ||
baseUnitPrice: 0, | ||
benefits: ['Unlimited public repositories', 'Unlimited private repositories'], | ||
planUserCount: 5, | ||
monthlyUploadLimit: null, | ||
trialStatus: TrialStatuses.CANNOT_TRIAL, | ||
trialStartDate: '', | ||
trialEndDate: '', | ||
trialTotalDays: 0, | ||
pretrialUsersCount: 0, | ||
} | ||
|
||
const mockTeamPlan = { | ||
marketingName: 'Team', | ||
value: 'users-teamm', | ||
billingRate: 'monthly', | ||
baseUnitPrice: 123, | ||
benefits: ['Team benefits', 'Unlimited private repositories'], | ||
planUserCount: 8, | ||
monthlyUploadLimit: null, | ||
trialStatus: TrialStatuses.CANNOT_TRIAL, | ||
trialStartDate: '', | ||
trialEndDate: '', | ||
trialTotalDays: 0, | ||
pretrialUsersCount: 0, | ||
} | ||
|
||
const mockScheduleDetail = { | ||
id: 'test_sub_sched_123', | ||
scheduled_phase: { | ||
plan: 'annually', | ||
quantity: 5, | ||
start_date: 1724258944, | ||
}, | ||
} | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { queries: { retry: false } }, | ||
}) | ||
|
||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter initialEntries={['/plan/bb/critical-role']}> | ||
<Route path="/plan/:provider/:owner">{children}</Route> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
) | ||
|
||
const server = setupServer() | ||
|
||
beforeAll(() => server.listen()) | ||
afterEach(() => { | ||
queryClient.clear() | ||
server.resetHandlers() | ||
}) | ||
afterAll(() => server.close()) | ||
|
||
describe('PaidPlanCard', () => { | ||
function setup( | ||
{ hasScheduledDetails = false, plan = mockProPlan } = { | ||
hasScheduledDetails: false, | ||
plan: mockProPlan, | ||
} | ||
) { | ||
server.use( | ||
rest.get( | ||
'/internal/bb/critical-role/account-details/', | ||
(req, res, ctx) => { | ||
if (hasScheduledDetails) { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ scheduleDetail: mockScheduleDetail }) | ||
) | ||
} else { | ||
return res(ctx.status(200), ctx.json({})) | ||
} | ||
} | ||
), | ||
graphql.query('GetPlanData', (req, res, ctx) => | ||
res( | ||
ctx.status(200), | ||
ctx.data({ | ||
owner: { | ||
plan, | ||
}, | ||
}) | ||
) | ||
) | ||
) | ||
} | ||
|
||
describe('When rendered for a pro plan', () => { | ||
beforeEach(() => { | ||
setup({ plan: mockProPlan }) | ||
}) | ||
|
||
it('renders the plan marketing name', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const planValue = await screen.findByText(/Pro plan/) | ||
expect(planValue).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the benefits', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const benefitsList = await screen.findByText(/BenefitsList/) | ||
expect(benefitsList).toBeInTheDocument() | ||
}) | ||
|
||
it('renders seats number', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const seats = await screen.findByText(/plan has 5 seats/) | ||
expect(seats).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the plan pricing', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const planPricing = await screen.findByText(/Plan Pricing/) | ||
expect(planPricing).toBeInTheDocument() | ||
}) | ||
|
||
it('renders actions billing button', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const actionsBilling = await screen.findByText(/Actions Billing/) | ||
expect(actionsBilling).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe('When rendered for a team plan', () => { | ||
beforeEach(() => { | ||
setup({ plan: mockTeamPlan }) | ||
}) | ||
|
||
it('renders the plan marketing name', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const planValue = await screen.findByText(/Team plan/) | ||
expect(planValue).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the benefits', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const benefitsList = await screen.findByText(/BenefitsList/) | ||
expect(benefitsList).toBeInTheDocument() | ||
}) | ||
|
||
it('renders seats number', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const seats = await screen.findByText(/plan has 8 seats/) | ||
expect(seats).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the plan pricing', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const planPricing = await screen.findByText(/Plan Pricing/) | ||
expect(planPricing).toBeInTheDocument() | ||
}) | ||
|
||
it('renders actions billing button', async () => { | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const actionsBilling = await screen.findByText(/Actions Billing/) | ||
expect(actionsBilling).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe('When rendered with scheduled details', () => { | ||
it('renders the scheduled details', async () => { | ||
setup({ hasScheduledDetails: true }) | ||
render(<PaidPlanCard />, { | ||
wrapper, | ||
}) | ||
|
||
const scheduledPlanDetails = await screen.findByText( | ||
/Scheduled Plan Details/ | ||
) | ||
expect(scheduledPlanDetails).toBeInTheDocument() | ||
}) | ||
}) | ||
}) |
1 change: 1 addition & 0 deletions
1
src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentPlanCard/PaidPlanCard/index.js
This file contains 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 @@ | ||
export { default } from './PaidPlanCard' |
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.
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.
Are you able to provide any default values here if these values are possibly null?
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.
So all of these can't be nullable as per our backend/zod schema, so we should be fine here.
But otherwise, for a scenario that applies, what default value would work here? It almost feels like if we didn't have all of these that we shouldn't show the card, or have designs reflect that state (but to be clear, they're non-nullable here)
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.
Ah I see, the optional chaining made me think they were possibly nullable