feat: initialize ERP base platform (extracted from HMS)
- Stripped 11 business crates (health, ai, dialysis, plugins) - Cleaned AppState, AppConfig, main.rs from business coupling - Reduced migrations from 169 to 53 (base-only) - Removed health_provider trait from erp-core - Removed business integration tests - Removed gateway rate limiting middleware - Base capabilities: auth, RBAC, JWT, config, workflow, message, plugin, audit, crypto, RLS, multi-tenant Cargo check: OK Cargo test: OK
This commit is contained in:
43
apps/web/e2e/auth.fixture.ts
Normal file
43
apps/web/e2e/auth.fixture.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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';
|
||||
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}/api/v1/health`, '后端 API');
|
||||
await check(webBase, '前端 SPA');
|
||||
console.log('✅ E2E 环境就绪');
|
||||
}
|
||||
200
apps/web/e2e/fixtures/api-client.ts
Normal file
200
apps/web/e2e/fixtures/api-client.ts
Normal file
@@ -0,0 +1,200 @@
|
||||
// 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<{ data: VEntity<Record<string, unknown>>[] }>('/health/alerts');
|
||||
return res.data ?? [];
|
||||
}
|
||||
|
||||
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 parseJson<T>(res: Response, method: string, path: string): Promise<T> {
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '');
|
||||
throw new Error(`${method} ${path} → HTTP ${res.status}: ${text.slice(0, 200)}`);
|
||||
}
|
||||
const json = await res.json();
|
||||
if (!json.success) throw new Error(`${method} ${path} failed: ${json.error ?? 'unknown'}`);
|
||||
return json.data as T;
|
||||
}
|
||||
|
||||
private async get<T>(path: string): Promise<T> {
|
||||
const res = await fetch(`${API_BASE}${path}`, { headers: await this.headers() });
|
||||
return this.parseJson<T>(res, 'GET', path);
|
||||
}
|
||||
|
||||
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),
|
||||
});
|
||||
return this.parseJson<T>(res, 'POST', path);
|
||||
}
|
||||
|
||||
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),
|
||||
});
|
||||
return this.parseJson<T>(res, 'PUT', path);
|
||||
}
|
||||
|
||||
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;
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '');
|
||||
throw new Error(`DELETE ${path} → HTTP ${res.status}: ${text.slice(0, 200)}`);
|
||||
}
|
||||
const json = await res.json();
|
||||
if (!json.success) throw new Error(`DELETE ${path} failed: ${json.error ?? 'unknown'}`);
|
||||
}
|
||||
|
||||
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),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '');
|
||||
throw new Error(`POST ${path} → HTTP ${res.status}: ${text.slice(0, 200)}`);
|
||||
}
|
||||
const json = await res.json();
|
||||
if (!json.success) throw new Error(`POST ${path} failed: ${json.error ?? 'unknown'}`);
|
||||
return json as T;
|
||||
}
|
||||
}
|
||||
73
apps/web/e2e/fixtures/auth.fixture.ts
Normal file
73
apps/web/e2e/fixtures/auth.fixture.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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;
|
||||
};
|
||||
|
||||
interface LoginResult {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
user: object;
|
||||
}
|
||||
|
||||
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)}`);
|
||||
}
|
||||
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)));
|
||||
}
|
||||
}
|
||||
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();
|
||||
client['token'] = access_token;
|
||||
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';
|
||||
198
apps/web/e2e/fixtures/test-data.ts
Normal file
198
apps/web/e2e/fixtures/test-data.ts
Normal file
@@ -0,0 +1,198 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
export interface DoctorData {
|
||||
name: string;
|
||||
department?: string;
|
||||
title?: string;
|
||||
specialty?: string;
|
||||
phone?: string;
|
||||
license_number?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface VitalSignsData {
|
||||
record_date: string;
|
||||
systolic_bp_morning?: number;
|
||||
diastolic_bp_morning?: number;
|
||||
heart_rate?: number;
|
||||
body_temperature?: number;
|
||||
spo2?: number;
|
||||
blood_sugar?: number;
|
||||
weight?: number;
|
||||
water_intake_ml?: number;
|
||||
urine_output_ml?: number;
|
||||
notes?: string;
|
||||
source?: string;
|
||||
}
|
||||
|
||||
export interface ScheduleData {
|
||||
doctor_id: string;
|
||||
schedule_date: string;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
max_appointments?: number;
|
||||
period_type?: string;
|
||||
}
|
||||
|
||||
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;
|
||||
follow_up_type: string;
|
||||
applicable_scope?: string;
|
||||
fields?: Array<{
|
||||
label: string;
|
||||
field_key: string;
|
||||
field_type: string;
|
||||
required?: boolean;
|
||||
options?: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface FollowUpTaskData {
|
||||
patient_id: string;
|
||||
follow_up_type: string;
|
||||
planned_date: string;
|
||||
assigned_to?: string;
|
||||
content_template?: string;
|
||||
}
|
||||
|
||||
export interface AlertRuleData {
|
||||
name: string;
|
||||
device_type: string;
|
||||
condition_type: string;
|
||||
condition_params: Record<string, unknown>;
|
||||
severity?: string;
|
||||
description?: string;
|
||||
apply_tags?: Record<string, unknown>;
|
||||
notify_roles?: Array<string>;
|
||||
cooldown_minutes?: number;
|
||||
}
|
||||
|
||||
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',
|
||||
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 {
|
||||
record_date: new Date().toISOString().slice(0, 10),
|
||||
systolic_bp_morning: 120,
|
||||
diastolic_bp_morning: 80,
|
||||
heart_rate: 72,
|
||||
body_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,
|
||||
schedule_date: 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自动创建的随访模板',
|
||||
follow_up_type: 'phone',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeFollowUpTask(patientId: string, _templateId: string, overrides?: Partial<FollowUpTaskData>): FollowUpTaskData {
|
||||
const plannedDate = new Date();
|
||||
plannedDate.setDate(plannedDate.getDate() + 7);
|
||||
return {
|
||||
patient_id: patientId,
|
||||
follow_up_type: 'phone',
|
||||
planned_date: plannedDate.toISOString().slice(0, 10),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeAlertRule(overrides?: Partial<AlertRuleData>): AlertRuleData {
|
||||
return {
|
||||
name: `E2E告警规则_${uid()}`,
|
||||
device_type: 'heart_rate',
|
||||
condition_type: 'single_threshold',
|
||||
condition_params: { direction: 'above', value: 50 },
|
||||
severity: 'warning',
|
||||
description: 'E2E测试低阈值规则,用于触发告警',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
28
apps/web/e2e/flows/alert-flow.spec.ts
Normal file
28
apps/web/e2e/flows/alert-flow.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// apps/web/e2e/flows/alert-flow.spec.ts
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
import { 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 rule = await api.createAlertRule(makeAlertRule());
|
||||
cleanup.push(() => api.deleteAlertRule(rule.id, rule.version));
|
||||
|
||||
await page.goto('/#/health/alert-rules');
|
||||
await page.waitForSelector('.ant-table', { timeout: 10000 });
|
||||
|
||||
const tableText = await page.locator('.ant-table-tbody').textContent();
|
||||
expect(tableText).toBeTruthy();
|
||||
|
||||
await page.goto('/#/health/alerts');
|
||||
await page.waitForSelector('.ant-table, .ant-empty', { timeout: 10000 });
|
||||
});
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
53
apps/web/e2e/flows/patient-journey.spec.ts
Normal file
53
apps/web/e2e/flows/patient-journey.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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,
|
||||
});
|
||||
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.length).toBeGreaterThan(0);
|
||||
|
||||
const assignBtn = page.locator('button:has-text("分配医生")');
|
||||
if (await assignBtn.isVisible().catch(() => false)) {
|
||||
await detailPage.clickAssignDoctor();
|
||||
await detailPage.selectDoctor(doctorData.name);
|
||||
await detailPage.confirmAssign();
|
||||
}
|
||||
});
|
||||
});
|
||||
37
apps/web/e2e/flows/vital-signs-flow.spec.ts
Normal file
37
apps/web/e2e/flows/vital-signs-flow.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// apps/web/e2e/flows/vital-signs-flow.spec.ts
|
||||
import { test, expect } from '../fixtures/auth.fixture';
|
||||
import { PatientDetailPage } from '../pages/patient-detail.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('API录入体征 → 患者详情查看体征数据列表', async ({ api, authenticatedPage: page }) => {
|
||||
const patient = await api.createPatient(makePatient());
|
||||
cleanup.push(() => api.deletePatient(patient.id, patient.version));
|
||||
|
||||
const vitalSigns = await api.createVitalSigns(patient.id, makeVitalSigns({
|
||||
systolic_bp_morning: 130,
|
||||
heart_rate: 80,
|
||||
}));
|
||||
cleanup.push(() => api.deleteVitalSigns(patient.id, vitalSigns.id, vitalSigns.version));
|
||||
|
||||
const detailPage = new PatientDetailPage(page);
|
||||
await detailPage.goto(patient.id);
|
||||
|
||||
await detailPage.clickTab('健康数据');
|
||||
await page.waitForTimeout(800);
|
||||
await detailPage.clickTab('体征数据');
|
||||
|
||||
await page.waitForSelector('.ant-table', { timeout: 10000 });
|
||||
const rows = await page.locator('.ant-table-tbody tr').count();
|
||||
expect(rows).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
15
apps/web/e2e/login.spec.ts
Normal file
15
apps/web/e2e/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); // 用户名 + 密码
|
||||
});
|
||||
});
|
||||
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 });
|
||||
}
|
||||
}
|
||||
78
apps/web/e2e/pages/health-data.page.ts
Normal file
78
apps/web/e2e/pages/health-data.page.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
// apps/web/e2e/pages/health-data.page.ts
|
||||
import type { Page, Locator } 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', { 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: {
|
||||
record_date?: string;
|
||||
systolic_bp_morning?: number;
|
||||
diastolic_bp_morning?: number;
|
||||
heart_rate?: number;
|
||||
body_temperature?: number;
|
||||
spo2?: number;
|
||||
weight?: number;
|
||||
blood_sugar?: number;
|
||||
}) {
|
||||
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() {
|
||||
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 });
|
||||
}
|
||||
|
||||
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('div[style*="font-weight"]').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 });
|
||||
}
|
||||
}
|
||||
66
apps/web/e2e/pages/patient-list.page.ts
Normal file
66
apps/web/e2e/pages/patient-list.page.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
// 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 }) {
|
||||
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 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 drawer.locator('[name="birth_date"] input, input[placeholder*="出生"]').fill(data.birth_date);
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
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*="搜索"]').first();
|
||||
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;
|
||||
}
|
||||
}
|
||||
24
apps/web/e2e/plugins.spec.ts
Normal file
24
apps/web/e2e/plugins.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { test, expect } from './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();
|
||||
}
|
||||
});
|
||||
});
|
||||
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');
|
||||
});
|
||||
});
|
||||
39
apps/web/e2e/tenant-isolation.spec.ts
Normal file
39
apps/web/e2e/tenant-isolation.spec.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { test, expect } from './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/users.spec.ts
Normal file
48
apps/web/e2e/users.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { test, expect } from './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