feat(NewAppointmentModal): implement pricing retrieval and validation for visit costs
This commit is contained in:
@@ -94,3 +94,40 @@ describe('NewAppointmentModal — جستجوی موبایلمحور', () => {
|
||||
})));
|
||||
});
|
||||
});
|
||||
|
||||
describe('NewAppointmentModal — هزینه ویزیت', () => {
|
||||
/** تعرفه را برای همان پزشکِ اسلات برمیگرداند؛ بقیهٔ GETها بیمارِ ناشناس. */
|
||||
function mockPricing(rials: number, requireVisit = false) {
|
||||
get.mockImplementation((url: string) =>
|
||||
url.startsWith('/api/v1/insurance-pricing')
|
||||
? Promise.resolve({ success: true, data: { free_visit_price_rials: rials, require_visit_price: requireVisit } })
|
||||
: Promise.resolve({ success: true, data: { found: false } }));
|
||||
}
|
||||
|
||||
it('تعرفه را با doctor_uuid همان اسلات میخواند و در فیلد میگذارد', async () => {
|
||||
mockPricing(2_120_000);
|
||||
renderWithProviders(<NewAppointmentModal slot={slot} onClose={() => {}} onSuccess={() => {}} />);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(get).toHaveBeenCalledWith('/api/v1/insurance-pricing?doctor_uuid=doc1'));
|
||||
// ۲٬۱۲۰٬۰۰۰ ریال = ۲۱۲٬۰۰۰ تومان
|
||||
await waitFor(() => expect(screen.getByPlaceholderText('0')).toHaveValue('۲۱۲٬۰۰۰'));
|
||||
});
|
||||
|
||||
it('بدون تعرفه، فیلد صفر میماند و اختیاری است', async () => {
|
||||
mockPricing(0);
|
||||
renderWithProviders(<NewAppointmentModal slot={slot} onClose={() => {}} onSuccess={() => {}} />);
|
||||
|
||||
await screen.findByText(/تعرفهای ثبت نشده/);
|
||||
expect(screen.getByPlaceholderText('0')).toHaveValue('');
|
||||
expect(screen.getByText('(اختیاری)')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('با الزامی بودن هزینه ویزیت و مبلغ صفر، ثبت غیرفعال است', async () => {
|
||||
mockPricing(0, true);
|
||||
renderWithProviders(<NewAppointmentModal slot={slot} onClose={() => {}} onSuccess={() => {}} />);
|
||||
|
||||
await screen.findByText('هزینه ویزیت الزامی است');
|
||||
expect(screen.getByRole('button', { name: 'ثبت نوبت' })).toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user