- default view is now the card grid (was table), matching tauri /files (viewMode='card'). - rebuild the patient card to mirror tauri files/list/CardView exactly: avatar-in-circle + name + ⋮ actions menu (view/edit) header, شماره پرونده / موبایل rows, برچسبها footer with the inline tag popover. Same Tailwind classes/colors/spacing (rounded-[6px], #EDEDED/#E0E0E0 borders, grid md:grid-cols-4 gap-[12px]). - per-view page size like tauri: 16 for card, 12 for table; reset page on view switch. - empty state text 'بیماری یافت نشد'. Frontend only; no API change. Tests updated (default card, ⋮ menu, table toggle, tag popover, filter apply) — all green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
82 lines
4.2 KiB
TypeScript
82 lines
4.2 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { screen, fireEvent, waitFor } from '@testing-library/react';
|
|
import { renderWithProviders } from '../test/utils';
|
|
|
|
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
|
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>;
|
|
const patch = api.patch as ReturnType<typeof vi.fn>;
|
|
|
|
const PATIENTS = [
|
|
{ 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: [] },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
get.mockReset();
|
|
patch.mockReset();
|
|
patch.mockResolvedValue({ success: true, data: {} });
|
|
get.mockImplementation((url: string) => {
|
|
if (url.includes('/tenant-tags')) return Promise.resolve({ success: true, data: [{ uuid: 'tag1', name: 'خوشحساب', color: '#0a0', active: true }] });
|
|
if (url.includes('/insurance-pricing')) return Promise.resolve({ success: true, data: { insurances: [{ insurance_id: 1, insurance_name: 'تأمین اجتماعی', type: 'basic' }] } });
|
|
return Promise.resolve({ success: true, data: PATIENTS, meta: { totalRecords: 2 } });
|
|
});
|
|
});
|
|
|
|
describe('PatientsListPage (پروندهها)', () => {
|
|
it('renders records as cards by default', async () => {
|
|
renderWithProviders(<PatientsListPage />, { route: '/admin/patients' });
|
|
expect(await screen.findByText('دنیا خلیلی')).toBeInTheDocument();
|
|
expect(screen.getByText('علی بدیعی زاده')).toBeInTheDocument();
|
|
// card-only labels (with colon) — proves the default view is the card grid
|
|
expect(screen.getAllByText('شماره پرونده:').length).toBe(2);
|
|
expect(screen.getByRole('button', { name: /تشکیل پرونده/ })).toBeInTheDocument();
|
|
// default card view: requests 16 per page
|
|
expect(get.mock.calls.some(([u]) => String(u).includes('limit=16'))).toBe(true);
|
|
});
|
|
|
|
it('opens the card ⋮ menu with view/edit actions', async () => {
|
|
renderWithProviders(<PatientsListPage />, { route: '/admin/patients' });
|
|
await screen.findByText('دنیا خلیلی');
|
|
fireEvent.click(screen.getAllByLabelText('عملیات')[0]);
|
|
expect(await screen.findByText('مشاهده')).toBeInTheDocument();
|
|
expect(screen.getByText('ویرایش')).toBeInTheDocument();
|
|
});
|
|
|
|
it('switches to the table view', async () => {
|
|
renderWithProviders(<PatientsListPage />, { route: '/admin/patients' });
|
|
await screen.findByText('دنیا خلیلی');
|
|
fireEvent.click(screen.getByLabelText('نمایش جدولی'));
|
|
expect(await screen.findByText('مراجعه کننده')).toBeInTheDocument(); // table header
|
|
expect(get.mock.calls.some(([u]) => String(u).includes('limit=12'))).toBe(true);
|
|
});
|
|
|
|
it('assigns a tag inline through the برچسبها popover', async () => {
|
|
renderWithProviders(<PatientsListPage />, { route: '/admin/patients' });
|
|
await screen.findByText('علی بدیعی زاده');
|
|
|
|
fireEvent.click(screen.getByText('اضافه کردن')); // open popover for the untagged record (r2)
|
|
fireEvent.click(await screen.findByText('خوشحساب')); // toggle the tenant tag
|
|
|
|
await waitFor(() => expect(patch).toHaveBeenCalledWith('/api/v1/patient/r2', { tags: ['tag1'] }));
|
|
});
|
|
|
|
it('applies an advanced filter and re-queries with the param', async () => {
|
|
renderWithProviders(<PatientsListPage />, { route: '/admin/patients' });
|
|
await screen.findByText('دنیا خلیلی');
|
|
|
|
fireEvent.click(screen.getByLabelText('فیلترها'));
|
|
fireEvent.click(await screen.findByLabelText('فقط پروندههای دارای بدهی'));
|
|
fireEvent.click(screen.getByRole('button', { name: 'اعمال تغییرات' }));
|
|
|
|
await waitFor(() => expect(get.mock.calls.some(([u]) => String(u).includes('has_debt=1'))).toBe(true));
|
|
});
|
|
});
|