import { describe, it, expect, vi } from 'vitest'; import { render, screen, fireEvent } from '@testing-library/react'; import DigitInput from './DigitInput'; describe('DigitInput — ورودی عددی با تبدیل رقم فارسی', () => { it('converts Persian/Arabic digits to English (happy path)', () => { const onChange = vi.fn(); render(); fireEvent.change(screen.getByPlaceholderText('p'), { target: { value: '۰۹۱۲٣٤' } }); expect(onChange).toHaveBeenCalledWith('091234'); }); it('strips non-digit characters (error/garbage input)', () => { const onChange = vi.fn(); render(); fireEvent.change(screen.getByPlaceholderText('p'), { target: { value: '0a9 1-2b' } }); expect(onChange).toHaveBeenCalledWith('0912'); }); it('enforces maxDigits and handles empty input (boundary)', () => { const onChange = vi.fn(); render(); const input = screen.getByPlaceholderText('p'); fireEvent.change(input, { target: { value: '۱۲۳۴۵۶۷۸۹۰۱۲' } }); expect(onChange).toHaveBeenCalledWith('1234567890'); expect(input).toHaveAttribute('dir', 'ltr'); expect(input).toHaveAttribute('inputmode', 'numeric'); }); });