-
-
Notifications
You must be signed in to change notification settings - Fork 43
test(components): expand unit tests for 22 components from smoke to variant-complete #123
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
oyi77
wants to merge
4
commits into
akii09:main
Choose a base branch
from
oyi77:claude/pdfx-contribution-b9G87
base: main
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
4 commits
Select commit
Hold shift + click to select a range
9419681
test(www): expand coverage for layout primitives
claude 5235a7d
test(www): expand coverage for content components
claude ffa9ff4
test(www): expand coverage for page chrome components
claude eaa83d0
test(www): expand coverage for media and data components
claude 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
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
71 changes: 67 additions & 4 deletions
71
apps/www/src/registry/components/data-table/data-table.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 |
|---|---|---|
| @@ -1,11 +1,74 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { DataTable } from './data-table'; | ||
| import type { DataTableColumn } from './data-table.types'; | ||
|
|
||
| interface Row extends Record<string, unknown> { | ||
| name: string; | ||
| score: number; | ||
| status: string; | ||
| } | ||
|
|
||
| const columns: DataTableColumn<Row>[] = [ | ||
| { key: 'name', header: 'Name', align: 'left' }, | ||
| { key: 'score', header: 'Score', align: 'right', width: 80 }, | ||
| { key: 'status', header: 'Status', align: 'center' }, | ||
| ]; | ||
|
|
||
| const data: Row[] = [ | ||
| { name: 'Ada', score: 99, status: 'active' }, | ||
| { name: 'Grace', score: 88, status: 'active' }, | ||
| { name: 'Linus', score: 77, status: 'inactive' }, | ||
| ]; | ||
|
|
||
| describe('DataTable', () => { | ||
| it('renders without throwing', () => { | ||
| expect(() => DataTable({ columns: [], data: [] })).not.toThrow(); | ||
| it('renders with empty columns and data', () => { | ||
| expect(() => DataTable<Row>({ columns: [], data: [] })).not.toThrow(); | ||
| }); | ||
|
|
||
| it('renders with columns but no rows', () => { | ||
| expect(() => DataTable<Row>({ columns, data: [] })).not.toThrow(); | ||
| }); | ||
|
|
||
| it('renders with rows and all column aligns/widths', () => { | ||
| expect(() => DataTable<Row>({ columns, data })).not.toThrow(); | ||
| }); | ||
| it('accepts size prop', () => { | ||
| expect(() => DataTable({ columns: [], data: [], size: 'compact' })).not.toThrow(); | ||
|
|
||
| it('renders both size variants', () => { | ||
| expect(() => DataTable<Row>({ columns, data, size: 'default' })).not.toThrow(); | ||
| expect(() => DataTable<Row>({ columns, data, size: 'compact' })).not.toThrow(); | ||
| }); | ||
|
|
||
| it('honors stripe, noWrap, and style overrides', () => { | ||
| expect(() => | ||
| DataTable<Row>({ | ||
| columns, | ||
| data, | ||
| stripe: true, | ||
| noWrap: true, | ||
| style: { marginTop: 8 }, | ||
| }) | ||
| ).not.toThrow(); | ||
| }); | ||
|
|
||
| it('invokes custom cell render and footer render', () => { | ||
| const renderScore = (value: unknown) => | ||
| typeof value === 'number' ? `${value}%` : String(value ?? ''); | ||
| expect(() => | ||
| DataTable<Row>({ | ||
| columns: [ | ||
| { key: 'name', header: 'Name' }, | ||
| { key: 'score', header: 'Score', render: renderScore, renderFooter: renderScore }, | ||
| ], | ||
| data, | ||
| footer: { score: 264 }, | ||
| }) | ||
| ).not.toThrow(); | ||
| }); | ||
|
|
||
| it('renders table variants through the underlying Table', () => { | ||
| // data-table.tsx:24 — variant is forwarded to <Table variant={...}/>. | ||
| for (const variant of ['grid', 'striped', 'minimal', 'bordered'] as const) { | ||
| expect(() => DataTable<Row>({ columns, data, variant })).not.toThrow(); | ||
| } | ||
| }); | ||
| }); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,76 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { PdfForm } from './form'; | ||
| import type { PdfFormGroup } from './form.types'; | ||
|
|
||
| describe('PdfForm', () => { | ||
| it('renders without throwing', () => { | ||
| const variants = ['underline', 'box', 'outlined', 'ghost'] as const; | ||
| const layouts = ['single', 'two-column', 'three-column'] as const; | ||
|
|
||
| const baseGroup: PdfFormGroup = { | ||
| title: 'Contact', | ||
| fields: [ | ||
| { label: 'Name' }, | ||
| { label: 'Email', hint: '[email protected]' }, | ||
| { label: 'Phone', height: 24 }, | ||
| ], | ||
| }; | ||
|
|
||
| it('renders with empty groups array', () => { | ||
| expect(() => PdfForm({ groups: [] })).not.toThrow(); | ||
| }); | ||
| it('accepts layout prop', () => { | ||
| expect(() => PdfForm({ groups: [], variant: 'box' })).not.toThrow(); | ||
|
|
||
| it('renders all variants', () => { | ||
| for (const variant of variants) { | ||
| expect(() => PdfForm({ groups: [baseGroup], variant })).not.toThrow(); | ||
| } | ||
| }); | ||
|
|
||
| it('renders all column layouts', () => { | ||
| for (const layout of layouts) { | ||
| expect(() => PdfForm({ groups: [{ ...baseGroup, layout }] })).not.toThrow(); | ||
| } | ||
| }); | ||
|
|
||
| it('renders both labelPositions', () => { | ||
| for (const labelPosition of ['above', 'left'] as const) { | ||
| expect(() => PdfForm({ groups: [baseGroup], labelPosition })).not.toThrow(); | ||
| } | ||
| }); | ||
|
|
||
| it('renders with title/subtitle (adds form divider)', () => { | ||
| // form.tsx:108 — title or subtitle triggers the formDivider row. | ||
| expect(() => | ||
| PdfForm({ title: 'Application', subtitle: 'Fill every field', groups: [baseGroup] }) | ||
| ).not.toThrow(); | ||
| expect(() => PdfForm({ title: 'Application', groups: [baseGroup] })).not.toThrow(); | ||
| expect(() => PdfForm({ subtitle: 'Only', groups: [baseGroup] })).not.toThrow(); | ||
| }); | ||
|
|
||
| it('renders groups with no title, empty fields, and uneven column chunks', () => { | ||
| expect(() => PdfForm({ groups: [{ fields: [] }] })).not.toThrow(); | ||
| expect(() => | ||
| PdfForm({ | ||
| groups: [ | ||
| { fields: [{ label: 'A' }], layout: 'three-column' }, | ||
| { fields: [{ label: 'A' }, { label: 'B' }], layout: 'three-column' }, | ||
| { | ||
| fields: [ | ||
| { label: 'A' }, | ||
| { label: 'B' }, | ||
| { label: 'C' }, | ||
| { label: 'D' }, | ||
| { label: 'E' }, | ||
| ], | ||
| layout: 'two-column', | ||
| }, | ||
| ], | ||
| }) | ||
| ).not.toThrow(); | ||
| }); | ||
|
|
||
| it('accepts noWrap and a style override', () => { | ||
| expect(() => | ||
| PdfForm({ groups: [baseGroup], noWrap: true, style: { padding: 12 } }) | ||
| ).not.toThrow(); | ||
| }); | ||
| }); |
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.
Test intent and assertion are mismatched for render callbacks.
Line 53 says callback invocation is tested, but the test only checks
not.toThrow. This can pass even ifrender/renderFooterare never called.Suggested fix
it('invokes custom cell render and footer render', () => { - const renderScore = (value: unknown) => - typeof value === 'number' ? `${value}%` : String(value ?? ''); + let cellRenderCalled = false; + let footerRenderCalled = false; + const formatScore = (value: unknown) => + typeof value === 'number' ? `${value}%` : String(value ?? ''); expect(() => DataTable<Row>({ columns: [ { key: 'name', header: 'Name' }, - { key: 'score', header: 'Score', render: renderScore, renderFooter: renderScore }, + { + key: 'score', + header: 'Score', + render: (value) => { + cellRenderCalled = true; + return formatScore(value); + }, + renderFooter: (value) => { + footerRenderCalled = true; + return formatScore(value); + }, + }, ], data, footer: { score: 264 }, }) ).not.toThrow(); + expect(cellRenderCalled).toBe(true); + expect(footerRenderCalled).toBe(true); });🤖 Prompt for AI Agents