feat(patients): phase A — records list + create/edit form (Figma)
Rebuild the patient records (پروندهها) area, phase A of the Figma redesign:
- BE: add a clinic-scoped `record_number` and a TenantTag `tags` M2M to
PatientRecord (migration + EAGER-hydrated collection). POST /patient and
PATCH /patient/{uuid} now accept `record_number` and tenant-scoped `tags`
(foreign tag → 422); demographic fields (gender, date_of_birth,
referral_source, description) continue to live on UserProfile via PATCH.
- FE: new PatientsListPage (table + card views, search, pagination, tags
column, "تشکیل پرونده") at /admin/patients, and PatientRecordFormPage
(create/edit) that POSTs the record then PATCHes the demographics. Point
the sidebar "پرونده" entry to the new list.
Phases B–E (tabbed patient file, service stepper, invoice, payments/wallet,
call-center) follow. Backend covered by PHPUnit, FE by Vitest.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { screen, fireEvent } from '@testing-library/react';
|
||||
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 PatientsListPage from './PatientsListPage';
|
||||
|
||||
const get = api.get as ReturnType<typeof vi.fn>;
|
||||
|
||||
beforeEach(() => {
|
||||
get.mockReset();
|
||||
get.mockResolvedValue({
|
||||
success: true,
|
||||
data: [
|
||||
{ uuid: 'r1', user_name: 'دنیا خلیلی', user_mobile: '09165401233', user_national_code: '1744023654', record_number: '123456789', tags: [{ uuid: 't1', name: 'فوری', color: '#F00' }] },
|
||||
{ uuid: 'r2', user_name: 'علی بدیعی زاده', user_mobile: '09165401233', user_national_code: null, record_number: '123456789', tags: [] },
|
||||
],
|
||||
meta: { totalRecords: 2 },
|
||||
});
|
||||
});
|
||||
|
||||
describe('PatientsListPage (پروندهها)', () => {
|
||||
it('renders the records table with the create button', async () => {
|
||||
renderWithProviders(<PatientsListPage />, { route: '/admin/patients' });
|
||||
expect(await screen.findByText('دنیا خلیلی')).toBeInTheDocument();
|
||||
expect(screen.getByText('علی بدیعی زاده')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /تشکیل پرونده/ })).toBeInTheDocument();
|
||||
// record with no tags shows the "add" link
|
||||
expect(screen.getByText('+ اضافه کردن')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('switches to the card view', async () => {
|
||||
renderWithProviders(<PatientsListPage />, { route: '/admin/patients' });
|
||||
await screen.findByText('دنیا خلیلی');
|
||||
fireEvent.click(screen.getByLabelText('نمایش کارتی'));
|
||||
expect(screen.getByText('دنیا خلیلی')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('مشاهده').length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user