Files
LinkPort/web/tests/database-monitoring.spec.ts
T

27 lines
1.7 KiB
TypeScript

import { expect, test } from '@playwright/test';
test('数据库监控展示压力、网关慢请求及权限提示', async ({ page }) => {
await page.route('**/api/v1/targets*', route => route.request().method() === 'GET'
? route.fulfill({ json: [{ config: { id: 'monitor-db', name: 'Monitoring Redis', type: 'redis', accounts: [] } }] }) : route.continue());
await page.route('**/api/v1/monitoring?*', route => route.fulfill({ json: {
gateways: [], health: [], intervalSeconds: 0,
slowRequests: [{ targetId: 'monitor-db', protocol: 'redis', operation: 'GET', durationMs: 1250, at: '2026-10-15T00:00:00Z' }],
} }));
await page.route('**/api/v1/monitoring/database', async route => {
expect(route.request().postDataJSON()).toMatchObject({ targetId: 'monitor-db', accountId: '' });
await route.fulfill({ json: { health: { healthy: true, latencyMs: 2 }, diagnostics: {
checkedAt: '2026-10-15T00:00:00Z', metrics: [{ name: 'used_memory', value: 4096, unit: 'bytes' }], notices: ['部分指标需要额外权限'],
} } });
});
await page.goto('/');
await page.getByRole('navigation').getByRole('button', { name: '监控运维', exact: true }).click();
const collect = page.getByRole('button', { name: '采集健康与压力', exact: true });
await expect(collect).toBeDisabled();
await page.getByRole('combobox', { name: '监控数据库', exact: true }).click();
await page.getByRole('option', { name: 'Monitoring Redis · redis', exact: true }).click();
await collect.click();
await expect(page.getByText('used_memory', { exact: true })).toBeVisible();
await expect(page.getByText('部分指标需要额外权限', { exact: true })).toBeVisible();
await expect(page.getByText('1250.0', { exact: true })).toBeVisible();
});