Files
MealQuest/web/src/ui/Chip.test.tsx
T
dev_agent 02f1dd6491
CI / ci (push) Successful in 1m31s
Feature 05 task 2: Core UI primitives (#34)
Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
Co-committed-by: dev_agent <dev_agent@cubecraftlabs.com>
2026-10-03 16:34:59 -04:00

27 lines
1.0 KiB
TypeScript

import { fireEvent, render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { expectMinHitArea } from '../test/hitArea.ts'
import { Chip } from './Chip.tsx'
describe('Chip', () => {
it('has no remove button unless onRemove is given', () => {
render(<Chip label="Beef tacos" />)
expect(screen.getByText('Beef tacos')).toBeInTheDocument()
expect(screen.queryByRole('button')).not.toBeInTheDocument()
})
it('exposes an accessible "Remove {label}" button that calls onRemove', () => {
const onRemove = vi.fn()
render(<Chip label="Beef tacos" onRemove={onRemove} />)
const remove = screen.getByRole('button', { name: 'Remove Beef tacos' })
expect(remove).toHaveAttribute('type', 'button')
fireEvent.click(remove)
expect(onRemove).toHaveBeenCalledOnce()
})
it('gives the remove button a ≥ 44 px hit area', () => {
render(<Chip label="Pizza night" onRemove={() => {}} />)
expectMinHitArea(screen.getByRole('button', { name: 'Remove Pizza night' }))
})
})