forked from akai/readest
956c71cd7b
Replace ESLint with Biome for ~14x faster linting (~360ms vs ~5s). - Add biome.json with rules matching ESLint parity (Next.js, a11y, TypeScript, unused vars/imports) - Remove eslint, @typescript-eslint/*, eslint-config-next, eslint-plugin-jsx-a11y, @eslint/* from deps - Remove eslint.config.mjs - Update lint script to: tsgo --noEmit && biome check . - Fix 11 real code issues caught by Biome (banned types, explicit any, unsafe finally, unreachable code, shadowed names) - Disable Biome formatter (Prettier stays for Tailwind class sorting) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
import { render, screen, cleanup, fireEvent } from '@testing-library/react';
|
|
|
|
import NumberInput from '@/components/settings/NumberInput';
|
|
|
|
vi.mock('@/hooks/useTranslation', () => ({
|
|
useTranslation: () => (s: string) => s,
|
|
}));
|
|
|
|
afterEach(cleanup);
|
|
|
|
describe('NumberInput', () => {
|
|
const defaultProps = {
|
|
label: 'Font Size',
|
|
value: 16,
|
|
min: 8,
|
|
max: 72,
|
|
onChange: vi.fn(),
|
|
};
|
|
|
|
it('commits value on Enter key (form submit)', () => {
|
|
const onChange = vi.fn();
|
|
render(<NumberInput {...defaultProps} onChange={onChange} />);
|
|
|
|
const input = screen.getByDisplayValue('16');
|
|
fireEvent.change(input, { target: { value: '24' } });
|
|
expect(onChange).not.toHaveBeenCalled();
|
|
|
|
// Enter triggers form submit which commits the value
|
|
fireEvent.submit(input.closest('form')!);
|
|
expect(onChange).toHaveBeenCalledWith(24);
|
|
});
|
|
|
|
it('commits value on blur', () => {
|
|
const onChange = vi.fn();
|
|
render(<NumberInput {...defaultProps} onChange={onChange} />);
|
|
|
|
const input = screen.getByDisplayValue('16');
|
|
fireEvent.change(input, { target: { value: '20' } });
|
|
fireEvent.blur(input);
|
|
expect(onChange).toHaveBeenCalledWith(20);
|
|
});
|
|
|
|
it('clamps value to min/max on commit', () => {
|
|
const onChange = vi.fn();
|
|
render(<NumberInput {...defaultProps} onChange={onChange} />);
|
|
|
|
const input = screen.getByDisplayValue('16');
|
|
fireEvent.change(input, { target: { value: '100' } });
|
|
fireEvent.submit(input.closest('form')!);
|
|
expect(onChange).toHaveBeenCalledWith(72);
|
|
});
|
|
});
|