diff --git a/e2e/practice.spec.ts b/e2e/practice.spec.ts index 6bb9da3f..01ca1093 100644 --- a/e2e/practice.spec.ts +++ b/e2e/practice.spec.ts @@ -18,7 +18,7 @@ for (const profile of viewports) { expect(records[0]).toMatchObject({ errorItemId: item.id, source: 'practice', result: 'correct' }); expect(records[0].questionText).toContain(`${scenario.marker}变式`); await expect.poll(async () => (await scenario.db.errorItem.findUniqueOrThrow({ where: { id: item.id } })).masteryProbability).toBe(0.7); - await page.locator(`a[href="/error-items/${item.id}"]`).click(); + await page.locator(`a[href="/error-items/${item.id}"]`).first().click(); await page.getByRole('button', { name: /做对.*单题练习/ }).click(); await expect(page.getByText(`${scenario.marker}变式`, { exact: false })).toBeVisible(); await page.goto(`/practice?id=${item.id}`); @@ -50,3 +50,29 @@ test('[E2E-M06] 判题失败不自动判错,用户手工确认后保存', asyn await expect(page.getByText(`${scenario.marker}变式`, { exact: false })).toBeVisible(); expect(await scenario.records()).toHaveLength(1); }); + +test('[E2E-M07] 练习页回车提交答案、查看原题入口与手机标题换行', async ({ page, scenario }) => { + test.setTimeout(90000); + const item = await generatePractice(page, scenario); + await page.setViewportSize({ width: 390, height: 844 }); + const title = page.getByTestId('practice-question-title'); + await expect(title).toBeVisible(); + expect(await title.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true); + + await page.getByPlaceholder('输入你的答案...').fill('令连续整数为 k 与 k+1,因此和为 2k+1,按奇数定义可得结论。'); + await page.getByPlaceholder('输入你的答案...').press('Enter'); + await expect(page.getByText('测试夹具判定:结论及论证完整', { exact: false })).toBeVisible({ timeout: 20000 }); + + await page.getByRole('link', { name: '查看原题', exact: true }).click(); + await expect(page).toHaveURL(`/error-items/${item.id}`); +}); + +test('[E2E-M08] 直达练习页时返回按钮回到原错题详情', async ({ page, scenario }) => { + const item = await scenario.item(); + await scenario.login(page); + const fresh = await page.context().newPage(); + await scenario.guardPage(fresh); + await fresh.goto(`/practice?id=${item.id}`); + await fresh.getByRole('button', { name: '返回', exact: true }).click(); + await expect(fresh).toHaveURL(`/error-items/${item.id}`); +}); diff --git a/src/app/practice/page.tsx b/src/app/practice/page.tsx index 516ba8ba..4072040b 100644 --- a/src/app/practice/page.tsx +++ b/src/app/practice/page.tsx @@ -1,8 +1,9 @@ "use client"; import { Suspense } from "react"; +import Link from "next/link"; import { useSearchParams, useRouter } from "next/navigation"; -import { Loader2, ArrowLeft } from "lucide-react"; +import { Loader2, ArrowLeft, Eye } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Textarea } from "@/components/ui/textarea"; @@ -37,13 +38,25 @@ function PracticeContent() { return