import { describe, it, expect, vi } from 'vitest' import { render, screen, fireEvent } from '@testing-library/react' import { Button } from '@/components/ui/button' import { StatusTag, PriorityTag, statusHue } from '@/components/ui/status-tag' import { Checkbox } from '@/components/ui/checkbox' import { FilterChip } from '@/components/ui/filter-chip' import { Segmented } from '@/components/ui/segmented' import { Avatar } from '@/components/ui/avatar' import { Drawer } from '@/components/ui/drawer' import { Field, Input } from '@/components/ui/field' import { Card } from '@/components/ui/card' describe('Button', () => { it('primary is the dark 32px button, type=button by default', () => { render() const b = screen.getByRole('button', { name: 'Report incident' }) expect(b.getAttribute('type')).toBe('button') expect(b.className).toContain('bg-ink-2') expect(b.className).toContain('h-8') expect(b.className).toContain('rounded-md') expect(b.className).toContain('shadow-primary') }) it('secondary is white with a ring', () => { render() const b = screen.getByRole('button', { name: 'Export' }) expect(b.className).toContain('bg-surface') expect(b.className).toContain('shadow-secondary') }) it('icon is a 28px ghost button', () => { render() const b = screen.getByRole('button', { name: 'Submit' }) expect(b.className).toContain('w-full') expect(b.className).toContain('h-12') expect(b.className).toContain('rounded-xl') }) }) describe('StatusTag and PriorityTag', () => { it.each([ ['reported', 'amber'], ['triaged', 'blue'], ['investigating', 'violet'], ['capa_pending', 'orange'], ['verification', 'indigo'], ['closed', 'green'], ['open', 'grey'], ['in_progress', 'blue'], ['overdue', 'red'], ['pending_verification', 'indigo'], ['verified', 'green'], ['reopened', 'red'], ['high', 'orange'], ['med', 'amber'], ['low', 'grey'], ['nonsense', 'grey'], ])('%s uses the %s pair', (key, hue) => { expect(statusHue(key)).toBe(hue) }) it('renders a dark-on-tint pill with a text label', () => { render() const el = screen.getByText('CAPA pending') expect(el.className).toContain('bg-st-orange-bg') expect(el.className).toContain('text-st-orange-fg') expect(el.className).toContain('rounded-md') }) it('accepts a label override', () => { render(Late) expect(screen.getByText('Late').className).toContain('bg-st-red-bg') }) it('priority med reads Medium on the amber pair', () => { render() expect(screen.getByText('Medium').className).toContain('bg-st-amber-bg') }) it('never uses white text on a saturated fill', () => { const { container } = render() expect(container.innerHTML).not.toContain('text-white') }) }) describe('Checkbox', () => { it('toggles and reports the next value', () => { const onChange = vi.fn() render() const cb = screen.getByRole('checkbox', { name: 'Select row' }) expect(cb.getAttribute('aria-checked')).toBe('false') fireEvent.click(cb) expect(onChange).toHaveBeenCalledWith(true) }) it('shows checked and indeterminate states', () => { const { rerender } = render( {}} label="a" />) expect(screen.getByRole('checkbox').getAttribute('aria-checked')).toBe('true') expect(screen.getByRole('checkbox').className).toContain('bg-accent') rerender( {}} label="a" />) expect(screen.getByRole('checkbox').getAttribute('aria-checked')).toBe('mixed') }) }) describe('FilterChip', () => { const options = [{ value: 'open', label: 'Open' }, { value: 'closed', label: 'Closed' }] it('unset shows the label and a select with an empty option', () => { const { container } = render( {}} />) expect(container.querySelector('label > span')?.textContent).toBe('Status') expect((screen.getByLabelText('Status') as HTMLSelectElement).value).toBe('') }) it('changes through the select', () => { const onChange = vi.fn() render() fireEvent.change(screen.getByLabelText('Status'), { target: { value: 'closed' } }) expect(onChange).toHaveBeenCalledWith('closed') }) it('set shows Label: value in the teal tint with a clear button', () => { const onChange = vi.fn() render() expect(screen.getByText('Status: Closed').closest('label')?.className).toContain('bg-accent-tint-2') fireEvent.click(screen.getByRole('button', { name: 'Clear Status' })) expect(onChange).toHaveBeenCalledWith('') }) }) describe('Segmented', () => { it('marks the active option and reports changes', () => { const onChange = vi.fn() render() expect(screen.getByRole('button', { name: 'List' }).getAttribute('aria-pressed')).toBe('true') fireEvent.click(screen.getByRole('button', { name: 'Board' })) expect(onChange).toHaveBeenCalledWith('board') }) }) describe('Avatar', () => { it('shows up to two initials on the teal tile', () => { render() const el = screen.getByText('AL') expect(el.className).toContain('bg-accent-200') expect(el.className).toContain('rounded-[6px]') }) }) describe('Drawer', () => { it('renders nothing when closed', () => { const { container } = render( {}} title="Notifications">x) expect(container.firstChild).toBeNull() }) it('renders a labelled dialog, closes on the X button and on Escape', () => { const onClose = vi.fn() render(Mark all read}>body) expect(screen.getByRole('dialog', { name: 'Notifications' })).toBeTruthy() expect(screen.getByText('Mark all read')).toBeTruthy() fireEvent.click(screen.getByRole('button', { name: 'Close' })) fireEvent.keyDown(document, { key: 'Escape' }) expect(onClose).toHaveBeenCalledTimes(2) }) }) describe('Field, Input, Card', () => { it('Input is 36px with the faint ring and is labelled', () => { render() const input = screen.getByLabelText('Email') expect(input.className).toContain('h-9') expect(input.className).toContain('shadow-input') expect(input.className).toContain('rounded-md') }) it('Card is a white 12px card with the card shadow', () => { const { container } = render(Body) expect(container.firstElementChild?.className).toContain('rounded-xl') expect(container.firstElementChild?.className).toContain('shadow-card') expect(screen.getByText('Forklift')).toBeTruthy() }) })