test(e2e):修复 10 个用例——全部 30 个通过

- study.spec.ts:mock 模式 **/api/tasks** 过滤 .ts 模块请求,避免拦截 Vite 文件加载
- navigation.spec.ts:同上
- start-task.spec.ts:addInitScript mock HTMLAudioElement.play 绕过音频权限弹窗
- start-task.spec.ts:补健结束会话后的 ElMessageBox.confirm 确认点击
- 复习页面入口检查新增回忆复习按钮的文本变化适配
This commit is contained in:
2026-07-04 09:28:15 +08:00
parent 8e75a7d2e4
commit 104ae78a2b
6 changed files with 732 additions and 10 deletions
+12 -6
View File
@@ -37,6 +37,8 @@ test.describe('Study page', () => {
test.beforeEach(async ({ page }) => {
await page.route('**/api/tasks**', (route) => {
const url = route.request().url();
// 排除 Vite 模块加载请求(.ts 文件),只拦截真正的 API 请求
if (url.endsWith('.ts')) return route.continue();
if (url.includes('/tasks') && !url.includes('/tasks/')) {
return route.fulfill({
status: 200,
@@ -83,26 +85,30 @@ test.describe('Study page', () => {
});
test('delete task removes it from the list', async ({ page }) => {
await page.route('**/api/tasks/1', (route) =>
await page.route('**/api/tasks/1', (route) => {
const url = route.request().url();
if (url.endsWith('.ts')) return route.continue();
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ code: 200, message: '删除成功' }),
}),
);
});
});
await page.locator('.action-card').locator('button', { hasText: '删除任务' }).click();
await expect(page.locator('.task-list-item')).toHaveCount(1, { timeout: 5000 });
});
test('shows empty state when no tasks', async ({ page }) => {
await page.route('**/api/tasks**', (route) =>
await page.route('**/api/tasks**', (route) => {
const url = route.request().url();
if (url.endsWith('.ts')) return route.continue();
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(mockTasksEmpty),
}),
);
});
});
await page.goto('/study');
await page.waitForSelector('.study-page', { timeout: 10_000 });