mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix(web): Prevent changing asset location triggering keyboard shortcuts (#21451)
fix(web): Prevent changing asset location triggering asset keyboard shortcuts
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
import NumberRangeInput from '$lib/components/shared-components/number-range-input.svelte';
|
||||
import { render, type RenderResult } from '@testing-library/svelte';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import type { Mock } from 'vitest';
|
||||
|
||||
describe('NumberRangeInput component', () => {
|
||||
const user = userEvent.setup();
|
||||
let sut: RenderResult<NumberRangeInput>;
|
||||
let input: HTMLInputElement;
|
||||
let onInput: Mock;
|
||||
let onKeyDown: Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
onInput = vi.fn();
|
||||
onKeyDown = vi.fn();
|
||||
sut = render(NumberRangeInput, {
|
||||
id: '',
|
||||
min: -90,
|
||||
max: 90,
|
||||
onInput: () => {},
|
||||
onInput,
|
||||
onKeyDown,
|
||||
});
|
||||
input = sut.getByRole('spinbutton') as HTMLInputElement;
|
||||
});
|
||||
@@ -21,35 +27,55 @@ describe('NumberRangeInput component', () => {
|
||||
expect(input.value).toBe('');
|
||||
await sut.rerender({ value: 10 });
|
||||
expect(input.value).toBe('10');
|
||||
expect(onInput).not.toHaveBeenCalled();
|
||||
expect(onKeyDown).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('restricts minimum value', async () => {
|
||||
await user.type(input, '-91');
|
||||
expect(input.value).toBe('-90');
|
||||
expect(onInput).toHaveBeenCalled();
|
||||
expect(onKeyDown).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('restricts maximum value', async () => {
|
||||
await user.type(input, '09990');
|
||||
expect(input.value).toBe('90');
|
||||
expect(onInput).toHaveBeenCalled();
|
||||
expect(onKeyDown).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows entering negative numbers', async () => {
|
||||
await user.type(input, '-10');
|
||||
expect(input.value).toBe('-10');
|
||||
expect(onInput).toHaveBeenCalled();
|
||||
expect(onKeyDown).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows entering zero', async () => {
|
||||
await user.type(input, '0');
|
||||
expect(input.value).toBe('0');
|
||||
expect(onInput).toHaveBeenCalled();
|
||||
expect(onKeyDown).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows entering decimal numbers', async () => {
|
||||
await user.type(input, '-0.09001');
|
||||
expect(input.value).toBe('-0.09001');
|
||||
expect(onInput).toHaveBeenCalled();
|
||||
expect(onKeyDown).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ignores text input', async () => {
|
||||
await user.type(input, 'test');
|
||||
expect(input.value).toBe('');
|
||||
expect(onInput).toHaveBeenCalled();
|
||||
expect(onKeyDown).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('test', async () => {
|
||||
await user.type(input, 'd');
|
||||
expect(onInput).not.toHaveBeenCalled();
|
||||
expect(onKeyDown).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user