Files
clinicpro/assets/admin/components/PatientRecordInfoForm.test.tsx
T
hamedandClaude Opus 4.8 46ee24d101 feat: add supplementary insurance select to patient record info form
The «اطلاعات پرونده» form only exposed basic insurance («نوع بیمه»). Add a
«بیمه تکمیلی» select next to it, wired to the supplementary insurances from
insurance-pricing. Backend PATCH /api/v1/patient/{uuid} already accepts
supplementary_insurance_id (UserProfile entity + controller) — frontend-only:
schema field, form select, profileToFormValues/formValuesToPayload mapping,
PatientProfileUpdate type, and the supplementary option passed from both the
case-file info tab (PatientDetailPage) and MyPatientsPage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-16 10:59:23 +03:30

88 lines
3.5 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import PatientRecordInfoForm, {
type PatientFormValues,
type PatientFormOptions,
} from '@/components/PatientRecordInfoForm';
const options: PatientFormOptions = {
gender: [{ value: 'female', label: 'زن' }, { value: 'male', label: 'مرد' }],
marital: [{ value: 'single', label: 'مجرد' }],
education: [{ value: 'bachelor', label: 'کارشناسی' }],
insurance: [{ value: 3, label: 'تأمین اجتماعی' }],
supplementary: [{ value: 5, label: 'بیمه دانا' }],
province: [{ value: 8, label: 'یزد' }],
city: [{ value: 42, label: 'یزد' }],
referral: [{ value: 'instagram', label: 'اینستاگرام' }],
};
const baseValues: PatientFormValues = {
name: 'ساغر صابری نژاد',
mobile: '',
national_code: '',
gender: null,
birth_date: '',
fathers_name: '',
marital_status: null,
basic_insurance_id: null,
supplementary_insurance_id: null,
field_of_study: '',
education: null,
job: '',
province_id: null,
city_id: null,
home_phone: '',
address: '',
postal_code: '',
referral_source: null,
description: '',
};
function setup(overrides: Partial<PatientFormValues> = {}) {
const onSubmit = vi.fn();
render(
<PatientRecordInfoForm
defaultValues={{ ...baseValues, ...overrides }}
recordNumber="123456789"
options={options}
onSubmit={onSubmit}
/>,
);
return { onSubmit };
}
describe('PatientRecordInfoForm', () => {
it('برچسب‌های اصلی و شماره پروندهٔ read-only را رندر می‌کند', () => {
setup();
expect(screen.getByText('نام و نام خانوادگی مراجعه کننده')).toBeInTheDocument();
expect(screen.getByText('بیمه پایه')).toBeInTheDocument();
expect(screen.getByText('بیمه تکمیلی')).toBeInTheDocument();
expect(screen.getByText('نحوه آشنایی')).toBeInTheDocument();
expect((screen.getByDisplayValue('123456789') as HTMLInputElement).readOnly).toBe(true);
});
it('نام خالی → خطای الزامی و onSubmit صدا نمی‌خورد', async () => {
const { onSubmit } = setup({ name: '' });
await userEvent.click(screen.getByRole('button', { name: /ثبت اطلاعات/ }));
expect(await screen.findByText('نام و نام خانوادگی الزامی است')).toBeInTheDocument();
expect(onSubmit).not.toHaveBeenCalled();
});
it('کدملی نامعتبر → خطای ۱۰ رقم', async () => {
setup({ national_code: '123' });
await userEvent.click(screen.getByRole('button', { name: /ثبت اطلاعات/ }));
expect(await screen.findByText('کد ملی باید ۱۰ رقم باشد')).toBeInTheDocument();
});
it('ورودی معتبر → onSubmit با مقادیر فرم', async () => {
const { onSubmit } = setup({ national_code: '0012345678' });
await userEvent.click(screen.getByRole('button', { name: /ثبت اطلاعات/ }));
await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1));
expect(onSubmit.mock.calls[0][0]).toMatchObject({
name: 'ساغر صابری نژاد',
national_code: '0012345678',
});
});
});