test(web+mp): E2E 测试全量实施 — Web 5 flow + MP 4 flow + 基础设施
Web 端 (Playwright): - fixtures: test-data 工厂 + API Client (乐观锁 version) + 增强 auth fixture - pages: LoginPage, PatientListPage, PatientDetailPage, HealthDataPage, AppointmentPage - flows: 患者全流程, 体征数据链路, 预约排班链路, 随访管理链路, 告警处理链路 - smoke tests 迁移到 smoke/ 目录,import 路径更新 - playwright.config.ts 更新: globalSetup 环境检查, 60s timeout, video retain 小程序端 (Vitest + miniprogram-automator): - helpers: AutomatorClient, MpApiClient, MpAuthHelper, MpNavigator - flows: 患者健康数据查看, 体征数据录入, 积分签到兑换, 积分商城浏览 - vitest.config.ts + check-readiness.ts - vitest 4.1.5 依赖安装 Playwright 发现 15 个测试 (5 flow + 10 smoke),全部就绪
This commit is contained in:
47
apps/web/e2e/flows/alert-flow.spec.ts
Normal file
47
apps/web/e2e/flows/alert-flow.spec.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
// apps/web/e2e/flows/alert-flow.spec.ts
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
import { makePatient, makeVitalSigns, makeAlertRule } from '../fixtures/test-data';
|
||||
|
||||
test.describe('@flow 告警处理链路', () => {
|
||||
const cleanup: Array<() => Promise<void>> = [];
|
||||
|
||||
test.afterEach(async () => {
|
||||
for (const fn of cleanup.reverse()) {
|
||||
await fn().catch(() => {});
|
||||
}
|
||||
cleanup.length = 0;
|
||||
});
|
||||
|
||||
test('创建规则 → 触发告警 → 查看列表 → 确认处理', async ({ api, authenticatedPage: page }) => {
|
||||
const patient = await api.createPatient(makePatient());
|
||||
cleanup.push(() => api.deletePatient(patient.id, patient.version));
|
||||
|
||||
const rule = await api.createAlertRule(makeAlertRule({
|
||||
indicator: 'heart_rate',
|
||||
condition: 'greater_than',
|
||||
threshold: 50,
|
||||
severity: 'warning',
|
||||
}));
|
||||
cleanup.push(() => api.deleteAlertRule(rule.id, rule.version));
|
||||
|
||||
const vitalSigns = await api.createVitalSigns(patient.id, makeVitalSigns({
|
||||
heart_rate: 110,
|
||||
}));
|
||||
cleanup.push(() => api.deleteVitalSigns(patient.id, vitalSigns.id, vitalSigns.version));
|
||||
|
||||
let alert: Record<string, unknown> | undefined;
|
||||
await expect(async () => {
|
||||
const alerts = await api.listAlerts();
|
||||
alert = alerts.find((a) => (a as Record<string, unknown>).patient_id === patient.id);
|
||||
expect(alert).toBeDefined();
|
||||
}).toPass({ timeout: 15000 });
|
||||
|
||||
if (!alert!) throw new Error('告警未生成');
|
||||
|
||||
await page.goto('/#/health/alerts');
|
||||
await page.waitForSelector('.ant-table', { timeout: 10000 });
|
||||
|
||||
const updated = await api.acknowledgeAlert(alert.id as string, alert.version as number);
|
||||
await api.resolveAlert(updated.id, updated.version);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user