## 前端修复 - 修复 9 个 TypeScript 编译错误(未使用变量/undefined 守卫/vitest 类型) - 重写 E2E auth fixture 使用真实 API 登录替代 mock token - 更新 E2E 测试选择器适配当前 UI 布局 - Playwright 改为串行执行避免 token 唯一约束冲突 - E2E 测试从 0/10 通过提升到 10/10 通过 ## 小程序接口一致性修复(P0-P3) - P0: consultation.ts type→consultation_type, unread_count→unread_count_patient - P0: followup.ts task_type→follow_up_type, due_date→planned_date, description→content_template - P1: appointment.ts calendarView 展平嵌套结构, available_count 计算 max-current - P1: doctor.ts HealthSummary 适配后台实际返回结构 - P2: doctor.ts PatientStats/ConsultationStats/FollowUpStats 字段名对齐 - P3: article.ts 新增 buildCategoryTree 工具函数
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { test as base } from '@playwright/test';
|
|
|
|
const API_BASE = 'http://localhost:3000/api/v1';
|
|
|
|
let loginPromise: Promise<{ token: string; user: unknown }> | null = null;
|
|
|
|
function login(): Promise<{ token: string; user: unknown }> {
|
|
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: 'admin', password: 'Admin@2026' }),
|
|
});
|
|
const json = await res.json();
|
|
if (json.success) {
|
|
return { token: json.data.access_token, user: json.data.user };
|
|
}
|
|
} catch {}
|
|
// Wait before retry on collision
|
|
await new Promise((r) => setTimeout(r, 500 * (attempt + 1)));
|
|
}
|
|
throw new Error('Login failed after 3 attempts');
|
|
})();
|
|
}
|
|
return loginPromise;
|
|
}
|
|
|
|
export const test = base.extend({
|
|
page: async ({ page }, use) => {
|
|
const { token, user } = await login();
|
|
await page.addInitScript((args) => {
|
|
localStorage.setItem('access_token', args.token);
|
|
localStorage.setItem('refresh_token', args.token);
|
|
localStorage.setItem('user', JSON.stringify(args.user));
|
|
}, { token, user });
|
|
await use(page);
|
|
},
|
|
});
|
|
|
|
export { expect } from '@playwright/test';
|