test(web): 添加测试数据工厂 — healthFixtures + 批量生成 + 分页包装
This commit is contained in:
94
apps/web/src/test/fixtures/healthFixtures.ts
vendored
Normal file
94
apps/web/src/test/fixtures/healthFixtures.ts
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
// --- 患者 ---
|
||||
export function createPatientFixture(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: 'patient-1',
|
||||
name: '张三',
|
||||
gender: 'male',
|
||||
birth_date: '1990-01-15',
|
||||
blood_type: 'A',
|
||||
status: 'active',
|
||||
verification_status: 'verified',
|
||||
source: 'manual',
|
||||
created_at: '2026-04-01T10:00:00Z',
|
||||
updated_at: '2026-04-01T10:00:00Z',
|
||||
version: 1,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
// --- 医生 ---
|
||||
export function createDoctorFixture(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: 'doctor-1',
|
||||
user_id: 'user-doc-1',
|
||||
name: '李医生',
|
||||
department: '内科',
|
||||
title: '主治医师',
|
||||
specialization: '心血管内科',
|
||||
phone: '13800000001',
|
||||
email: 'doctor1@test.com',
|
||||
status: 'online',
|
||||
created_at: '2026-04-01T10:00:00Z',
|
||||
updated_at: '2026-04-01T10:00:00Z',
|
||||
version: 1,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
// --- 告警 ---
|
||||
export function createAlertFixture(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: 'alert-1',
|
||||
patient_id: 'patient-1',
|
||||
patient_name: '张三',
|
||||
alert_type: 'vital_sign',
|
||||
severity: 'high',
|
||||
status: 'active',
|
||||
message: '血压异常偏高',
|
||||
created_at: '2026-04-01T10:00:00Z',
|
||||
updated_at: '2026-04-01T10:00:00Z',
|
||||
version: 1,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
// --- 预约 ---
|
||||
export function createAppointmentFixture(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: 'appt-1',
|
||||
patient_id: 'patient-1',
|
||||
patient_name: '张三',
|
||||
doctor_id: 'doctor-1',
|
||||
doctor_name: '李医生',
|
||||
appointment_date: '2026-05-10',
|
||||
start_time: '09:00',
|
||||
end_time: '09:30',
|
||||
status: 'pending',
|
||||
type: 'follow_up',
|
||||
notes: '',
|
||||
created_at: '2026-04-01T10:00:00Z',
|
||||
updated_at: '2026-04-01T10:00:00Z',
|
||||
version: 1,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
// --- 批量生成 ---
|
||||
export function createFixtureList<T>(
|
||||
factory: (overrides?: Record<string, unknown>) => T,
|
||||
count: number,
|
||||
overridesList: Record<string, unknown>[] = [],
|
||||
): T[] {
|
||||
return Array.from({ length: count }, (_, i) => factory(overridesList[i] || {}));
|
||||
}
|
||||
|
||||
// --- 分页响应包装 ---
|
||||
export function wrapPaginated<T>(items: T[], total?: number) {
|
||||
return {
|
||||
data: items,
|
||||
total: total ?? items.length,
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
total_pages: Math.ceil((total ?? items.length) / 20),
|
||||
};
|
||||
}
|
||||
1
apps/web/src/test/fixtures/index.ts
vendored
Normal file
1
apps/web/src/test/fixtures/index.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './healthFixtures';
|
||||
Reference in New Issue
Block a user