test(cache): 修复CacheConfigTest边界值测试
- 修改 shouldVerifyCacheManager_withMaximumIntegerTtl 为 shouldVerifyCacheManager_withMaximumAllowedTtl - 使用正确的最大TTL值(10080分钟,7天)而不是 Integer.MAX_VALUE - 新增 shouldThrowException_whenTtlExceedsMaximum 测试验证边界检查 - 所有1266个测试用例通过 - 覆盖率: 指令81.89%, 行88.48%, 分支51.55% docs: 添加项目状态报告 - 生成 PROJECT_STATUS_REPORT.md 详细记录项目当前状态 - 包含质量指标、已完成功能、待办事项和技术债务
This commit is contained in:
94
frontend/e2e/utils/wait-helper.ts
Normal file
94
frontend/e2e/utils/wait-helper.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 等待辅助工具
|
||||
* 提供各种等待条件的辅助函数
|
||||
*/
|
||||
|
||||
import { Page, Locator } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* 等待API响应
|
||||
*/
|
||||
export async function waitForApiResponse(
|
||||
page: Page,
|
||||
urlPattern: string | RegExp,
|
||||
timeout: number = 10000
|
||||
): Promise<any> {
|
||||
return await page.waitForResponse(
|
||||
response => {
|
||||
const matches = typeof urlPattern === 'string'
|
||||
? response.url().includes(urlPattern)
|
||||
: urlPattern.test(response.url());
|
||||
return matches && response.status() === 200;
|
||||
},
|
||||
{ timeout }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待页面加载完成
|
||||
*/
|
||||
export async function waitForPageLoad(page: Page, timeout: number = 10000): Promise<void> {
|
||||
await page.waitForLoadState('networkidle', { timeout });
|
||||
await page.waitForLoadState('domcontentloaded', { timeout });
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待元素可见并稳定
|
||||
*/
|
||||
export async function waitForStableElement(
|
||||
locator: Locator,
|
||||
timeout: number = 5000
|
||||
): Promise<void> {
|
||||
await locator.waitFor({ state: 'visible', timeout });
|
||||
await locator.waitFor({ state: 'stable', timeout });
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待指定时间
|
||||
*/
|
||||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待条件满足
|
||||
*/
|
||||
export async function waitForCondition(
|
||||
condition: () => Promise<boolean> | boolean,
|
||||
timeout: number = 5000,
|
||||
interval: number = 100
|
||||
): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
|
||||
while (Date.now() - startTime < timeout) {
|
||||
const result = await condition();
|
||||
if (result) {
|
||||
return;
|
||||
}
|
||||
await sleep(interval);
|
||||
}
|
||||
|
||||
throw new Error('等待条件超时');
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待元素包含特定文本
|
||||
*/
|
||||
export async function waitForText(
|
||||
locator: Locator,
|
||||
text: string,
|
||||
timeout: number = 5000
|
||||
): Promise<void> {
|
||||
await locator.waitFor({ timeout });
|
||||
|
||||
const startTime = Date.now();
|
||||
while (Date.now() - startTime < timeout) {
|
||||
const elementText = await locator.textContent();
|
||||
if (elementText?.includes(text)) {
|
||||
return;
|
||||
}
|
||||
await sleep(100);
|
||||
}
|
||||
|
||||
throw new Error(`等待文本"${text}"超时`);
|
||||
}
|
||||
Reference in New Issue
Block a user