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:
22
apps/web/e2e/check-readiness.ts
Normal file
22
apps/web/e2e/check-readiness.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// apps/web/e2e/check-readiness.ts
|
||||
import type { FullConfig } from '@playwright/test';
|
||||
|
||||
async function check(url: string, label: string): Promise<void> {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
try {
|
||||
const res = await fetch(url);
|
||||
if (res.ok) return;
|
||||
} catch { /* retry */ }
|
||||
console.log(`⏳ ${label} 未就绪,等待重试 (${i + 1}/5)...`);
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
}
|
||||
throw new Error(`❌ ${label} 未就绪: ${url}。请确认后端服务已启动 (cd crates/erp-server && cargo run)`);
|
||||
}
|
||||
|
||||
export default async function globalSetup(_config: FullConfig) {
|
||||
const apiBase = process.env.E2E_API_URL || 'http://localhost:3000';
|
||||
const webBase = process.env.E2E_BASE_URL || 'http://localhost:5174';
|
||||
await check(`${apiBase}/health/live`, '后端 API');
|
||||
await check(webBase, '前端 SPA');
|
||||
console.log('✅ E2E 环境就绪');
|
||||
}
|
||||
188
apps/web/e2e/fixtures/api-client.ts
Normal file
188
apps/web/e2e/fixtures/api-client.ts
Normal file
@@ -0,0 +1,188 @@
|
||||
// apps/web/e2e/fixtures/api-client.ts
|
||||
|
||||
import type {
|
||||
PatientData, DoctorData, VitalSignsData, ScheduleData,
|
||||
AppointmentData, FollowUpTemplateData, FollowUpTaskData, AlertRuleData,
|
||||
} from './test-data';
|
||||
|
||||
const API_BASE = process.env.E2E_API_URL || 'http://localhost:3000/api/v1';
|
||||
|
||||
interface ApiResponse<T> { success: boolean; data: T }
|
||||
interface Versioned { id: string; version: number }
|
||||
type VEntity<T> = T & Versioned;
|
||||
|
||||
interface LoginResponse {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
expires_in: number;
|
||||
user: { id: string; username: string; display_name: string; roles: string[] };
|
||||
}
|
||||
|
||||
export class ApiClient {
|
||||
private token = '';
|
||||
|
||||
async login(username?: string, password?: string): Promise<LoginResponse> {
|
||||
const res = await this.rawPost<{ success: boolean; data: LoginResponse }>(
|
||||
'/auth/login',
|
||||
{
|
||||
username: username || process.env.E2E_ADMIN_USER || 'admin',
|
||||
password: password || process.env.E2E_ADMIN_PASS || 'Admin@2026',
|
||||
},
|
||||
);
|
||||
this.token = res.data.access_token;
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async loginAsAdmin(): Promise<LoginResponse> {
|
||||
return this.login();
|
||||
}
|
||||
|
||||
getToken(): string { return this.token; }
|
||||
|
||||
async createPatient(overrides?: Partial<PatientData>): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.post('/health/patients', overrides ?? {});
|
||||
}
|
||||
|
||||
async updatePatient(id: string, version: number, data: Partial<PatientData>): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.put(`/health/patients/${id}`, { ...data, version });
|
||||
}
|
||||
|
||||
async deletePatient(id: string, version: number): Promise<void> {
|
||||
await this.del(`/health/patients/${id}`, { version });
|
||||
}
|
||||
|
||||
async createDoctor(overrides?: Partial<DoctorData>): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.post('/health/doctors', overrides ?? {});
|
||||
}
|
||||
|
||||
async deleteDoctor(id: string, version: number): Promise<void> {
|
||||
await this.del(`/health/doctors/${id}`, { version });
|
||||
}
|
||||
|
||||
async createVitalSigns(patientId: string, overrides?: Partial<VitalSignsData>): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.post(`/health/patients/${patientId}/vital-signs`, overrides ?? {});
|
||||
}
|
||||
|
||||
async deleteVitalSigns(patientId: string, id: string, version: number): Promise<void> {
|
||||
await this.del(`/health/patients/${patientId}/vital-signs/${id}`, { version });
|
||||
}
|
||||
|
||||
async createSchedule(overrides: ScheduleData): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.post('/health/doctor-schedules', overrides);
|
||||
}
|
||||
|
||||
async deleteSchedule(id: string, version: number): Promise<void> {
|
||||
await this.del(`/health/doctor-schedules/${id}`, { version });
|
||||
}
|
||||
|
||||
async createAppointment(overrides: AppointmentData): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.post('/health/appointments', overrides);
|
||||
}
|
||||
|
||||
async updateAppointmentStatus(id: string, version: number, status: string): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.put(`/health/appointments/${id}/status`, { status, version });
|
||||
}
|
||||
|
||||
async deleteAppointment(id: string, version: number): Promise<void> {
|
||||
await this.del(`/health/appointments/${id}`, { version });
|
||||
}
|
||||
|
||||
async createFollowUpTemplate(overrides?: Partial<FollowUpTemplateData>): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.post('/health/follow-up-templates', overrides ?? {});
|
||||
}
|
||||
|
||||
async deleteFollowUpTemplate(id: string, version: number): Promise<void> {
|
||||
await this.del(`/health/follow-up-templates/${id}`, { version });
|
||||
}
|
||||
|
||||
async createFollowUpTask(overrides: FollowUpTaskData): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.post('/health/follow-up-tasks', overrides);
|
||||
}
|
||||
|
||||
async deleteFollowUpTask(id: string, version: number): Promise<void> {
|
||||
await this.del(`/health/follow-up-tasks/${id}`, { version });
|
||||
}
|
||||
|
||||
async createAlertRule(overrides?: Partial<AlertRuleData>): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.post('/health/alert-rules', overrides ?? {});
|
||||
}
|
||||
|
||||
async deleteAlertRule(id: string, version: number): Promise<void> {
|
||||
await this.del(`/health/alert-rules/${id}`, { version });
|
||||
}
|
||||
|
||||
async listAlerts(): Promise<VEntity<Record<string, unknown>>[]> {
|
||||
const res = await this.get<{ items: VEntity<Record<string, unknown>>[] }>('/health/alerts');
|
||||
return res.items ?? [];
|
||||
}
|
||||
|
||||
async acknowledgeAlert(id: string, version: number): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.put(`/health/alerts/${id}/acknowledge`, { version });
|
||||
}
|
||||
|
||||
async resolveAlert(id: string, version: number): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.put(`/health/alerts/${id}/resolve`, { version });
|
||||
}
|
||||
|
||||
async dismissAlert(id: string, version: number): Promise<VEntity<Record<string, unknown>>> {
|
||||
return this.put(`/health/alerts/${id}/dismiss`, { version });
|
||||
}
|
||||
|
||||
private async headers(): Promise<Record<string, string>> {
|
||||
return {
|
||||
'Content-Type': 'application/json',
|
||||
...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
private async get<T>(path: string): Promise<T> {
|
||||
const res = await fetch(`${API_BASE}${path}`, { headers: await this.headers() });
|
||||
const json = await res.json();
|
||||
if (!json.success) throw new Error(`GET ${path} failed: ${json.error ?? res.status}`);
|
||||
return json.data as T;
|
||||
}
|
||||
|
||||
private async post<T>(path: string, body: unknown): Promise<T> {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
method: 'POST',
|
||||
headers: await this.headers(),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.success) throw new Error(`POST ${path} failed: ${json.error ?? res.status}`);
|
||||
return json.data as T;
|
||||
}
|
||||
|
||||
private async put<T>(path: string, body: unknown): Promise<T> {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
method: 'PUT',
|
||||
headers: await this.headers(),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.success) throw new Error(`PUT ${path} failed: ${json.error ?? res.status}`);
|
||||
return json.data as T;
|
||||
}
|
||||
|
||||
private async del(path: string, body?: unknown): Promise<void> {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
method: 'DELETE',
|
||||
headers: await this.headers(),
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
if (res.status === 204) return;
|
||||
const json = await res.json();
|
||||
if (!json.success) throw new Error(`DELETE ${path} failed: ${json.error ?? res.status}`);
|
||||
}
|
||||
|
||||
private async rawPost<T>(path: string, body: unknown): Promise<T> {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.success) throw new Error(`POST ${path} failed: ${json.error ?? res.status}`);
|
||||
return json as T;
|
||||
}
|
||||
}
|
||||
66
apps/web/e2e/fixtures/auth.fixture.ts
Normal file
66
apps/web/e2e/fixtures/auth.fixture.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
// apps/web/e2e/fixtures/auth.fixture.ts
|
||||
import { test as base, type Page } from '@playwright/test';
|
||||
import { ApiClient } from './api-client';
|
||||
|
||||
const API_BASE = process.env.E2E_API_URL || 'http://localhost:3000/api/v1';
|
||||
|
||||
type E2eFixtures = {
|
||||
api: ApiClient;
|
||||
authenticatedPage: Page;
|
||||
};
|
||||
|
||||
let loginPromise: Promise<{ access_token: string; refresh_token: string; user: object }> | null = null;
|
||||
|
||||
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)));
|
||||
}
|
||||
throw new Error('Login failed after 3 attempts');
|
||||
})();
|
||||
}
|
||||
return loginPromise;
|
||||
}
|
||||
|
||||
export const test = base.extend<E2eFixtures>({
|
||||
api: async ({}, use) => {
|
||||
const client = new ApiClient();
|
||||
await client.loginAsAdmin();
|
||||
await use(client);
|
||||
},
|
||||
|
||||
authenticatedPage: async ({ page }, use) => {
|
||||
const { access_token, refresh_token, user } = await login();
|
||||
await page.addInitScript((args) => {
|
||||
localStorage.setItem('access_token', args.token);
|
||||
localStorage.setItem('refresh_token', args.refresh);
|
||||
localStorage.setItem('user', JSON.stringify(args.userData));
|
||||
}, { token: access_token, refresh: refresh_token, userData: user });
|
||||
await use(page);
|
||||
},
|
||||
|
||||
page: async ({ page }, use) => {
|
||||
const { access_token, refresh_token, user } = await login();
|
||||
await page.addInitScript((args) => {
|
||||
localStorage.setItem('access_token', args.token);
|
||||
localStorage.setItem('refresh_token', args.refresh);
|
||||
localStorage.setItem('user', JSON.stringify(args.userData));
|
||||
}, { token: access_token, refresh: refresh_token, userData: user });
|
||||
await use(page);
|
||||
},
|
||||
});
|
||||
|
||||
export { expect } from '@playwright/test';
|
||||
190
apps/web/e2e/fixtures/test-data.ts
Normal file
190
apps/web/e2e/fixtures/test-data.ts
Normal file
@@ -0,0 +1,190 @@
|
||||
// apps/web/e2e/fixtures/test-data.ts
|
||||
|
||||
export interface PatientData {
|
||||
name: string;
|
||||
gender?: string;
|
||||
birth_date?: string;
|
||||
blood_type?: string;
|
||||
id_number?: string;
|
||||
allergy_history?: string;
|
||||
medical_history_summary?: string;
|
||||
emergency_contact_name?: string;
|
||||
emergency_contact_phone?: string;
|
||||
source?: string;
|
||||
notes?: string;
|
||||
phone?: string;
|
||||
}
|
||||
|
||||
export interface DoctorData {
|
||||
name: string;
|
||||
department?: string;
|
||||
title?: string;
|
||||
specialty?: string;
|
||||
phone?: string;
|
||||
license_number?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface VitalSignsData {
|
||||
systolic_bp?: number;
|
||||
diastolic_bp?: number;
|
||||
heart_rate?: number;
|
||||
temperature?: number;
|
||||
spo2?: number;
|
||||
blood_glucose_fasting?: number;
|
||||
blood_glucose_postprandial?: number;
|
||||
weight?: number;
|
||||
height?: number;
|
||||
recorded_at?: string;
|
||||
source?: string;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
export interface ScheduleData {
|
||||
doctor_id: string;
|
||||
date: string;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
max_appointments?: number;
|
||||
}
|
||||
|
||||
export interface AppointmentData {
|
||||
patient_id: string;
|
||||
doctor_id: string;
|
||||
schedule_id: string;
|
||||
appointment_date: string;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface FollowUpTemplateData {
|
||||
name: string;
|
||||
description?: string;
|
||||
frequency_days: number;
|
||||
total_rounds: number;
|
||||
questions?: string;
|
||||
}
|
||||
|
||||
export interface FollowUpTaskData {
|
||||
patient_id: string;
|
||||
template_id: string;
|
||||
assigned_to?: string;
|
||||
due_date: string;
|
||||
}
|
||||
|
||||
export interface AlertRuleData {
|
||||
name: string;
|
||||
indicator: string;
|
||||
condition: string;
|
||||
threshold: number;
|
||||
severity: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
let counter = 0;
|
||||
|
||||
function uid(): string {
|
||||
counter += 1;
|
||||
return `${Date.now()}_${counter}_${Math.random().toString(36).slice(2, 6)}`;
|
||||
}
|
||||
|
||||
export function makePatient(overrides?: Partial<PatientData>): PatientData {
|
||||
const id = uid();
|
||||
return {
|
||||
name: `E2E患者_${id}`,
|
||||
gender: 'male',
|
||||
birth_date: '1990-01-15',
|
||||
phone: `138${String(Math.random()).slice(2, 11)}`,
|
||||
id_number: `110101199001${String(Math.random()).slice(2, 8)}`,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeDoctor(overrides?: Partial<DoctorData>): DoctorData {
|
||||
const id = uid();
|
||||
return {
|
||||
name: `E2E医生_${id}`,
|
||||
department: '内科',
|
||||
title: '主治医师',
|
||||
specialty: '全科',
|
||||
license_number: `DOC${id}`,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeVitalSigns(overrides?: Partial<VitalSignsData>): VitalSignsData {
|
||||
return {
|
||||
systolic_bp: 120,
|
||||
diastolic_bp: 80,
|
||||
heart_rate: 72,
|
||||
temperature: 36.5,
|
||||
spo2: 98,
|
||||
source: 'web_e2e',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeSchedule(doctorId: string, overrides?: Partial<ScheduleData>): ScheduleData {
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
const date = tomorrow.toISOString().slice(0, 10);
|
||||
return {
|
||||
doctor_id: doctorId,
|
||||
date,
|
||||
start_time: '09:00',
|
||||
end_time: '12:00',
|
||||
max_appointments: 10,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeAppointment(patientId: string, doctorId: string, scheduleId: string, overrides?: Partial<AppointmentData>): AppointmentData {
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
const date = tomorrow.toISOString().slice(0, 10);
|
||||
return {
|
||||
patient_id: patientId,
|
||||
doctor_id: doctorId,
|
||||
schedule_id: scheduleId,
|
||||
appointment_date: date,
|
||||
start_time: '09:00',
|
||||
end_time: '10:00',
|
||||
reason: 'E2E测试预约',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeFollowUpTemplate(overrides?: Partial<FollowUpTemplateData>): FollowUpTemplateData {
|
||||
return {
|
||||
name: `E2E随访模板_${uid()}`,
|
||||
description: 'E2E自动创建的随访模板',
|
||||
frequency_days: 7,
|
||||
total_rounds: 3,
|
||||
questions: JSON.stringify([{ question: '血压是否正常?', type: 'yes_no' }]),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeFollowUpTask(patientId: string, templateId: string, overrides?: Partial<FollowUpTaskData>): FollowUpTaskData {
|
||||
const dueDate = new Date();
|
||||
dueDate.setDate(dueDate.getDate() + 7);
|
||||
return {
|
||||
patient_id: patientId,
|
||||
template_id: templateId,
|
||||
due_date: dueDate.toISOString().slice(0, 10),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeAlertRule(overrides?: Partial<AlertRuleData>): AlertRuleData {
|
||||
return {
|
||||
name: `E2E告警规则_${uid()}`,
|
||||
indicator: 'heart_rate',
|
||||
condition: 'greater_than',
|
||||
threshold: 50,
|
||||
severity: 'warning',
|
||||
description: 'E2E测试低阈值规则,用于触发告警',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
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);
|
||||
});
|
||||
});
|
||||
38
apps/web/e2e/flows/appointment-flow.spec.ts
Normal file
38
apps/web/e2e/flows/appointment-flow.spec.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// apps/web/e2e/flows/appointment-flow.spec.ts
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
import { AppointmentPage } from '../pages/appointment.page';
|
||||
import { makePatient, makeDoctor, makeSchedule, makeAppointment } 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 doctor = await api.createDoctor(makeDoctor());
|
||||
cleanup.push(() => api.deleteDoctor(doctor.id, doctor.version));
|
||||
|
||||
const patient = await api.createPatient(makePatient());
|
||||
cleanup.push(() => api.deletePatient(patient.id, patient.version));
|
||||
|
||||
const schedule = await api.createSchedule(makeSchedule(doctor.id));
|
||||
cleanup.push(() => api.deleteSchedule(schedule.id, schedule.version));
|
||||
|
||||
const appointmentPage = new AppointmentPage(page);
|
||||
await appointmentPage.gotoSchedule();
|
||||
|
||||
const appointment = await api.createAppointment(
|
||||
makeAppointment(patient.id, doctor.id, schedule.id),
|
||||
);
|
||||
cleanup.push(() => api.deleteAppointment(appointment.id, appointment.version));
|
||||
|
||||
await appointmentPage.gotoAppointments();
|
||||
const tableText = await page.locator('.ant-table-tbody').textContent();
|
||||
expect(tableText).toBeTruthy();
|
||||
});
|
||||
});
|
||||
36
apps/web/e2e/flows/follow-up-flow.spec.ts
Normal file
36
apps/web/e2e/flows/follow-up-flow.spec.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
// apps/web/e2e/flows/follow-up-flow.spec.ts
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
import { makePatient, makeFollowUpTemplate, makeFollowUpTask } 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 template = await api.createFollowUpTemplate(makeFollowUpTemplate());
|
||||
cleanup.push(() => api.deleteFollowUpTemplate(template.id, template.version));
|
||||
|
||||
await page.goto('/#/health/follow-up-tasks');
|
||||
await page.waitForSelector('.ant-table', { timeout: 10000 });
|
||||
|
||||
const task = await api.createFollowUpTask(
|
||||
makeFollowUpTask(patient.id, template.id),
|
||||
);
|
||||
cleanup.push(() => api.deleteFollowUpTask(task.id, task.version));
|
||||
|
||||
await page.reload();
|
||||
await page.waitForSelector('.ant-table');
|
||||
|
||||
const rowCount = await page.locator('.ant-table-tbody tr').count();
|
||||
expect(rowCount).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
51
apps/web/e2e/flows/patient-journey.spec.ts
Normal file
51
apps/web/e2e/flows/patient-journey.spec.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
// apps/web/e2e/flows/patient-journey.spec.ts
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
import { PatientListPage } from '../pages/patient-list.page';
|
||||
import { PatientDetailPage } from '../pages/patient-detail.page';
|
||||
import { makePatient, makeDoctor } 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 doctorData = makeDoctor();
|
||||
const doctor = await api.createDoctor(doctorData);
|
||||
cleanup.push(() => api.deleteDoctor(doctor.id, doctor.version));
|
||||
|
||||
const listPage = new PatientListPage(page);
|
||||
await listPage.goto();
|
||||
|
||||
const patientData = makePatient();
|
||||
await listPage.clickCreate();
|
||||
await listPage.fillCreateForm({
|
||||
name: patientData.name,
|
||||
phone: patientData.phone,
|
||||
});
|
||||
await listPage.submitForm();
|
||||
|
||||
await expect(async () => {
|
||||
const found = await listPage.hasPatientInTable(patientData.name);
|
||||
expect(found).toBeTruthy();
|
||||
}).toPass({ timeout: 10000 });
|
||||
|
||||
const patient = await api.createPatient({ ...patientData, name: `${patientData.name}_detail` });
|
||||
cleanup.push(() => api.deletePatient(patient.id, patient.version));
|
||||
|
||||
const detailPage = new PatientDetailPage(page);
|
||||
await detailPage.goto(patient.id);
|
||||
|
||||
const name = await detailPage.getPatientName();
|
||||
expect(name).toContain('E2E');
|
||||
|
||||
await detailPage.clickAssignDoctor();
|
||||
await detailPage.selectDoctor(doctorData.name);
|
||||
await detailPage.confirmAssign();
|
||||
});
|
||||
});
|
||||
49
apps/web/e2e/flows/vital-signs-flow.spec.ts
Normal file
49
apps/web/e2e/flows/vital-signs-flow.spec.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
// apps/web/e2e/flows/vital-signs-flow.spec.ts
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
import { PatientDetailPage } from '../pages/patient-detail.page';
|
||||
import { HealthDataPage } from '../pages/health-data.page';
|
||||
import { makePatient, makeVitalSigns } 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 detailPage = new PatientDetailPage(page);
|
||||
await detailPage.goto(patient.id);
|
||||
|
||||
await detailPage.clickTab('体征');
|
||||
|
||||
const healthPage = new HealthDataPage(page);
|
||||
await healthPage.clickAddVitalSigns();
|
||||
await healthPage.fillVitalSignsForm({
|
||||
systolic_bp: 125,
|
||||
diastolic_bp: 82,
|
||||
heart_rate: 75,
|
||||
});
|
||||
await healthPage.submitVitalSigns();
|
||||
|
||||
const list = await healthPage.getVitalSignsList();
|
||||
expect(list.length).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const vitalSigns = await api.createVitalSigns(patient.id, makeVitalSigns({
|
||||
systolic_bp: 130,
|
||||
heart_rate: 80,
|
||||
}));
|
||||
cleanup.push(() => api.deleteVitalSigns(patient.id, vitalSigns.id, vitalSigns.version));
|
||||
|
||||
await page.reload();
|
||||
await page.waitForSelector('.ant-table');
|
||||
const updatedList = await healthPage.getVitalSignsList();
|
||||
expect(updatedList.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
56
apps/web/e2e/pages/appointment.page.ts
Normal file
56
apps/web/e2e/pages/appointment.page.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
// apps/web/e2e/pages/appointment.page.ts
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
export class AppointmentPage {
|
||||
readonly page: Page;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
async gotoSchedule() {
|
||||
await this.page.goto('/#/health/schedules');
|
||||
await this.page.waitForSelector('.ant-table, .ant-fullcalendar, [class*="calendar"]', { timeout: 10000 });
|
||||
}
|
||||
|
||||
async gotoAppointments() {
|
||||
await this.page.goto('/#/health/appointments');
|
||||
await this.page.waitForSelector('.ant-table', { timeout: 10000 });
|
||||
}
|
||||
|
||||
async clickCreateSchedule() {
|
||||
await this.page.click('button:has-text("新增排班"), button:has-text("创建")');
|
||||
await this.page.waitForSelector('.ant-modal, .ant-drawer', { timeout: 5000 });
|
||||
}
|
||||
|
||||
async fillScheduleForm(data: { doctor_id?: string; date: string; start_time: string; end_time: string }) {
|
||||
if (data.doctor_id) {
|
||||
await this.page.click('.ant-select');
|
||||
await this.page.click('.ant-select-item-option');
|
||||
}
|
||||
await this.page.fill('input[placeholder*="日期"]', data.date);
|
||||
await this.page.fill('input[placeholder*="开始"]', data.start_time);
|
||||
await this.page.fill('input[placeholder*="结束"]', data.end_time);
|
||||
}
|
||||
|
||||
async submitScheduleForm() {
|
||||
await this.page.click('.ant-modal button[type="submit"], .ant-btn-primary');
|
||||
await this.page.waitForSelector('.ant-message-success', { timeout: 10000 });
|
||||
}
|
||||
|
||||
async clickCreateAppointment() {
|
||||
await this.page.click('button:has-text("新增预约"), button:has-text("创建")');
|
||||
await this.page.waitForSelector('.ant-modal, .ant-drawer', { timeout: 5000 });
|
||||
}
|
||||
|
||||
async fillAppointmentForm(data: { patient_id: string; doctor_id: string; date: string; reason?: string }) {
|
||||
if (data.reason) {
|
||||
await this.page.fill('textarea, input[placeholder*="原因"]', data.reason);
|
||||
}
|
||||
}
|
||||
|
||||
async submitAppointmentForm() {
|
||||
await this.page.click('.ant-modal button[type="submit"], .ant-btn-primary');
|
||||
await this.page.waitForSelector('.ant-message-success', { timeout: 10000 });
|
||||
}
|
||||
}
|
||||
49
apps/web/e2e/pages/health-data.page.ts
Normal file
49
apps/web/e2e/pages/health-data.page.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
// apps/web/e2e/pages/health-data.page.ts
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
export class HealthDataPage {
|
||||
readonly page: Page;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
async clickAddVitalSigns() {
|
||||
await this.page.click('button:has-text("录入体征"), button:has-text("新增")');
|
||||
await this.page.waitForSelector('.ant-modal, .ant-drawer', { timeout: 5000 });
|
||||
}
|
||||
|
||||
async fillVitalSignsForm(data: {
|
||||
systolic_bp?: number;
|
||||
diastolic_bp?: number;
|
||||
heart_rate?: number;
|
||||
temperature?: number;
|
||||
spo2?: 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));
|
||||
}
|
||||
|
||||
async submitVitalSigns() {
|
||||
await this.page.click('.ant-modal button[type="submit"], .ant-btn-primary');
|
||||
await this.page.waitForSelector('.ant-message-success', { timeout: 10000 });
|
||||
}
|
||||
|
||||
async getVitalSignsList(): Promise<string[]> {
|
||||
const rows = this.page.locator('.ant-table-tbody tr');
|
||||
const count = await rows.count();
|
||||
const texts: string[] = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
texts.push(await rows.nth(i).textContent() ?? '');
|
||||
}
|
||||
return texts;
|
||||
}
|
||||
|
||||
async trendChartIsVisible(): Promise<boolean> {
|
||||
const chart = this.page.locator('canvas, .recharts-wrapper, [class*="chart"]');
|
||||
return chart.isVisible();
|
||||
}
|
||||
}
|
||||
6
apps/web/e2e/pages/index.ts
Normal file
6
apps/web/e2e/pages/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// apps/web/e2e/pages/index.ts
|
||||
export { LoginPage } from './login.page';
|
||||
export { PatientListPage } from './patient-list.page';
|
||||
export { PatientDetailPage } from './patient-detail.page';
|
||||
export { HealthDataPage } from './health-data.page';
|
||||
export { AppointmentPage } from './appointment.page';
|
||||
48
apps/web/e2e/pages/login.page.ts
Normal file
48
apps/web/e2e/pages/login.page.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// apps/web/e2e/pages/login.page.ts
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
export class LoginPage {
|
||||
readonly page: Page;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/#/login');
|
||||
await this.page.waitForSelector('.ant-card, .ant-form');
|
||||
}
|
||||
|
||||
async fillUsername(username: string) {
|
||||
await this.page.fill('input[id="username"], input[placeholder*="用户名"]', username);
|
||||
}
|
||||
|
||||
async fillPassword(password: string) {
|
||||
await this.page.fill('input[type="password"]', password);
|
||||
}
|
||||
|
||||
async clickSubmit() {
|
||||
await this.page.click('button[type="submit"]');
|
||||
}
|
||||
|
||||
async login(username: string, password: string) {
|
||||
await this.goto();
|
||||
await this.fillUsername(username);
|
||||
await this.fillPassword(password);
|
||||
await this.clickSubmit();
|
||||
}
|
||||
|
||||
async getErrorMessage(): Promise<string> {
|
||||
const el = this.page.locator('.ant-form-item-explain-error, .ant-message-error, .ant-alert-error');
|
||||
return el.first().textContent() ?? '';
|
||||
}
|
||||
|
||||
async isLoggedIn(): Promise<boolean> {
|
||||
try {
|
||||
await this.page.waitForURL('**/#/', { timeout: 5000 });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
apps/web/e2e/pages/patient-detail.page.ts
Normal file
44
apps/web/e2e/pages/patient-detail.page.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// apps/web/e2e/pages/patient-detail.page.ts
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
export class PatientDetailPage {
|
||||
readonly page: Page;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
async goto(id: string) {
|
||||
await this.page.goto(`/#/health/patients/${id}`);
|
||||
await this.page.waitForSelector('.ant-descriptions, .ant-tabs', { timeout: 10000 });
|
||||
}
|
||||
|
||||
async getPatientName(): Promise<string> {
|
||||
const el = this.page.locator('.ant-descriptions-item-content').first();
|
||||
return el.textContent() ?? '';
|
||||
}
|
||||
|
||||
async clickTab(tabName: string) {
|
||||
await this.page.click(`.ant-tabs-tab:has-text("${tabName}")`);
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async getVitalSignsCount(): Promise<number> {
|
||||
return this.page.locator('.ant-table-tbody tr').count();
|
||||
}
|
||||
|
||||
async clickAssignDoctor() {
|
||||
await this.page.click('button:has-text("分配医生")');
|
||||
await this.page.waitForSelector('.ant-modal, .ant-drawer', { timeout: 5000 });
|
||||
}
|
||||
|
||||
async selectDoctor(doctorName: string) {
|
||||
await this.page.click('.ant-select');
|
||||
await this.page.click(`.ant-select-item-option:has-text("${doctorName}")`);
|
||||
}
|
||||
|
||||
async confirmAssign() {
|
||||
await this.page.click('.ant-modal button[type="submit"], .ant-btn-primary');
|
||||
await this.page.waitForSelector('.ant-message-success', { timeout: 5000 });
|
||||
}
|
||||
}
|
||||
67
apps/web/e2e/pages/patient-list.page.ts
Normal file
67
apps/web/e2e/pages/patient-list.page.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
// apps/web/e2e/pages/patient-list.page.ts
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
export class PatientListPage {
|
||||
readonly page: Page;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/#/health/patients');
|
||||
await this.page.waitForSelector('.ant-table', { timeout: 15000 });
|
||||
}
|
||||
|
||||
async clickCreate() {
|
||||
await this.page.click('button:has-text("新增"), button:has-text("新建"), button:has-text("创建")');
|
||||
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);
|
||||
}
|
||||
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' ? '男' : '女'}")`);
|
||||
}
|
||||
if (data.birth_date) {
|
||||
await this.page.fill('#birth_date, input[placeholder*="出生"]', data.birth_date);
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
await this.page.click('.ant-modal button[type="submit"], .ant-drawer button[type="submit"]');
|
||||
await this.page.waitForSelector('.ant-message-success', { timeout: 10000 });
|
||||
}
|
||||
|
||||
async searchPatient(name: string) {
|
||||
const searchInput = this.page.locator('input[placeholder*="搜索"], input[placeholder*="姓名"]');
|
||||
await searchInput.fill(name);
|
||||
await searchInput.press('Enter');
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async clickPatientRow(row: number) {
|
||||
const rows = this.page.locator('.ant-table-tbody tr');
|
||||
await rows.nth(row).click();
|
||||
}
|
||||
|
||||
async clickPatientByName(name: string) {
|
||||
await this.searchPatient(name);
|
||||
const row = this.page.locator(`.ant-table-tbody tr:has-text("${name}")`).first();
|
||||
await row.click();
|
||||
}
|
||||
|
||||
async getTableRowCount(): Promise<number> {
|
||||
return this.page.locator('.ant-table-tbody tr').count();
|
||||
}
|
||||
|
||||
async hasPatientInTable(name: string): Promise<boolean> {
|
||||
await this.searchPatient(name);
|
||||
const count = await this.page.locator(`.ant-table-tbody tr:has-text("${name}")`).count();
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
15
apps/web/e2e/smoke/login.spec.ts
Normal file
15
apps/web/e2e/smoke/login.spec.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('登录流程', () => {
|
||||
test('显示登录页面', async ({ page }) => {
|
||||
await page.goto('/#/login');
|
||||
await expect(page.locator('.ant-card, .ant-form')).toBeVisible();
|
||||
});
|
||||
|
||||
test('空表单提交显示验证错误', async ({ page }) => {
|
||||
await page.goto('/#/login');
|
||||
await page.click('button[type="submit"]');
|
||||
// Ant Design 应显示验证错误
|
||||
await expect(page.locator('.ant-form-item-explain-error')).toHaveCount(2); // 用户名 + 密码
|
||||
});
|
||||
});
|
||||
24
apps/web/e2e/smoke/plugins.spec.ts
Normal file
24
apps/web/e2e/smoke/plugins.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
|
||||
test.describe('插件管理', () => {
|
||||
test('插件管理页面加载', async ({ page }) => {
|
||||
await page.goto('/#/');
|
||||
// 侧边栏显示"扩展管理插件管理"
|
||||
await page.locator('text=扩展管理').first().click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
// 页面不崩溃
|
||||
await expect(page.locator('main')).toBeVisible();
|
||||
});
|
||||
|
||||
test('刷新按钮可点击', async ({ page }) => {
|
||||
await page.goto('/#/');
|
||||
await page.locator('text=扩展管理').first().click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
const refreshBtn = page.locator('button:has-text("刷新")');
|
||||
if (await refreshBtn.isVisible().catch(() => false)) {
|
||||
await expect(refreshBtn).toBeEnabled();
|
||||
await refreshBtn.click();
|
||||
await expect(page.locator('main')).toBeVisible();
|
||||
}
|
||||
});
|
||||
});
|
||||
39
apps/web/e2e/smoke/tenant-isolation.spec.ts
Normal file
39
apps/web/e2e/smoke/tenant-isolation.spec.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
|
||||
test.describe('多租户隔离', () => {
|
||||
test('侧边栏按模块分组显示', async ({ page }) => {
|
||||
await page.goto('/#/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// 验证侧边栏模块分组
|
||||
await expect(page.locator('text=基础模块').first()).toBeVisible({ timeout: 10000 });
|
||||
await expect(page.locator('text=业务模块').first()).toBeVisible();
|
||||
await expect(page.locator('text=系统').first()).toBeVisible();
|
||||
|
||||
// 验证关键菜单项
|
||||
await expect(page.locator('text=工作台').first()).toBeVisible();
|
||||
await expect(page.locator('text=用户管理').first()).toBeVisible();
|
||||
});
|
||||
|
||||
test('顶部导航栏显示用户信息', async ({ page }) => {
|
||||
await page.goto('/#/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// 验证顶部导航栏显示管理员信息
|
||||
await expect(page.locator('text=系统管理员').first()).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test('页面间导航正常工作', async ({ page }) => {
|
||||
await page.goto('/#/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// 点击侧边栏的用户管理(精确匹配侧边栏区域)
|
||||
const sidebar = page.locator('complementary, [class*=sider], [class*=menu], nav').first();
|
||||
await sidebar.locator('text=用户管理').first().click();
|
||||
await expect(page).toHaveURL(/#\/users/, { timeout: 10000 });
|
||||
|
||||
// 点击工作台返回
|
||||
await sidebar.locator('text=工作台').first().click();
|
||||
await expect(page).toHaveURL(/#\/$/, { timeout: 10000 });
|
||||
});
|
||||
});
|
||||
48
apps/web/e2e/smoke/users.spec.ts
Normal file
48
apps/web/e2e/smoke/users.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
|
||||
test.describe('用户管理', () => {
|
||||
test('用户列表页面加载并显示表格', async ({ page }) => {
|
||||
await page.goto('/#/');
|
||||
// 通过侧边栏导航到用户管理
|
||||
await page.locator('text=用户管理').first().click();
|
||||
await expect(page).toHaveURL(/#\/users/, { timeout: 10000 });
|
||||
|
||||
// 标题
|
||||
await expect(page.locator('h4')).toContainText('用户管理');
|
||||
// 新建用户按钮
|
||||
await expect(page.locator('button:has-text("新建用户")')).toBeVisible();
|
||||
// 搜索框
|
||||
await expect(page.locator('input[placeholder*="搜索"]')).toBeVisible();
|
||||
// 表格列头
|
||||
await expect(page.locator('text=用户').first()).toBeVisible();
|
||||
await expect(page.locator('text=状态').first()).toBeVisible();
|
||||
});
|
||||
|
||||
test('新建用户弹窗表单验证', async ({ page }) => {
|
||||
await page.goto('/#/');
|
||||
await page.locator('text=用户管理').first().click();
|
||||
await expect(page).toHaveURL(/#\/users/, { timeout: 10000 });
|
||||
|
||||
// 点击新建
|
||||
await page.click('button:has-text("新建用户")');
|
||||
// 弹窗出现
|
||||
await expect(page.locator('.ant-modal')).toBeVisible();
|
||||
// 直接提交应显示验证错误(点击 modal 内最后一个 button 即确认按钮)
|
||||
const modalButtons = page.locator('.ant-modal .ant-modal-footer button');
|
||||
await modalButtons.last().click();
|
||||
// Ant Design 应显示验证错误(用户名 + 密码必填)
|
||||
await expect(page.locator('.ant-form-item-explain-error')).toHaveCount(2);
|
||||
// 关闭弹窗(点击第一个按钮即取消)
|
||||
await modalButtons.first().click();
|
||||
});
|
||||
|
||||
test('搜索框可输入', async ({ page }) => {
|
||||
await page.goto('/#/');
|
||||
await page.locator('text=用户管理').first().click();
|
||||
await expect(page).toHaveURL(/#\/users/, { timeout: 10000 });
|
||||
|
||||
const searchInput = page.locator('input[placeholder*="搜索"]');
|
||||
await searchInput.fill('admin');
|
||||
await expect(searchInput).toHaveValue('admin');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user