Files
clinicpro/assets/admin/components/ui/PersianDateInput.test.tsx
T
hamed 773f9d4d16 feat: update session payment logic to ensure accurate payable amounts and reflect consumables in cost breakdown
- Adjusted the calculation of payable amounts in PaymentStep to align with server logic, ensuring overpayments are handled correctly.
- Enhanced DetailsStep to include consumables in the itemized cost breakdown, ensuring consistency with patient share calculations.
- Updated tests for SessionPaymentPage to validate new behavior regarding overpayments and consumable listings.
- Modified PatientController to register SessionPayment correctly when settling sessions via wallet, preventing double charges.
- Refactored WalletService to remove outdated methods and ensure wallet transactions reflect the correct amounts after discounts.
- Improved accessibility in SearchableSelect component by adding aria labels and ensuring proper role attributes for screen readers.
- Updated styles to ensure minimum touch targets meet WCAG guidelines for mobile usability.
2026-07-19 13:29:46 +03:30

45 lines
2.4 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import PersianDateInput from '@/components/ui/PersianDateInput';
describe('PersianDateInput', () => {
it('placeholder را وقتی مقدار خالی است نشان می‌دهد', () => {
render(<PersianDateInput value="" onChange={vi.fn()} placeholder="از تاریخ" />);
expect(screen.getByText('از تاریخ')).toBeInTheDocument();
});
it('از تقویم شمسی استفاده می‌کند نه input بومی میلادی', () => {
const { container } = render(<PersianDateInput value="" onChange={vi.fn()} />);
expect(container.querySelector('input[type="date"]')).toBeNull();
});
it('با کلیک، تقویم شمسی باز می‌شود (نام ماه فارسی)', () => {
const { container } = render(<PersianDateInput value="2024-03-25" onChange={vi.fn()} />);
fireEvent.click((container.firstChild as HTMLElement).firstChild as Element);
// 2024-03-25 میلادی = ۶ فروردین ۱۴۰۳ شمسی
expect(screen.getByText('فروردین')).toBeInTheDocument();
});
it('انتخاب روز، onChange را با YYYY-MM-DD میلادی صدا می‌زند', () => {
const onChange = vi.fn();
const { container } = render(<PersianDateInput value="2024-03-25" onChange={onChange} />);
fireEvent.click((container.firstChild as HTMLElement).firstChild as Element);
// تقویم با createPortal به document.body می‌رود، پس بیرون از container است
const target = Array.from(document.body.querySelectorAll('button')).find(
(b) => b.textContent?.trim() === '۱۵',
);
expect(target).toBeTruthy();
fireEvent.click(target as Element);
expect(onChange).toHaveBeenCalledWith(expect.stringMatching(/^\d{4}-\d{2}-\d{2}$/));
});
it('دکمه پاک‌کردن، onChange با رشته خالی می‌فرستد', () => {
const onChange = vi.fn();
const { container } = render(<PersianDateInput value="2024-03-25" onChange={onChange} />);
const svgs = container.querySelectorAll('svg');
const clearIcon = svgs[svgs.length - 1];
fireEvent.click(clearIcon.parentElement as Element);
expect(onChange).toHaveBeenCalledWith('');
});
});