133 lines
4.4 KiB
TypeScript
133 lines
4.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { render, screen } from '@testing-library/react'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Tag } from '@/components/ui/tag'
|
|
import { StatusTag, PriorityTag, statusTone } from '@/components/ui/status-tag'
|
|
import { Field, Input } from '@/components/ui/field'
|
|
import { Card } from '@/components/ui/card'
|
|
import { TABLE, TH, TR, TD } from '@/components/ui/table-styles'
|
|
|
|
describe('Button', () => {
|
|
it('renders a primary accent button that is type=button and flush left', () => {
|
|
render(<Button variant="primary">Save</Button>)
|
|
const btn = screen.getByRole('button', { name: 'Save' })
|
|
expect(btn.getAttribute('type')).toBe('button')
|
|
expect(btn.className).toContain('bg-accent')
|
|
expect(btn.className).toContain('justify-start')
|
|
expect(btn.className).not.toContain('justify-center')
|
|
})
|
|
|
|
it('block buttons span the row and stay flush left', () => {
|
|
render(<Button block>Go</Button>)
|
|
const btn = screen.getByRole('button', { name: 'Go' })
|
|
expect(btn.className).toContain('w-full')
|
|
expect(btn.className).toContain('justify-start')
|
|
})
|
|
|
|
it('icon buttons are square and centered', () => {
|
|
render(<Button variant="icon" aria-label="Close" />)
|
|
const btn = screen.getByRole('button', { name: 'Close' })
|
|
expect(btn.className).toContain('w-9')
|
|
expect(btn.className).toContain('justify-center')
|
|
expect(btn.className).not.toContain('justify-start')
|
|
})
|
|
|
|
it('never uses a rounded class', () => {
|
|
render(<Button variant="secondary">x</Button>)
|
|
expect(screen.getByRole('button').className).not.toMatch(/rounded/)
|
|
})
|
|
})
|
|
|
|
describe('Tag', () => {
|
|
it.each([
|
|
['accent', 'bg-accent-100'],
|
|
['neutral', 'bg-neutral-100'],
|
|
['outline', 'border-accent'],
|
|
] as const)('%s variant carries %s', (variant, cls) => {
|
|
render(<Tag variant={variant}>Label</Tag>)
|
|
expect(screen.getByText('Label').className).toContain(cls)
|
|
})
|
|
})
|
|
|
|
describe('statusTone', () => {
|
|
it.each([
|
|
['reported', 'accent'],
|
|
['triaged', 'outline'],
|
|
['investigating', 'outline'],
|
|
['capa_pending', 'outline'],
|
|
['verification', 'outline'],
|
|
['closed', 'neutral'],
|
|
['open', 'accent'],
|
|
['in_progress', 'outline'],
|
|
['overdue', 'accent'],
|
|
['pending_verification', 'outline'],
|
|
['verified', 'neutral'],
|
|
['reopened', 'accent'],
|
|
['something_else', 'neutral'],
|
|
])('%s maps to %s', (status, tone) => {
|
|
expect(statusTone(status)).toBe(tone)
|
|
})
|
|
})
|
|
|
|
describe('StatusTag', () => {
|
|
it('shows a humanized text label plus an icon, never color alone', () => {
|
|
const { container } = render(<StatusTag status="capa_pending" />)
|
|
expect(screen.getByText('CAPA Pending')).toBeTruthy()
|
|
expect(container.querySelector('svg')).not.toBeNull()
|
|
})
|
|
|
|
it('accepts a label override', () => {
|
|
render(<StatusTag status="overdue">Late</StatusTag>)
|
|
expect(screen.getByText('Late')).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('PriorityTag', () => {
|
|
it.each([
|
|
['high', 'bg-accent-100'],
|
|
['med', 'border-accent'],
|
|
['low', 'bg-neutral-100'],
|
|
])('%s priority uses %s', (priority, cls) => {
|
|
const { container } = render(<PriorityTag priority={priority} />)
|
|
expect(container.firstElementChild?.className).toContain(cls)
|
|
})
|
|
})
|
|
|
|
describe('Field and Input', () => {
|
|
it('associates the label with the input', () => {
|
|
render(
|
|
<Field label="Email" htmlFor="email">
|
|
<Input id="email" />
|
|
</Field>,
|
|
)
|
|
const input = screen.getByLabelText('Email')
|
|
expect(input.className).toContain('bg-surface')
|
|
expect(input.className).toContain('border-divider')
|
|
})
|
|
})
|
|
|
|
describe('Card', () => {
|
|
it('renders kicker, title, body and meta on the surface fill', () => {
|
|
const { container } = render(
|
|
<Card kicker="Open" title="Forklift" meta="Due Friday">
|
|
Body text
|
|
</Card>,
|
|
)
|
|
expect(screen.getByText('Open')).toBeTruthy()
|
|
expect(screen.getByText('Forklift')).toBeTruthy()
|
|
expect(screen.getByText('Body text')).toBeTruthy()
|
|
expect(screen.getByText('Due Friday')).toBeTruthy()
|
|
expect(container.firstElementChild?.className).toContain('bg-surface')
|
|
})
|
|
})
|
|
|
|
describe('table styles', () => {
|
|
it('uses a 2px header rule and 1px row rules', () => {
|
|
expect(TH).toContain('border-b-2')
|
|
expect(TH).toContain('border-divider')
|
|
expect(TD).toContain('border-b')
|
|
expect(TR).toContain('hover:bg-ink/4')
|
|
expect(TABLE).toContain('w-full')
|
|
})
|
|
})
|