Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
import { userEvent } from 'vite-plus/test/browser'
import { render } from 'vitest-browser-react'
import { Checkbox, CheckboxSkeleton } from '../index'
describe('Checkbox', () => {
it('should render an unchecked checkbox with Base UI semantics', async () => {
const screen = await render(<Checkbox checked={false} aria-label="Accept terms" />)
const checkbox = screen.getByRole('checkbox', { name: 'Accept terms' })
await expect.element(checkbox).toHaveAttribute('aria-checked', 'false')
await expect.element(checkbox).toHaveAttribute('data-unchecked', '')
await expect.element(checkbox).not.toHaveAttribute('data-checked')
await expect.element(checkbox).not.toHaveAttribute('data-indeterminate')
})
it('should expose checked data attributes', async () => {
const screen = await render(<Checkbox checked aria-label="Accept terms" />)
const checkbox = screen.getByRole('checkbox', { name: 'Accept terms' })
await expect.element(checkbox).toHaveAttribute('aria-checked', 'true')
await expect.element(checkbox).toHaveAttribute('data-checked', '')
})
it('should expose mixed state when indeterminate', async () => {
const screen = await render(<Checkbox checked={false} indeterminate aria-label="Select all" />)
const checkbox = screen.getByRole('checkbox', { name: 'Select all' })
await expect.element(checkbox).toHaveAttribute('aria-checked', 'mixed')
await expect.element(checkbox).toHaveAttribute('data-indeterminate', '')
})
it('should call onCheckedChange with the next checked value', async () => {
const onCheckedChange = vi.fn()
const screen = await render(
<Checkbox checked={false} aria-label="Accept terms" onCheckedChange={onCheckedChange} />,
)
await screen.getByRole('checkbox', { name: 'Accept terms' }).click()
expect(onCheckedChange).toHaveBeenCalledTimes(1)
expect(onCheckedChange.mock.calls[0]?.[0]).toBe(true)
})
it('should stay controlled until the checked prop changes', async () => {
const onCheckedChange = vi.fn()
const screen = await render(
<Checkbox checked={false} aria-label="Accept terms" onCheckedChange={onCheckedChange} />,
)
const checkbox = screen.getByRole('checkbox', { name: 'Accept terms' })
await checkbox.click()
expect(onCheckedChange.mock.calls[0]?.[0]).toBe(true)
await expect.element(checkbox).toHaveAttribute('aria-checked', 'false')
await screen.rerender(
<Checkbox checked aria-label="Accept terms" onCheckedChange={onCheckedChange} />,
)
await expect
.element(screen.getByRole('checkbox', { name: 'Accept terms' }))
.toHaveAttribute('aria-checked', 'true')
})
it('should ignore interaction when disabled', async () => {
const screen = await render(<Checkbox checked={false} disabled aria-label="Accept terms" />)
const checkbox = screen.getByRole('checkbox', { name: 'Accept terms' })
await expect.element(checkbox).toBeDisabled()
await expect.element(checkbox).toHaveAttribute('data-disabled', '')
})
it.each([false, true])(
'should keep a read-only checkbox unchanged on hover and click (checked: %s)',
async (checked) => {
const screen = await render(
<Checkbox readOnly defaultChecked={checked} aria-label="Accept terms" />,
)
const checkbox = screen.getByRole('checkbox', { name: 'Accept terms' })
const style = getComputedStyle(checkbox.element())
const resting = [style.backgroundColor, style.borderColor]
await userEvent.hover(checkbox)
expect([style.backgroundColor, style.borderColor]).toEqual(resting)
expect(style.cursor).toBe('default')
await checkbox.click()
await expect.element(checkbox).toHaveAttribute('aria-checked', String(checked))
},
)
it('should submit checked and unchecked form values through the hidden input', async () => {
const screen = await render(
<form>
<Checkbox
checked
name="terms"
value="accepted"
uncheckedValue="declined"
aria-label="Terms"
/>
<Checkbox
checked={false}
name="newsletter"
value="yes"
uncheckedValue="no"
aria-label="Newsletter"
/>
</form>,
)
const form = screen.container.querySelector('form') as HTMLFormElement
const data = new FormData(form)
expect(data.get('terms')).toBe('accepted')
expect(data.get('newsletter')).toBe('no')
})
})
describe('CheckboxSkeleton', () => {
it('should render a visual placeholder without checkbox semantics', async () => {
const screen = await render(<CheckboxSkeleton data-testid="checkbox-skeleton" />)
expect(screen.container.querySelector('[role="checkbox"]')).not.toBeInTheDocument()
await expect.element(screen.getByTestId('checkbox-skeleton')).toBeInTheDocument()
})
})