-
Notifications
You must be signed in to change notification settings - Fork 241
feat(custom): implement SubscriptionTable scaffolding and register global module exports #1660
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
Open
abhinavkdeval08-design
wants to merge
17
commits into
layer5io:master
Choose a base branch
from
abhinavkdeval08-design:feature/subscription-comparison-table
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b7298c4
feat: implement SubscriptionTable scaffolding and register global mod…
abhinavkdeval08-design 812e1ac
feat: implement SubscriptionTable scaffolding and register global mod…
abhinavkdeval08-design 43af05b
refactor: resolve bot feedback for SubscriptionTable
abhinavkdeval08-design 7d6b915
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design 9ed80d4
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design f8c8be8
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design 1b53031
Merge branch 'master' into feature/subscription-comparison-table
hortison ccda099
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design 06e9bb9
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design 0034b96
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design 55cfd16
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design 191ae3b
refactor: resolve bot feedback on responsive overflow, tokens, and ac…
abhinavkdeval08-design d1d1835
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design efd53ac
feat: add root exports, default export and unit tests for Subscriptio…
abhinavkdeval08-design 111f843
Merge branch 'master' into feature/subscription-comparison-table
abhinavkdeval08-design 171f8be
refactor(SubscriptionTable): switch to standard typography variants a…
abhinavkdeval08-design 26b15e0
refactor(SubscriptionTable): simplify custom barrel export and assert…
abhinavkdeval08-design 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,64 @@ | ||
| import React from 'react'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import { SubscriptionTable, PlanFeature } from './SubscriptionTable'; | ||
|
|
||
| const mockFeatures: PlanFeature[] = [ | ||
| { | ||
| featureName: 'Cloud Storage', | ||
| freePlan: '5GB', | ||
| teamPlan: '50GB', | ||
| enterprisePlan: 'Unlimited' | ||
| }, | ||
| { | ||
| featureName: 'Priority Support', | ||
| freePlan: false, | ||
| teamPlan: true, | ||
| enterprisePlan: true | ||
| } | ||
| ]; | ||
|
|
||
| describe('SubscriptionTable Component', () => { | ||
| it('renders table title and feature rows correctly', () => { | ||
| render(<SubscriptionTable title="Custom Pricing Table" features={mockFeatures} />); | ||
| expect(screen.getByText('Custom Pricing Table')).toBeInTheDocument(); | ||
| expect(screen.getByText('Cloud Storage')).toBeInTheDocument(); | ||
| expect(screen.getByText('Priority Support')).toBeInTheDocument(); | ||
| expect(screen.getByText('5GB')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders boolean indicators with accessibility labels', () => { | ||
| render(<SubscriptionTable features={mockFeatures} />); | ||
| // Assert actual accessible text labels instead of test IDs | ||
| expect(screen.getAllByLabelText('Included').length).toBeGreaterThan(0); | ||
| expect(screen.getAllByLabelText('Not included').length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('calls onPlanSelect when action buttons are clicked', () => { | ||
| const handlePlanSelect = jest.fn(); | ||
| render(<SubscriptionTable features={mockFeatures} onPlanSelect={handlePlanSelect} />); | ||
|
|
||
| fireEvent.click(screen.getByText('Get Started')); | ||
| expect(handlePlanSelect).toHaveBeenCalledWith('free'); | ||
|
|
||
| fireEvent.click(screen.getByText('Upgrade')); | ||
| expect(handlePlanSelect).toHaveBeenCalledWith('team'); | ||
|
|
||
| fireEvent.click(screen.getByText('Contact Us')); | ||
| expect(handlePlanSelect).toHaveBeenCalledWith('enterprise'); | ||
| }); | ||
|
|
||
| it('renders custom labels when passed via props', () => { | ||
| render( | ||
| <SubscriptionTable | ||
| features={mockFeatures} | ||
| featuresLabel="Key Capabilities" | ||
| freePlanLabel="Starter" | ||
| freePlanButtonLabel="Join Now" | ||
| /> | ||
| ); | ||
| expect(screen.getByText('Key Capabilities')).toBeInTheDocument(); | ||
| expect(screen.getByText('Starter')).toBeInTheDocument(); | ||
| expect(screen.getByText('Join Now')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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,145 @@ | ||
| import CheckIcon from '@mui/icons-material/Check'; | ||
| import CloseIcon from '@mui/icons-material/Close'; | ||
| import { Box, Button, Table, TableBody, TableHead, TableRow, Typography } from '@mui/material'; | ||
| import React from 'react'; | ||
| import { FeatureHeaderCell, StyledHeaderRow, StyledTableCell, StyledTableContainer } from './style'; | ||
|
|
||
| export interface PlanFeature { | ||
| featureName: string; | ||
| freePlan: boolean | string; | ||
| teamPlan: boolean | string; | ||
| enterprisePlan: boolean | string; | ||
| } | ||
|
|
||
| export interface SubscriptionTableProps { | ||
| title?: string; | ||
| features?: PlanFeature[]; | ||
| onPlanSelect?: (planType: 'free' | 'team' | 'enterprise') => void; | ||
| featuresLabel?: string; | ||
| freePlanLabel?: string; | ||
| freePlanButtonLabel?: string; | ||
| teamPlanLabel?: string; | ||
| teamPlanButtonLabel?: string; | ||
| enterprisePlanLabel?: string; | ||
| enterprisePlanButtonLabel?: string; | ||
| } | ||
|
|
||
| export const SubscriptionTable: React.FC<SubscriptionTableProps> = ({ | ||
| title = 'Subscription Plans Comparison', | ||
| features = [], | ||
| onPlanSelect, | ||
| featuresLabel = 'Features', | ||
| freePlanLabel = 'Free Plan', | ||
| freePlanButtonLabel = 'Get Started', | ||
| teamPlanLabel = 'Team Plan', | ||
| teamPlanButtonLabel = 'Upgrade', | ||
| enterprisePlanLabel = 'Enterprise Plan', | ||
| enterprisePlanButtonLabel = 'Contact Us' | ||
| }) => { | ||
|
abhinavkdeval08-design marked this conversation as resolved.
|
||
| const renderValue = (value: boolean | string) => { | ||
| if (typeof value === 'boolean') { | ||
| return value ? ( | ||
| <CheckIcon color="success" data-testid="check-icon" titleAccess="Included" aria-label="Included" /> | ||
| ) : ( | ||
| <CloseIcon color="error" data-testid="close-icon" titleAccess="Not included" aria-label="Not included" /> | ||
| ); | ||
| } | ||
| return ( | ||
| <Typography variant="body2" fontWeight="fontWeightMedium"> | ||
| {value} | ||
| </Typography> | ||
| ); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| return ( | ||
| <Box sx={{ width: '100%', my: 4 }}> | ||
| {title && ( | ||
| <Typography | ||
| variant="h4" | ||
| component="h2" | ||
| sx={{ | ||
| mb: 3, | ||
| fontWeight: 'fontWeightBold' | ||
| }} | ||
| > | ||
| {title} | ||
| </Typography> | ||
| )} | ||
| <StyledTableContainer> | ||
| <Table sx={{ minWidth: 650 }} aria-label="subscription comparison table"> | ||
| <TableHead> | ||
| <StyledHeaderRow> | ||
| <StyledTableCell> | ||
| <Typography variant="subtitle1" fontWeight="fontWeightBold" component="span"> | ||
| {featuresLabel} | ||
| </Typography> | ||
| </StyledTableCell> | ||
| <StyledTableCell align="center"> | ||
| <Typography variant="subtitle1" fontWeight="fontWeightBold" component="span"> | ||
| {freePlanLabel} | ||
| </Typography> | ||
| <Box sx={{ mt: 1 }}> | ||
| <Button size="small" variant="outlined" onClick={() => onPlanSelect?.('free')}> | ||
| {freePlanButtonLabel} | ||
| </Button> | ||
| </Box> | ||
| </StyledTableCell> | ||
| <StyledTableCell align="center"> | ||
| <Typography variant="subtitle1" fontWeight="fontWeightBold" component="span"> | ||
| {teamPlanLabel} | ||
| </Typography> | ||
| <Box sx={{ mt: 1 }}> | ||
| <Button | ||
| size="small" | ||
| variant="contained" | ||
| color="primary" | ||
| onClick={() => onPlanSelect?.('team')} | ||
| > | ||
| {teamPlanButtonLabel} | ||
| </Button> | ||
| </Box> | ||
| </StyledTableCell> | ||
| <StyledTableCell align="center"> | ||
| <Typography variant="subtitle1" fontWeight="fontWeightBold" component="span"> | ||
| {enterprisePlanLabel} | ||
| </Typography> | ||
| <Box sx={{ mt: 1 }}> | ||
| <Button | ||
| size="small" | ||
| variant="contained" | ||
| color="secondary" | ||
| onClick={() => onPlanSelect?.('enterprise')} | ||
| > | ||
| {enterprisePlanButtonLabel} | ||
| </Button> | ||
| </Box> | ||
| </StyledTableCell> | ||
| </StyledHeaderRow> | ||
| </TableHead> | ||
| <TableBody> | ||
| {features.map((row) => ( | ||
| <TableRow | ||
| key={row.featureName} | ||
| sx={{ | ||
| '&:last-child td, &:last-child th': { border: 0 }, | ||
| '&:hover': { backgroundColor: 'action.hover' } | ||
| }} | ||
| > | ||
| <FeatureHeaderCell component="th" scope="row"> | ||
| {row.featureName} | ||
| </FeatureHeaderCell> | ||
| <StyledTableCell align="center">{renderValue(row.freePlan)}</StyledTableCell> | ||
| <StyledTableCell align="center">{renderValue(row.teamPlan)}</StyledTableCell> | ||
| <StyledTableCell align="center">{renderValue(row.enterprisePlan)}</StyledTableCell> | ||
| </TableRow> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| </StyledTableContainer> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| SubscriptionTable.displayName = 'SubscriptionTable'; | ||
|
|
||
| export default SubscriptionTable; | ||
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 @@ | ||
| export * from './SubscriptionTable'; |
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,26 @@ | ||
| import { Paper, TableCell, TableRow } from '@mui/material'; | ||
| import { styled } from '@mui/material/styles'; | ||
|
|
||
| export const StyledTableContainer = styled(Paper)(({ theme }) => ({ | ||
| borderRadius: theme.shape.borderRadius * 2, | ||
| overflowX: 'auto', | ||
| overflowY: 'hidden', | ||
| boxShadow: theme.shadows[2], | ||
| border: `1px solid ${theme.palette.divider}` | ||
| })); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| export const StyledHeaderRow = styled(TableRow)(({ theme }) => ({ | ||
| backgroundColor: theme.palette.mode === 'light' ? theme.palette.grey[50] : theme.palette.grey[900] | ||
| })); | ||
|
|
||
| export const StyledTableCell = styled(TableCell)(({ theme }) => ({ | ||
| fontFamily: theme.typography.fontFamily, | ||
| borderColor: theme.palette.divider, | ||
| fontWeight: 500 | ||
| })); | ||
|
|
||
| export const FeatureHeaderCell = styled(StyledTableCell)(({ theme }) => ({ | ||
| fontFamily: theme.typography.fontFamily, | ||
| fontWeight: 700, | ||
| color: theme.palette.text.primary | ||
| })); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
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.
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.