2026-01-07 09:31:02 +00:00
|
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
|
import { Checkbox } from './checkbox';
|
|
|
|
|
|
|
|
|
|
describe('Checkbox Component', () => {
|
|
|
|
|
it('renders checkbox', () => {
|
|
|
|
|
render(<Checkbox />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const checkbox = screen.getByRole('checkbox');
|
|
|
|
|
expect(checkbox).toBeInTheDocument();
|
|
|
|
|
expect(checkbox).not.toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders with label', () => {
|
|
|
|
|
render(<Checkbox label="Accept terms" />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const label = screen.getByText('Accept terms');
|
|
|
|
|
expect(label).toBeInTheDocument();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const checkbox = screen.getByRole('checkbox');
|
|
|
|
|
expect(checkbox).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('handles onCheckedChange callback', () => {
|
|
|
|
|
const handleCheckedChange = vi.fn();
|
|
|
|
|
render(<Checkbox onCheckedChange={handleCheckedChange} />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const checkbox = screen.getByRole('checkbox');
|
|
|
|
|
fireEvent.click(checkbox);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(handleCheckedChange).toHaveBeenCalledWith(true);
|
|
|
|
|
expect(checkbox).toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('handles onChange event', () => {
|
|
|
|
|
const handleChange = vi.fn();
|
|
|
|
|
render(<Checkbox onChange={handleChange} />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const checkbox = screen.getByRole('checkbox');
|
|
|
|
|
fireEvent.click(checkbox);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('handles checked state', () => {
|
|
|
|
|
render(<Checkbox checked />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const checkbox = screen.getByRole('checkbox');
|
|
|
|
|
expect(checkbox).toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('handles disabled state', () => {
|
|
|
|
|
render(<Checkbox disabled label="Disabled checkbox" />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const checkbox = screen.getByRole('checkbox');
|
|
|
|
|
expect(checkbox).toBeDisabled();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 18:39:18 +00:00
|
|
|
// The opacity-50 is on the wrapping label element, not the text span
|
|
|
|
|
const label = screen.getByText('Disabled checkbox').closest('label');
|
2026-01-07 09:31:02 +00:00
|
|
|
expect(label).toHaveClass('opacity-50');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('toggles checked state on click', () => {
|
|
|
|
|
render(<Checkbox label="Toggle me" />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const checkbox = screen.getByRole('checkbox');
|
|
|
|
|
expect(checkbox).not.toBeChecked();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
fireEvent.click(checkbox);
|
|
|
|
|
expect(checkbox).toBeChecked();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
fireEvent.click(checkbox);
|
|
|
|
|
expect(checkbox).not.toBeChecked();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('applies custom className', () => {
|
|
|
|
|
render(<Checkbox className="custom-checkbox" />);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:31:02 +00:00
|
|
|
const label = screen.getByRole('checkbox').closest('label');
|
|
|
|
|
expect(label).toHaveClass('custom-checkbox');
|
|
|
|
|
});
|
|
|
|
|
});
|