import { render } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
import { describe, expect, test } from 'vitest';
import UiCheckbox from '../UiCheckbox.vue';

describe('UiCheckbox', () => {
  test('renders enabled and emits update:modelValue on click', async () => {
    const { getByRole, emitted } = render(UiCheckbox);
    const checkbox = getByRole('checkbox');
    expect(checkbox).toBeEnabled();

    await userEvent.click(checkbox);
    expect(emitted('update:modelValue')?.[0][0]).toBe(true);
  });

  test('renders disabled when disabled prop is true', () => {
    const { getByRole } = render(UiCheckbox, {
      props: { disabled: true },
    });
    expect(getByRole('checkbox')).toBeDisabled();
  });

  test('renders indeterminate state with aria-checked="mixed"', () => {
    const { getByRole } = render(UiCheckbox, {
      props: { modelValue: 'indeterminate' },
    });
    expect(getByRole('checkbox')).toHaveAttribute('aria-checked', 'mixed');
  });
});
