import { describe, expect, it } from 'vitest'; import { render, screen } from '@testing-library/svelte'; import { cxTestArguments, cxTestResults } from '../../__tests__/cx-test'; import NumericInput from '../numeric-input.svelte'; describe('Numeric Input', () => { it('Renders the input', () => { render(NumericInput, { placeholder: 'Enter a number' }); expect(screen.getByPlaceholderText('Enter a number')).toHaveAttribute( 'type', 'number' ); }); it('Should set the input value', () => { render(NumericInput, { placeholder: 'Enter a number', value: 3.4 }); const input = screen.getByPlaceholderText('Enter a number'); // valueAsNumber should be used to retrieve input type=number values expect(input.valueAsNumber).toBe(3.4); expect(input.checkValidity()).toBe(true); }); it('Is invalid if type is integer and value is decimal', () => { render(NumericInput, { placeholder: 'Enter a number', type: 'integer', value: 12.34, }); const input = screen.getByPlaceholderText('Enter a number'); expect(input.checkValidity()).toBe(false); }); it('Renders with the passed cx classes', () => { render(NumericInput, { placeholder: 'Enter a number', cx: cxTestArguments, }); expect(screen.getByPlaceholderText('Enter a number')).toHaveClass( cxTestResults ); }); });