mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-01 03:45:53 -05:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
/** @vitest-environment jsdom */
|
|
|
|
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import { NumberInput } from './controls';
|
|
|
|
afterEach(cleanup);
|
|
|
|
describe('NumberInput', () => {
|
|
it('renders on its own and reports the entered number', () => {
|
|
const onValueChange = vi.fn();
|
|
|
|
render(<NumberInput aria-label='Limit' value={10} onValueChange={onValueChange} />);
|
|
|
|
const input = screen.getByRole('textbox', { name: 'Limit' });
|
|
|
|
expect(input).toHaveValue('10');
|
|
|
|
fireEvent.change(input, { target: { value: '25' } });
|
|
fireEvent.blur(input);
|
|
|
|
expect(onValueChange).toHaveBeenLastCalledWith(25, expect.anything());
|
|
});
|
|
|
|
it('reports an emptied field as null', () => {
|
|
const onValueChange = vi.fn();
|
|
|
|
render(<NumberInput aria-label='Limit' value={10} onValueChange={onValueChange} />);
|
|
|
|
const input = screen.getByRole('textbox', { name: 'Limit' });
|
|
|
|
fireEvent.change(input, { target: { value: '' } });
|
|
fireEvent.blur(input);
|
|
|
|
expect(onValueChange).toHaveBeenLastCalledWith(null, expect.anything());
|
|
});
|
|
});
|