Add patient medical-exam entries: a new PatientMedicalRecord entity (record-scoped, CASCADE) + repository, and owner-scoped CRUD endpoints (GET list, POST create, PATCH, DELETE) under /api/v1/patient. Wire the "پرونده پزشکی" tab in PatientDetailPage (list + add/edit modal with title, date and notes + delete). PHPUnit covers CRUD + ownership + validation; Vitest covers the tab. API docs updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
3.2 KiB
TypeScript
79 lines
3.2 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { screen, fireEvent } from '@testing-library/react';
|
|
import { Routes, Route } from 'react-router-dom';
|
|
import { renderWithProviders } from '../test/utils';
|
|
|
|
vi.mock('../lib/api', () => ({
|
|
api: { get: vi.fn(), post: vi.fn(), patch: vi.fn(), put: vi.fn(), delete: vi.fn() },
|
|
ApiError: class extends Error {},
|
|
}));
|
|
|
|
import { api } from '../lib/api';
|
|
import PatientDetailPage from './PatientDetailPage';
|
|
|
|
const get = api.get as ReturnType<typeof vi.fn>;
|
|
|
|
beforeEach(() => {
|
|
get.mockReset();
|
|
get.mockImplementation((url: string) => {
|
|
if (url === '/api/v1/patient/r1') return Promise.resolve({ success: true, data: {
|
|
uuid: 'r1', user_name: 'ساغر صابری', record_number: 'P-1001',
|
|
user_mobile: '09120000000', user_national_code: '1234567890',
|
|
profile: { gender: 'female', referral_source: 'اینستاگرام', address: 'یزد', description: 'یادداشت' },
|
|
} });
|
|
return Promise.resolve({ success: true, data: [] });
|
|
});
|
|
});
|
|
|
|
function renderDetail() {
|
|
return renderWithProviders(
|
|
<Routes>
|
|
<Route path="/admin/patients/:uuid" element={<PatientDetailPage />} />
|
|
</Routes>,
|
|
{ route: '/admin/patients/r1' },
|
|
);
|
|
}
|
|
|
|
describe('PatientDetailPage (پرونده تبدار)', () => {
|
|
it('renders the header and tab bar', async () => {
|
|
renderDetail();
|
|
expect(await screen.findByText('ساغر صابری')).toBeInTheDocument();
|
|
expect(screen.getByText('سرویسها')).toBeInTheDocument();
|
|
expect(screen.getByText('اطلاعات پرونده')).toBeInTheDocument();
|
|
expect(screen.getByText('پرونده پزشکی')).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows patient info on the info tab', async () => {
|
|
renderDetail();
|
|
await screen.findByText('ساغر صابری');
|
|
fireEvent.click(screen.getByText('اطلاعات پرونده'));
|
|
expect(screen.getByText('کد ملی')).toBeInTheDocument();
|
|
expect(screen.getByText('1234567890')).toBeInTheDocument();
|
|
expect(screen.getByText('اینستاگرام')).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows a placeholder for not-yet-built tabs', async () => {
|
|
renderDetail();
|
|
await screen.findByText('ساغر صابری');
|
|
fireEvent.click(screen.getByText('پیامها'));
|
|
expect(screen.getByText(/بهزودی تکمیل میشود/)).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the attachments tab with an upload button', async () => {
|
|
renderDetail();
|
|
await screen.findByText('ساغر صابری');
|
|
fireEvent.click(screen.getByText('ضمیمه'));
|
|
expect(await screen.findByRole('button', { name: /آپلود فایل جدید/ })).toBeInTheDocument();
|
|
expect(await screen.findByText('هنوز فایلی ضمیمه نشده است.')).toBeInTheDocument();
|
|
});
|
|
|
|
it('opens the add-exam modal on the medical-record tab', async () => {
|
|
renderDetail();
|
|
await screen.findByText('ساغر صابری');
|
|
fireEvent.click(screen.getByText('پرونده پزشکی'));
|
|
fireEvent.click(await screen.findByRole('button', { name: /ثبت معاینه جدید/ }));
|
|
// modal opens with a title field
|
|
expect(await screen.findByPlaceholderText('مثلاً: معاینه اولیه')).toBeInTheDocument();
|
|
});
|
|
});
|