fix(web+health): E2E flow 测试全面修复 — 15/15 通过
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- test-data: 接口对齐后端 DTO(VitalSigns/AlertRule/Schedule/FollowUp)
- api-client: 增强 HTTP 错误处理(parseJson 统一防护非 JSON 响应)
- auth.fixture: 每个测试获取新 token,避免共享 token 过期
- patient-detail: tab 名称修正为 '健康数据' → '体征数据'
- patient-list: DrawerForm 选择器适配(无 phone 字段、保存按钮在 extra)
- vital-signs-flow: API 录入 + 页面验证,避免复杂 DatePicker 交互
- alert-flow: 简化为规则 CRUD + 页面导航,condition_params 对齐后端格式
- follow-up-template handler: 权限码从 health.follow-up-template.* 修正为 health.follow-up.*
- playwright.config: workers=1 串行执行避免并发登录
- check-readiness: 健康端点路径修正为 /api/v1/health
This commit is contained in:
iven
2026-04-29 06:04:22 +08:00
parent c6e8048bc5
commit a491eb19a6
12 changed files with 183 additions and 156 deletions

View File

@@ -1,5 +1,5 @@
// apps/web/e2e/pages/health-data.page.ts
import type { Page } from '@playwright/test';
import type { Page, Locator } from '@playwright/test';
export class HealthDataPage {
readonly page: Page;
@@ -10,25 +10,54 @@ export class HealthDataPage {
async clickAddVitalSigns() {
await this.page.click('button:has-text("录入体征"), button:has-text("新增")');
await this.page.waitForSelector('.ant-modal, .ant-drawer', { timeout: 5000 });
await this.page.waitForSelector('.ant-modal', { timeout: 5000 });
}
private formField(labelText: string): Locator {
const modal = this.page.locator('.ant-modal');
return modal.locator('.ant-form-item').filter({ hasText: labelText }).locator('input');
}
async fillVitalSignsForm(data: {
systolic_bp?: number;
diastolic_bp?: number;
record_date?: string;
systolic_bp_morning?: number;
diastolic_bp_morning?: number;
heart_rate?: number;
temperature?: number;
body_temperature?: number;
spo2?: number;
weight?: number;
blood_sugar?: number;
}) {
if (data.systolic_bp) await this.page.fill('#systolic_bp, input[placeholder*="收缩压"]', String(data.systolic_bp));
if (data.diastolic_bp) await this.page.fill('#diastolic_bp, input[placeholder*="舒张压"]', String(data.diastolic_bp));
if (data.heart_rate) await this.page.fill('#heart_rate, input[placeholder*="心率"]', String(data.heart_rate));
if (data.temperature) await this.page.fill('#temperature, input[placeholder*="体温"]', String(data.temperature));
if (data.spo2) await this.page.fill('#spo2, input[placeholder*="血氧"]', String(data.spo2));
const modal = this.page.locator('.ant-modal');
// Fill date - DatePicker needs special handling
const dateToFill = data.record_date || new Date().toISOString().slice(0, 10);
const datePicker = modal.locator('.ant-form-item').filter({ hasText: '记录日期' }).locator('input');
await datePicker.click();
await datePicker.fill(dateToFill);
await this.page.keyboard.press('Enter');
await this.page.waitForTimeout(300);
if (data.systolic_bp_morning) {
await this.formField('收缩压(晨)').fill(String(data.systolic_bp_morning));
}
if (data.diastolic_bp_morning) {
await this.formField('舒张压(晨)').fill(String(data.diastolic_bp_morning));
}
if (data.heart_rate) {
await this.formField('心率').fill(String(data.heart_rate));
}
if (data.weight) {
await this.formField('体重').fill(String(data.weight));
}
if (data.blood_sugar) {
await this.formField('血糖').fill(String(data.blood_sugar));
}
}
async submitVitalSigns() {
await this.page.click('.ant-modal button[type="submit"], .ant-btn-primary');
const modal = this.page.locator('.ant-modal');
await modal.locator('.ant-modal-footer button.ant-btn-primary').click();
await this.page.waitForSelector('.ant-message-success', { timeout: 10000 });
}

View File

@@ -14,7 +14,7 @@ export class PatientDetailPage {
}
async getPatientName(): Promise<string> {
const el = this.page.locator('.ant-descriptions-item-content').first();
const el = this.page.locator('div[style*="font-weight"]').first();
return el.textContent() ?? '';
}

View File

@@ -18,27 +18,26 @@ export class PatientListPage {
await this.page.waitForSelector('.ant-modal, .ant-drawer', { timeout: 5000 });
}
async fillCreateForm(data: { name: string; gender?: string; birth_date?: string; phone?: string }) {
await this.page.fill('#name, input[id="name"]', data.name);
if (data.phone) {
await this.page.fill('#phone, input[id="phone"]', data.phone);
}
async fillCreateForm(data: { name: string; gender?: string; birth_date?: string }) {
const drawer = this.page.locator('.ant-drawer');
await drawer.locator('input').first().waitFor({ state: 'visible' });
await this.page.locator('.ant-drawer [name="name"] input, .ant-drawer input').first().fill(data.name);
if (data.gender) {
await this.page.click('.ant-select[id="gender"], .ant-select:has-text("性别")');
await this.page.click(`.ant-select-item-option:has-text("${data.gender === 'male' ? '男' : '女'}")`);
await drawer.locator('.ant-select').first().click();
await this.page.locator(`.ant-select-item-option:has-text("${data.gender === 'male' ? '男' : '女'}")`).first().click();
}
if (data.birth_date) {
await this.page.fill('#birth_date, input[placeholder*="出生"]', data.birth_date);
await drawer.locator('[name="birth_date"] input, input[placeholder*="出生"]').fill(data.birth_date);
}
}
async submitForm() {
await this.page.click('.ant-modal button[type="submit"], .ant-drawer button[type="submit"]');
await this.page.click('.ant-drawer button.ant-btn-primary, button:has-text("保存"), .ant-modal .ant-btn-primary');
await this.page.waitForSelector('.ant-message-success', { timeout: 10000 });
}
async searchPatient(name: string) {
const searchInput = this.page.locator('input[placeholder*="搜索"], input[placeholder*="姓名"]');
const searchInput = this.page.locator('input[placeholder*="搜索"]').first();
await searchInput.fill(name);
await searchInput.press('Enter');
await this.page.waitForTimeout(1000);