117 lines
3.9 KiB
TypeScript
117 lines
3.9 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
|
|
test('release build boots the setup wizard without runtime errors', async ({ page }) => {
|
|
const pageErrors: string[] = [];
|
|
const consoleErrors: string[] = [];
|
|
|
|
page.on('pageerror', (error) => pageErrors.push(error.message));
|
|
page.on('console', (message) => {
|
|
if (message.type() === 'error') consoleErrors.push(message.text());
|
|
});
|
|
await page.route('**/api/v1/setup/status', async (route) => {
|
|
await route.fulfill({
|
|
json: {
|
|
data: {
|
|
required: true,
|
|
locked: false,
|
|
supportedDatabaseTypes: ['MYSQL'],
|
|
message: '请完成安装',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
const response = await page.goto('/setup');
|
|
expect(response?.ok()).toBe(true);
|
|
await expect(page.getByRole('heading', { name: '安装向导', exact: true })).toBeVisible();
|
|
expect(pageErrors).toEqual([]);
|
|
expect(consoleErrors).toEqual([]);
|
|
});
|
|
|
|
test('release build boots the dashboard and initializes charts without runtime errors', async ({ page }) => {
|
|
const pageErrors: string[] = [];
|
|
const consoleErrors: string[] = [];
|
|
page.on('pageerror', (error) => pageErrors.push(error.message));
|
|
page.on('console', (message) => {
|
|
if (message.type() === 'error') consoleErrors.push(message.text());
|
|
});
|
|
|
|
await page.route('**/api/v1/**', async (route) => {
|
|
const pathname = new URL(route.request().url()).pathname;
|
|
if (pathname === '/api/v1/setup/status') {
|
|
await route.fulfill({ json: { data: { required: false, locked: true } } });
|
|
return;
|
|
}
|
|
if (pathname === '/api/v1/auth/session') {
|
|
await route.fulfill({
|
|
json: {
|
|
data: {
|
|
authenticated: true,
|
|
user: {
|
|
publicId: '01M00000000000000000000001',
|
|
username: 'dist-dashboard',
|
|
displayName: '构建验收管理员',
|
|
mustChangePassword: false,
|
|
},
|
|
roles: [{ code: 'SYSTEM_ADMIN', name: '超级管理员', workbenchRoute: '/dashboard' }],
|
|
activeRole: 'SYSTEM_ADMIN',
|
|
permissions: ['dashboard:overview:view'],
|
|
},
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
if (pathname === '/api/v1/auth/profile') {
|
|
await route.fulfill({
|
|
json: {
|
|
data: {
|
|
publicId: '01M00000000000000000000001',
|
|
username: 'dist-dashboard',
|
|
displayName: '构建验收管理员',
|
|
mustChangePassword: false,
|
|
},
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
if (pathname === '/api/v1/dashboard/overview') {
|
|
await route.fulfill({
|
|
json: {
|
|
data: {
|
|
title: '系统经营仪表盘',
|
|
refreshedAt: '2026-08-19T04:00:00Z',
|
|
currency: 'CNY',
|
|
system: {
|
|
overallStatus: 'UP',
|
|
currentVersion: '1.0.0-preview.49',
|
|
uptimeSeconds: 60,
|
|
services: [],
|
|
},
|
|
metrics: [],
|
|
trend: {
|
|
currency: 'CNY',
|
|
receiptsAvailable: true,
|
|
paymentsAvailable: true,
|
|
invoicesAvailable: true,
|
|
points: [{ period: '2026-08', receivedAmount: '100', paidAmount: '80', invoicedAmount: '90' }],
|
|
},
|
|
lifecycle: [],
|
|
risks: [],
|
|
geography: { available: false, message: '暂无地域数据', regions: [] },
|
|
activities: [],
|
|
},
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
await route.fulfill({ json: { data: [], meta: { page: 1, size: 20, totalElements: 0, totalPages: 0 } } });
|
|
});
|
|
|
|
const response = await page.goto('/dashboard');
|
|
expect(response?.ok()).toBe(true);
|
|
await expect(page.getByRole('heading', { name: '系统经营仪表盘', exact: true })).toBeVisible();
|
|
await expect(page.getByTestId('dashboard-chart').first()).toBeVisible();
|
|
expect(pageErrors).toEqual([]);
|
|
expect(consoleErrors).toEqual([]);
|
|
});
|