Feature 05 task 2: Core UI primitives (#34)
CI / ci (push) Successful in 1m31s

Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
Co-committed-by: dev_agent <dev_agent@cubecraftlabs.com>
This commit was merged in pull request #34.
This commit is contained in:
2026-10-03 16:34:59 -04:00
committed by approver_agent
parent 496f2e5375
commit 02f1dd6491
36 changed files with 1408 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import { fireEvent, render, screen } from '@testing-library/react'
import { createRef } from 'react'
import { describe, expect, it, vi } from 'vitest'
import { hitArea, expectMinHitArea } from '../test/hitArea.ts'
import { TextInput } from './TextInput.tsx'
describe('TextInput', () => {
it('is a textbox named by its label', () => {
const onChange = vi.fn()
render(<TextInput label="Dinner name" placeholder="e.g. Chicken enchiladas" onChange={onChange} />)
const input = screen.getByRole('textbox', { name: 'Dinner name' })
fireEvent.change(input, { target: { value: 'Chili' } })
expect(onChange).toHaveBeenCalledOnce()
expect(input).toHaveValue('Chili')
})
it('keeps the accessible name when the label is visually hidden', () => {
render(<TextInput label="Add a regular" labelHidden />)
expect(screen.getByRole('textbox', { name: 'Add a regular' })).toBeInTheDocument()
})
it('is a 48 px pill with a ≥ 44 px hit area', () => {
render(<TextInput label="Dinner name" />)
const input = screen.getByRole('textbox', { name: 'Dinner name' })
expectMinHitArea(input)
expect(hitArea(input).height).toBe(48)
})
it('forwards the ref', () => {
const ref = createRef<HTMLInputElement>()
render(<TextInput label="Dinner name" ref={ref} />)
expect(ref.current).toBe(screen.getByRole('textbox', { name: 'Dinner name' }))
})
})