mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-05 07:29:27 +08:00
test: 更新校对保存按钮与移动端裁剪提示的 E2E 断言
This commit is contained in:
@@ -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: '' });
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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<void>) {
|
||||
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 } });
|
||||
|
||||
Reference in New Issue
Block a user