From 1b79ab823b25681bf7ca239cd7a55951c3eae6aa Mon Sep 17 00:00:00 2001 From: margrop <1731827+margrop@users.noreply.github.com> Date: Sat, 5 Dec 2026 00:59:57 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E6=A0=A1=E5=AF=B9?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=8C=89=E9=92=AE=E4=B8=8E=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=AB=AF=E8=A3=81=E5=89=AA=E6=8F=90=E7=A4=BA=E7=9A=84=20E2E=20?= =?UTF-8?q?=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/import-task-recovery.spec.ts | 4 ++-- e2e/multi-question-photo.spec.ts | 10 +++++++--- e2e/support/flows.ts | 11 ++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/e2e/import-task-recovery.spec.ts b/e2e/import-task-recovery.spec.ts index 1b8cf535..ed317133 100644 --- a/e2e/import-task-recovery.spec.ts +++ b/e2e/import-task-recovery.spec.ts @@ -3,7 +3,7 @@ import { expect } from '@playwright/test'; import type { Page, TestInfo } from '@playwright/test'; import { test } from './support/fixtures'; import type { Scenario } from './support/fixtures'; -import { viewports } from './support/flows'; +import { saveCorrectionToNotebook, viewports } from './support/flows'; async function upload(page: Page, scenario: Scenario, path = '/') { await scenario.control({ hold: true }); @@ -66,7 +66,7 @@ for (const profile of viewports) { expect(await analysisCalls(scenario)).toBe(1); await question.fill(`校对后的方程 x + 2 = 5。${scenario.marker}`); - await page.getByRole('button', { name: /保存|Save/ }).click(); + await saveCorrectionToNotebook(page); await expect.poll(() => scenario.db.errorItem.count({ where: { userId: scenario.user.id } })).toBe(1); const task = await scenario.db.importTask.findFirstOrThrow({ where: { userId: scenario.user.id } }); expect(task).toMatchObject({ status: 'saved', imageData: '' }); diff --git a/e2e/multi-question-photo.spec.ts b/e2e/multi-question-photo.spec.ts index 17ab9708..8e84124c 100644 --- a/e2e/multi-question-photo.spec.ts +++ b/e2e/multi-question-photo.spec.ts @@ -1,7 +1,7 @@ import { resolve } from 'node:path'; import { expect, test } from './support/fixtures'; import { batchOf, calls, expectNoHorizontalOverflow, expectNotCovered, saveShot } from './support/batch-flows'; -import { viewports } from './support/flows'; +import { saveCorrectionToNotebook, viewports } from './support/flows'; const PAGE_PHOTO = resolve('src/__tests__/fixtures/images/multi-question-page.jpg'); @@ -15,7 +15,11 @@ for (const profile of viewports) { await page.goto(`/notebooks/${scenario.book.id}/add`); await page.locator('input[type="file"]').first().setInputFiles(PAGE_PHOTO); await page.getByRole('button', { name: '自动分题' }).click(); - await expect(page.getByText(/AI 自动找出每道题及其位置/)).toBeVisible(); + if (profile.isMobile) { + await expect(page.getByText(/AI 自动找出每道题及其位置/)).toBeHidden(); + } else { + await expect(page.getByText(/AI 自动找出每道题及其位置/)).toBeVisible(); + } await page.getByRole('button', { name: '自动识别题目' }).click(); await expect(page).toHaveURL(/\/import-batches\/[a-f0-9]+$/); await expect(page.getByTestId('draft-summary')).toHaveText(/识别出 3 题\s*·\s*已选 3 题/, { timeout: 20000 }); @@ -81,7 +85,7 @@ test('[E2E-B04] 照片批次开启人工确认:逐题校对后回到本批, await expect(page).toHaveURL(/\/import-tasks\/[a-f0-9]+$/); const question = page.locator('textarea').first(); await question.fill(`校对后的第 1 题 ${scenario.marker}`); - await page.getByRole('button', { name: /保存|Save/ }).click(); + await saveCorrectionToNotebook(page); // 校对保存后回到本批题目 await expect(page).toHaveURL(/\/import-batches\/[a-f0-9]+$/); await expect(page.getByTestId('batch-counts')).toContainText('待校对 2'); diff --git a/e2e/support/flows.ts b/e2e/support/flows.ts index 0f8219db..9d8c5cd3 100644 --- a/e2e/support/flows.ts +++ b/e2e/support/flows.ts @@ -7,6 +7,15 @@ export const viewports = [ { name: '手机', viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true }, ]; +/** 点击校对页「保存到错题本」按钮:窄屏(<1024px)优先点底部固定栏,避免与顶部栏或「保存并下一题」冲突 */ +export async function saveCorrectionToNotebook(page: Page) { + const mobileSaveBar = page.getByTestId('correction-mobile-save-bar'); + const saveButton = (await mobileSaveBar.isVisible()) + ? mobileSaveBar.getByRole('button', { name: /保存到错题本|Save to Notebook/ }) + : page.getByRole('button', { name: /保存到错题本|Save to Notebook/ }); + await saveButton.click(); +} + export async function importImage(page: Page, scenario: Scenario, confirm: boolean, onCorrection?: (page: Page) => Promise) { await scenario.db.user.update({ where: { id: scenario.user.id }, data: { confirmBeforeImport: confirm } }); await scenario.control({ hold: true }); @@ -27,7 +36,7 @@ export async function importImage(page: Page, scenario: Scenario, confirm: boole await expect(question).toHaveValue(`求解方程 x + 2 = 5。${scenario.marker}`); await question.fill(`校对后的方程 x + 2 = 5。${scenario.marker}`); await expect(page.getByText('一元一次方程', { exact: true }).first()).toBeVisible(); - await page.getByRole('button', { name: /保存|Save/ }).click(); + await saveCorrectionToNotebook(page); } else await expect(page.getByRole('heading', { name: /校对|Review & Correct/ })).toHaveCount(0); await expect.poll(() => scenario.db.errorItem.count({ where: { userId: scenario.user.id } })).toBe(1); const item = await scenario.db.errorItem.findFirstOrThrow({ where: { userId: scenario.user.id }, include: { tags: true } });