feat(web): coordinate input for asset location (#11291)

This commit is contained in:
Michel Heusschen 2024-07-23 14:01:10 +02:00 committed by GitHub
parent 8725656fd2
commit 7d3db11a5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 126 additions and 8 deletions

View file

@ -0,0 +1,50 @@
import NumberRangeInput from '$lib/components/shared-components/number-range-input.svelte';
import { act, render, type RenderResult } from '@testing-library/svelte';
import userEvent from '@testing-library/user-event';
describe('NumberRangeInput component', () => {
const user = userEvent.setup();
let sut: RenderResult<NumberRangeInput>;
let input: HTMLInputElement;
beforeEach(() => {
sut = render(NumberRangeInput, { id: '', min: -90, max: 90, onInput: () => {} });
input = sut.getByRole('spinbutton') as HTMLInputElement;
});
it('updates value', async () => {
expect(input.value).toBe('');
await act(() => sut.component.$set({ value: 10 }));
expect(input.value).toBe('10');
});
it('restricts minimum value', async () => {
await user.type(input, '-91');
expect(input.value).toBe('-90');
});
it('restricts maximum value', async () => {
await user.type(input, '09990');
expect(input.value).toBe('90');
});
it('allows entering negative numbers', async () => {
await user.type(input, '-10');
expect(input.value).toBe('-10');
});
it('allows entering zero', async () => {
await user.type(input, '0');
expect(input.value).toBe('0');
});
it('allows entering decimal numbers', async () => {
await user.type(input, '-0.09001');
expect(input.value).toBe('-0.09001');
});
it('ignores text input', async () => {
await user.type(input, 'test');
expect(input.value).toBe('');
});
});