fix(web+health): E2E flow 测试全面修复 — 15/15 通过
- 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:
@@ -9,36 +9,43 @@ type E2eFixtures = {
|
||||
authenticatedPage: Page;
|
||||
};
|
||||
|
||||
let loginPromise: Promise<{ access_token: string; refresh_token: string; user: object }> | null = null;
|
||||
interface LoginResult {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
user: object;
|
||||
}
|
||||
|
||||
function login() {
|
||||
if (!loginPromise) {
|
||||
loginPromise = (async () => {
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/auth/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username: process.env.E2E_ADMIN_USER || 'admin',
|
||||
password: process.env.E2E_ADMIN_PASS || 'Admin@2026',
|
||||
}),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.success) return json.data;
|
||||
} catch { /* retry */ }
|
||||
await new Promise((r) => setTimeout(r, 500 * (attempt + 1)));
|
||||
async function login(): Promise<LoginResult> {
|
||||
for (let attempt = 0; attempt < 5; attempt++) {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/auth/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username: process.env.E2E_ADMIN_USER || 'admin',
|
||||
password: process.env.E2E_ADMIN_PASS || 'Admin@2026',
|
||||
}),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '');
|
||||
throw new Error(`HTTP ${res.status}: ${text.slice(0, 100)}`);
|
||||
}
|
||||
throw new Error('Login failed after 3 attempts');
|
||||
})();
|
||||
const json = await res.json();
|
||||
if (json.success) return json.data;
|
||||
throw new Error(`Login unsuccessful: ${json.error ?? 'unknown'}`);
|
||||
} catch (err) {
|
||||
if (attempt === 4) throw err;
|
||||
await new Promise((r) => setTimeout(r, 1000 * (attempt + 1)));
|
||||
}
|
||||
}
|
||||
return loginPromise;
|
||||
throw new Error('Login failed after 5 attempts');
|
||||
}
|
||||
|
||||
export const test = base.extend<E2eFixtures>({
|
||||
api: async ({}, use) => {
|
||||
const { access_token } = await login();
|
||||
const client = new ApiClient();
|
||||
await client.loginAsAdmin();
|
||||
client['token'] = access_token;
|
||||
await use(client);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user