- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
import OtpInput5 from '../OtpInput5';
|
|
|
|
describe('OtpInput5 Component', () => {
|
|
it('renders 5 input boxes', () => {
|
|
render(<OtpInput5 value="" onChange={vi.fn()} />);
|
|
const inputs = screen.getAllByRole('textbox');
|
|
expect(inputs).toHaveLength(5);
|
|
});
|
|
|
|
it('updates digit and focuses next input on typing', () => {
|
|
const handleChange = vi.fn();
|
|
render(<OtpInput5 value="" onChange={handleChange} />);
|
|
const inputs = screen.getAllByRole('textbox');
|
|
|
|
fireEvent.change(inputs[0], { target: { value: '4' } });
|
|
expect(handleChange).toHaveBeenCalledWith('4');
|
|
});
|
|
|
|
it('converts Persian digits automatically to English', () => {
|
|
const handleChange = vi.fn();
|
|
render(<OtpInput5 value="" onChange={handleChange} />);
|
|
const inputs = screen.getAllByRole('textbox');
|
|
|
|
fireEvent.change(inputs[0], { target: { value: '۹' } });
|
|
expect(handleChange).toHaveBeenCalledWith('9');
|
|
});
|
|
|
|
it('distributes full 5-digit pasted code and calls onComplete', () => {
|
|
const handleChange = vi.fn();
|
|
const handleComplete = vi.fn();
|
|
render(
|
|
<OtpInput5
|
|
value=""
|
|
onChange={handleChange}
|
|
onComplete={handleComplete}
|
|
/>,
|
|
);
|
|
const inputs = screen.getAllByRole('textbox');
|
|
|
|
fireEvent.paste(inputs[0], {
|
|
clipboardData: {
|
|
getData: () => '12345',
|
|
},
|
|
});
|
|
|
|
expect(handleChange).toHaveBeenCalledWith('12345');
|
|
expect(handleComplete).toHaveBeenCalledWith('12345');
|
|
});
|
|
|
|
it('handles backspace to navigate to previous input when current is empty', () => {
|
|
const handleChange = vi.fn();
|
|
render(<OtpInput5 value="12" onChange={handleChange} />);
|
|
const inputs = screen.getAllByRole('textbox');
|
|
|
|
fireEvent.keyDown(inputs[2], { key: 'Backspace' });
|
|
expect(handleChange).toHaveBeenCalledWith('1');
|
|
});
|
|
});
|