test(web): PatientList/AlertList/DoctorList 页面测试 — 验证工厂模式
- 添加 matchMedia + ResizeObserver mock (Ant Design 依赖) - renderWithProviders 注入 auth state + localStorage token - 修复 fixture 批量生成自动分配唯一 id - PatientList 5 测试 / AlertList 3 测试 / DoctorList 4 测试
This commit is contained in:
20
apps/web/src/pages/health/AlertList.test.tsx
Normal file
20
apps/web/src/pages/health/AlertList.test.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { createListPageTests } from '../../test/factories/listPageTests';
|
||||
import { createFixtureList, createAlertFixture } from '../../test/fixtures';
|
||||
import AlertList from './AlertList';
|
||||
|
||||
const mockAlerts = createFixtureList(createAlertFixture, 12, [
|
||||
{ id: 'alert-1', severity: 'high', status: 'active', message: '血压异常偏高' },
|
||||
{ id: 'alert-2', severity: 'medium', status: 'active', message: '心率偏高' },
|
||||
]);
|
||||
|
||||
createListPageTests({
|
||||
Component: AlertList,
|
||||
apiPath: '/api/v1/health/alerts',
|
||||
columns: ['严重程度', '状态'],
|
||||
firstRowTexts: ['血压异常偏高'],
|
||||
totalItems: 12,
|
||||
hasCreateButton: false,
|
||||
hasSearch: true,
|
||||
hasPagination: false,
|
||||
mockItems: mockAlerts as Record<string, unknown>[],
|
||||
});
|
||||
18
apps/web/src/pages/health/DoctorList.test.tsx
Normal file
18
apps/web/src/pages/health/DoctorList.test.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createListPageTests } from '../../test/factories/listPageTests';
|
||||
import { createFixtureList, createDoctorFixture } from '../../test/fixtures';
|
||||
import DoctorList from './DoctorList';
|
||||
|
||||
const mockDoctors = createFixtureList(createDoctorFixture, 8);
|
||||
|
||||
createListPageTests({
|
||||
Component: DoctorList,
|
||||
apiPath: '/api/v1/health/doctors',
|
||||
columns: ['姓名', '科室', '职称'],
|
||||
firstRowTexts: ['李医生'],
|
||||
totalItems: 8,
|
||||
hasCreateButton: true,
|
||||
createButtonText: '新建医护',
|
||||
hasSearch: true,
|
||||
hasPagination: false,
|
||||
mockItems: mockDoctors as Record<string, unknown>[],
|
||||
});
|
||||
23
apps/web/src/pages/health/PatientList.test.tsx
Normal file
23
apps/web/src/pages/health/PatientList.test.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { server } from '../../test/mocks/server';
|
||||
import { createListPageTests } from '../../test/factories/listPageTests';
|
||||
import { createFixtureList, createPatientFixture } from '../../test/fixtures';
|
||||
import PatientList from './PatientList';
|
||||
|
||||
const mockPatients = createFixtureList(createPatientFixture, 25, [
|
||||
{ id: 'patient-1', name: '张三', gender: 'male' },
|
||||
{ id: 'patient-2', name: '李四', gender: 'female' },
|
||||
]);
|
||||
|
||||
createListPageTests({
|
||||
Component: PatientList,
|
||||
apiPath: '/api/v1/health/patients',
|
||||
columns: ['姓名', '性别', '年龄'],
|
||||
firstRowTexts: ['张三'],
|
||||
totalItems: 25,
|
||||
hasCreateButton: true,
|
||||
createButtonText: '新建患者',
|
||||
hasSearch: true,
|
||||
hasPagination: true,
|
||||
mockItems: mockPatients as Record<string, unknown>[],
|
||||
});
|
||||
Reference in New Issue
Block a user