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:
@@ -36,9 +36,10 @@ test.describe('Header navigation', () => {
|
||||
});
|
||||
|
||||
test('back button shows on sub-pages and navigates to /welcome', async ({ page }) => {
|
||||
await page.route('**/api/tasks**', (route) =>
|
||||
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockTasks) }),
|
||||
);
|
||||
await page.route('**/api/tasks**', (route) => {
|
||||
if (route.request().url().endsWith('.ts')) return route.continue();
|
||||
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockTasks) });
|
||||
});
|
||||
await page.route('**/api/review/feed**', (route) =>
|
||||
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockFeed) }),
|
||||
);
|
||||
|
||||
@@ -37,6 +37,11 @@ const mockApiResponse = (code = 200, data: any = null, message = '请求成功')
|
||||
|
||||
test.describe('StartTask - 暂停后继续', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// mock 音频权限(阻止 audio.play() 弹窗阻塞会话加载)
|
||||
await page.addInitScript(() => {
|
||||
HTMLAudioElement.prototype.play = () => Promise.resolve();
|
||||
});
|
||||
|
||||
// 模拟登录
|
||||
await page.goto('/login');
|
||||
await page.evaluate(() => localStorage.setItem('isLoggedIn', 'true'));
|
||||
@@ -192,6 +197,11 @@ test.describe('StartTask - 暂停后继续', () => {
|
||||
await page.locator('.el-dialog textarea').fill('测试总结');
|
||||
await page.locator('.el-dialog button', { hasText: '确认结束' }).click();
|
||||
|
||||
// 确认第二个弹窗("确定要结束本次学习会话吗?")
|
||||
const confirmBtn = page.locator('.el-message-box__btns button', { hasText: '确定' });
|
||||
await confirmBtn.waitFor({ timeout: 5000 });
|
||||
await confirmBtn.click();
|
||||
|
||||
// 应看到 warning 提示(有效时间不足)
|
||||
await expect(page.locator('.el-message--warning')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
+12
-6
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user