From ed66043210668c3163e774ca35b51b06f56fe9e2 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Fri, 18 Sep 2026 14:45:44 -0500 Subject: [PATCH] docs: improve test suite documentation Co-Authored-By: Claude Sonnet 5 --- src/components/Badge/Badge.test.tsx | 13 +++++++++++++ src/components/Button/Button.test.tsx | 13 +++++++++++++ src/components/Card/Card.test.tsx | 11 +++++++++++ src/components/Input/Input.test.tsx | 11 +++++++++++ src/components/ProgressBar/ProgressBar.test.tsx | 13 +++++++++++++ src/components/Select/Select.test.tsx | 11 +++++++++++ src/components/Spinner/Spinner.test.tsx | 10 ++++++++++ src/components/StatusDot/StatusDot.test.tsx | 13 +++++++++++++ src/components/Table/Table.test.tsx | 17 +++++++++++++++++ src/components/Tabs/Tabs.test.tsx | 11 +++++++++++ src/components/Tooltip/Tooltip.test.tsx | 9 +++++++++ src/test-setup.ts | 6 ++++++ 12 files changed, 138 insertions(+) diff --git a/src/components/Badge/Badge.test.tsx b/src/components/Badge/Badge.test.tsx index cee39cd..3125738 100644 --- a/src/components/Badge/Badge.test.tsx +++ b/src/components/Badge/Badge.test.tsx @@ -1,33 +1,46 @@ +/** + * Validate the Badge component: rendering children, the class applied for each variant (success, + * warning, danger, info, neutral, default), and the default variant. + * + * Developer: Manish Kumar + */ import { render, screen } from '@testing-library/react'; import { Badge } from './Badge'; describe('Badge', () => { + // Render the given children inside the badge. it('renders children', () => { render(hello); expect(screen.getByText('hello')).toBeInTheDocument(); }); + // Apply the omni-badge--success class for the success variant. it('applies success variant class', () => { const { container } = render(ok); expect(container.firstChild).toHaveClass('omni-badge--success'); }); + // Apply the omni-badge--warning class for the warning variant. it('applies warning variant class', () => { const { container } = render(warn); expect(container.firstChild).toHaveClass('omni-badge--warning'); }); + // Apply the omni-badge--danger class for the danger variant. it('applies danger variant class', () => { const { container } = render(fail); expect(container.firstChild).toHaveClass('omni-badge--danger'); }); + // Apply the omni-badge--info class for the info variant. it('applies info variant class', () => { const { container } = render(info); expect(container.firstChild).toHaveClass('omni-badge--info'); }); + // Render without error for both the neutral and default variants. it('neutral and default both render without error', () => { const { container: a } = render(n); const { container: b } = render(d); expect(a.firstChild).toBeTruthy(); expect(b.firstChild).toBeTruthy(); }); + // Apply the base omni-badge class when no variant is given. it('defaults to neutral when no variant given', () => { const { container } = render(default); expect(container.firstChild).toHaveClass('omni-badge'); diff --git a/src/components/Button/Button.test.tsx b/src/components/Button/Button.test.tsx index e66b828..d725fb8 100644 --- a/src/components/Button/Button.test.tsx +++ b/src/components/Button/Button.test.tsx @@ -1,36 +1,49 @@ +/** + * Validate the Button component: rendering children, click handling, the disabled and loading + * states, and the variant and size class names. + * + * Developer: Manish Kumar + */ import { render, screen, fireEvent } from '@testing-library/react'; import { Button } from './Button'; describe('Button', () => { + // Render the given children inside the button. it('renders children', () => { render(); expect(screen.getByText('Click me')).toBeInTheDocument(); }); + // Call onClick exactly once when the button is clicked. it('calls onClick when clicked', () => { const fn = vi.fn(); render(); fireEvent.click(screen.getByText('Click')); expect(fn).toHaveBeenCalledTimes(1); }); + // Disable the button when the disabled prop is true. it('is disabled when disabled prop is true', () => { render(); expect(screen.getByRole('button')).toBeDisabled(); }); + // Disable the button and show a spinner while loading. it('is disabled and shows spinner when loading', () => { const { container } = render(); expect(screen.getByRole('button')).toBeDisabled(); expect(container.querySelector('.omni-spinner')).toBeInTheDocument(); }); + // Never call onClick when the button is disabled. it('does not call onClick when disabled', () => { const fn = vi.fn(); render(); fireEvent.click(screen.getByRole('button')); expect(fn).not.toHaveBeenCalled(); }); + // Apply the variant class, e.g. omni-btn--danger. it('applies variant classes', () => { const { container } = render(); expect(container.firstChild).toHaveClass('omni-btn--danger'); }); + // Apply the size class, e.g. omni-btn--lg. it('applies size classes', () => { const { container } = render(); expect(container.firstChild).toHaveClass('omni-btn--lg'); diff --git a/src/components/Card/Card.test.tsx b/src/components/Card/Card.test.tsx index 76e61c1..f83b804 100644 --- a/src/components/Card/Card.test.tsx +++ b/src/components/Card/Card.test.tsx @@ -1,23 +1,34 @@ +/** + * Validate the Card component: rendering children and an optional title, omitting the header when + * there is nothing to show in it, and the elevated and clickable class/click-handler behavior. + * + * Developer: Manish Kumar + */ import { render, screen, fireEvent } from '@testing-library/react'; import { Card } from './Card'; describe('Card', () => { + // Render the given children inside the card. it('renders children', () => { render(content); expect(screen.getByText('content')).toBeInTheDocument(); }); + // Render the title when one is provided. it('renders title when provided', () => { render(body); expect(screen.getByText('My Card')).toBeInTheDocument(); }); + // Omit the header element when there is no title or actions to show. it('does not render header when no title or actions', () => { const { container } = render(body); expect(container.querySelector('.omni-card__header')).toBeNull(); }); + // Apply the omni-card--elevated class when elevated is set. it('applies elevated class', () => { const { container } = render(body); expect(container.firstChild).toHaveClass('omni-card--elevated'); }); + // Apply the omni-card--clickable class and call onClick when the card is clicked. it('applies clickable class and calls onClick', () => { const fn = vi.fn(); const { container } = render(body); diff --git a/src/components/Input/Input.test.tsx b/src/components/Input/Input.test.tsx index 7da36b4..342e0b1 100644 --- a/src/components/Input/Input.test.tsx +++ b/src/components/Input/Input.test.tsx @@ -1,21 +1,31 @@ +/** + * Validate the Input component: label and placeholder rendering, change handling, the error + * message and error class, and the disabled state. + * + * Developer: Manish Kumar + */ import { render, screen, fireEvent } from '@testing-library/react'; import { Input } from './Input'; describe('Input', () => { + // Render the field's label text when one is provided. it('renders label when provided', () => { render( {}} />); expect(screen.getByText('Sample ID')).toBeInTheDocument(); }); + // Render the placeholder text on the input. it('renders placeholder', () => { render( {}} />); expect(screen.getByPlaceholderText('Enter value')).toBeInTheDocument(); }); + // Call onChange once when the input value changes. it('calls onChange when typed', () => { const fn = vi.fn(); render(); fireEvent.change(screen.getByRole('textbox'), { target: { value: 'abc' } }); expect(fn).toHaveBeenCalledTimes(1); }); + // Show the error message and apply the omni-input--error class. it('shows error message and error class', () => { const { container } = render( {}} error="File not found" /> @@ -23,6 +33,7 @@ describe('Input', () => { expect(screen.getByText('File not found')).toBeInTheDocument(); expect(container.querySelector('.omni-input--error')).toBeInTheDocument(); }); + // Disable the input when the disabled prop is true. it('is disabled when disabled prop is true', () => { render( {}} disabled />); expect(screen.getByRole('textbox')).toBeDisabled(); diff --git a/src/components/ProgressBar/ProgressBar.test.tsx b/src/components/ProgressBar/ProgressBar.test.tsx index 94714d8..14608d6 100644 --- a/src/components/ProgressBar/ProgressBar.test.tsx +++ b/src/components/ProgressBar/ProgressBar.test.tsx @@ -1,32 +1,45 @@ +/** + * Validate the ProgressBar component: default rendering, clamping out-of-range values, the + * variant and size classes, and the percentage label's default, custom, and hidden states. + * + * Developer: Manish Kumar + */ import { render } from '@testing-library/react'; import { ProgressBar } from './ProgressBar'; describe('ProgressBar', () => { + // Render the progress fill element with default props. it('renders with default props', () => { const { container } = render(); expect(container.querySelector('.omni-progress-fill')).toBeInTheDocument(); }); + // Clamp a value above 100 to a 100% fill width. it('clamps value to 0–100', () => { const { container } = render(); const fill = container.querySelector('.omni-progress-fill') as HTMLElement; expect(fill.style.width).toBe('100%'); }); + // Apply the variant class, e.g. omni-progress-fill--success. it('applies correct variant class', () => { const { container } = render(); expect(container.querySelector('.omni-progress-fill--success')).toBeInTheDocument(); }); + // Show the numeric percentage as the label by default. it('shows percentage label by default', () => { const { getByText } = render(); expect(getByText('75%')).toBeInTheDocument(); }); + // Show a custom label string when one is provided. it('shows custom label when provided', () => { const { getByText } = render(); expect(getByText('98.7%')).toBeInTheDocument(); }); + // Omit the label element when showLabel is false. it('hides label when showLabel is false', () => { const { container } = render(); expect(container.querySelector('.omni-progress-label')).toBeNull(); }); + // Apply the size class, e.g. omni-progress-track--lg. it('applies size class', () => { const { container } = render(); expect(container.querySelector('.omni-progress-track--lg')).toBeInTheDocument(); diff --git a/src/components/Select/Select.test.tsx b/src/components/Select/Select.test.tsx index cd841c7..3ec4071 100644 --- a/src/components/Select/Select.test.tsx +++ b/src/components/Select/Select.test.tsx @@ -1,3 +1,9 @@ +/** + * Validate the Select component: rendering its options and label, change handling, the disabled + * state, and the placeholder option. + * + * Developer: Manish Kumar + */ import { render, screen, fireEvent } from '@testing-library/react'; import { Select } from './Select'; @@ -8,25 +14,30 @@ const options = [ ]; describe('Select', () => { + // Render every option's label. it('renders all options', () => { render( {}} label="Category" />); expect(screen.getByText('Category')).toBeInTheDocument(); }); + // Call onChange with the newly selected value. it('calls onChange with selected value', () => { const fn = vi.fn(); render( {}} disabled />); expect(screen.getByRole('combobox')).toBeDisabled(); }); + // Render the placeholder option when the value is empty. it('renders placeholder option', () => { render(