All checks were successful
🚀 Release / release (push) Successful in 4m7s
Reviewed-on: #31 Co-authored-by: Max Richter <max@max-richter.dev> Co-committed-by: Max Richter <max@max-richter.dev>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { render } from 'vitest-browser-svelte';
|
|
import { page } from 'vitest/browser';
|
|
import InputNumber from './InputNumber.svelte';
|
|
|
|
describe('InputNumber', () => {
|
|
it('should render input element', async () => {
|
|
render(InputNumber, { value: 0.5 });
|
|
|
|
const input = page.getByRole('spinbutton');
|
|
await expect.element(input).toBeInTheDocument();
|
|
});
|
|
|
|
it('should render with step buttons when step is provided', async () => {
|
|
render(InputNumber, { value: 0.5, step: 0.1 });
|
|
|
|
const decrementBtn = page.getByRole('button', { name: 'step down' });
|
|
const incrementBtn = page.getByRole('button', { name: 'step up' });
|
|
await expect.element(decrementBtn).toBeInTheDocument();
|
|
await expect.element(incrementBtn).toBeInTheDocument();
|
|
});
|
|
|
|
it('should not render step buttons when step is undefined', async () => {
|
|
const screen = render(InputNumber, { value: 0.5 });
|
|
|
|
const buttons = screen.locator.getByRole('button');
|
|
const count = buttons.all().length;
|
|
expect(count).toBe(0);
|
|
});
|
|
|
|
it('should accept numeric value', async () => {
|
|
render(InputNumber, { value: 42 });
|
|
|
|
const input = page.getByRole('spinbutton');
|
|
await expect.element(input).toHaveValue(42);
|
|
});
|
|
|
|
it('should accept min and max bounds', async () => {
|
|
render(InputNumber, { value: 5, min: 0, max: 10 });
|
|
|
|
const input = page.getByRole('spinbutton');
|
|
await expect.element(input).toHaveAttribute('min', '0');
|
|
await expect.element(input).toHaveAttribute('max', '10');
|
|
});
|
|
});
|