mirror of
https://github.com/appwrite/console.git
synced 2026-04-07 19:17:46 +00:00
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { expect, test } from 'vitest';
|
|
import { render, fireEvent } from '@testing-library/svelte';
|
|
import { InputSwitch } from '../../../src/lib/elements/forms';
|
|
|
|
test('shows boolean input', () => {
|
|
const { getByText, getByRole } = render(InputSwitch, { id: 'input', label: 'Bool' });
|
|
const checkbox = getByRole('switch');
|
|
|
|
expect(getByText('Bool')).toBeInTheDocument();
|
|
expect(checkbox).toBeInTheDocument();
|
|
expect(checkbox).toHaveAttribute('type', 'checkbox');
|
|
});
|
|
|
|
test('shows boolean input - disabled', () => {
|
|
const { getByRole } = render(InputSwitch, { id: 'input', label: 'Bool', disabled: true });
|
|
|
|
expect(getByRole('switch')).toBeDisabled();
|
|
});
|
|
|
|
test('state', async () => {
|
|
const { getByRole, component } = render(InputSwitch, { id: 'input', label: 'Bool' });
|
|
const checkbox = getByRole('switch');
|
|
|
|
expect(checkbox).not.toBeChecked();
|
|
expect(component.value).toStrictEqual(false);
|
|
|
|
await fireEvent.click(checkbox);
|
|
expect(checkbox).toBeChecked();
|
|
expect(component.value).toStrictEqual(true);
|
|
|
|
await fireEvent.click(checkbox);
|
|
expect(checkbox).not.toBeChecked();
|
|
expect(component.value).toStrictEqual(false);
|
|
|
|
component.value = true;
|
|
expect(checkbox).toBeChecked();
|
|
expect(component.value).toStrictEqual(true);
|
|
|
|
component.value = false;
|
|
expect(checkbox).not.toBeChecked();
|
|
expect(component.value).toStrictEqual(false);
|
|
});
|