diff --git a/web/components/learning/practice/PracticePage.tsx b/web/components/learning/practice/PracticePage.tsx index 9d8623797..8067c654e 100644 --- a/web/components/learning/practice/PracticePage.tsx +++ b/web/components/learning/practice/PracticePage.tsx @@ -137,7 +137,7 @@ function ScopedPracticePage({ mode, initialImport }: { mode: "practice" | "libra > {!libraryOnly &&
{t("All workspaces")}
} {session ? ( - + ) : ( <> {notice && ( diff --git a/web/components/learning/practice/PracticeSession.tsx b/web/components/learning/practice/PracticeSession.tsx index 680fea76c..048a30553 100644 --- a/web/components/learning/practice/PracticeSession.tsx +++ b/web/components/learning/practice/PracticeSession.tsx @@ -28,10 +28,12 @@ export function PracticeSession({ ids, questions, onClose, + backLabel, }: { ids?: number[] questions?: PracticeRef[] onClose: () => void + backLabel?: string }) { const [queue, setQueue] = useState( () => questions ?? (ids ?? []).map(id => ({ id })) @@ -55,7 +57,7 @@ export function PracticeSession({ className="inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground" > - {t('Back to practice')} + {backLabel ?? t('Back to practice')}

{t('{{count}} remaining', { count: total - saved - skipped })} @@ -91,7 +93,7 @@ export function PracticeSession({ onClick={onClose} className="mt-6 rounded-xl bg-primary px-5 py-2.5 text-sm text-primary-foreground" > - {t('Back to practice')} + {backLabel ?? t('Back to practice')} ) : ( diff --git a/web/tests/practice-entrypoints.spec.tsx b/web/tests/practice-entrypoints.spec.tsx index 538c3f0d2..5e6e10d12 100644 --- a/web/tests/practice-entrypoints.spec.tsx +++ b/web/tests/practice-entrypoints.spec.tsx @@ -27,6 +27,7 @@ vi.mock("@/components/space/question-bank", () => ({ vi.mock("@/lib/practice-api", async original => ({ ...(await original()), getPracticeSummary: vi.fn(), + getPracticeQuestion: vi.fn(), getPracticeAnalytics: vi.fn(), })); initI18n("en"); @@ -61,7 +62,7 @@ beforeEach(() => { }); }); -it("keeps Learning Space in its own collection route with scoped imports and no practice panels", async () => { +it("keeps Learning Space in its own collection route with scoped imports and no daily review panels", async () => { render(); expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Question Bank"); expect(await screen.findByRole("tab", { name: "Mistakes42" })).toHaveAttribute( @@ -71,7 +72,7 @@ it("keeps Learning Space in its own collection route with scoped imports and no expect(screen.getByText("Stored mistakes")).toBeVisible(); expect(screen.queryByRole("region", { name: "Practice activity" })).not.toBeInTheDocument(); expect(screen.queryByRole("region", { name: "Today's review" })).not.toBeInTheDocument(); - expect(screen.queryByRole("button", { name: "Practice this page" })).not.toBeInTheDocument(); + expect(screen.getByRole("button", { name: "Practice this page" })).toBeVisible(); expect(api.getPracticeAnalytics).not.toHaveBeenCalled(); expect(api.getPracticeSummary).toHaveBeenCalledWith("course-a"); @@ -100,3 +101,29 @@ it("retains analytics, daily review and collections in Personalized Learning", a { scroll: false } ); }); + + +it("starts manual practice from the collection and returns to the same course and mistakes view", async () => { + vi.mocked(api.getPracticeQuestion).mockResolvedValue({ + entry: { + id: 1, session_id: "lesson", session_title: "Lesson", turn_id: "", question_id: "q1", + question: "Which ocean?", question_type: "single_choice", options: { A: "Pacific", B: "Atlantic" }, + correct_answer: "B", explanation: "Reference explanation", difficulty: "", user_answer: "", + source: "deep_question", material_id: "", material_title: "", section_id: "", section_title: "", + score_trend: "new", is_correct: false, resolved: false, bookmarked: false, followup_session_id: "", created_at: 1, updated_at: 1, + }, + state: { version: 2, review_count: 1, is_mistake: true, due_at: 100 }, + }); + render(); + await screen.findByRole("tab", { name: "Mistakes42" }); + fireEvent.click(screen.getByRole("button", { name: "Practice this page" })); + expect(await screen.findByRole("button", { name: "Back to library" })).toBeVisible(); + expect(api.getPracticeQuestion).toHaveBeenCalledWith(1, undefined); + expect(screen.queryByText("Stored mistakes")).toBeNull(); + fireEvent.click(screen.getByRole("button", { name: "Back to library" })); + expect(await screen.findByText("Stored mistakes")).toBeVisible(); + expect(screen.getByRole("tab", { name: "Mistakes42" })).toHaveAttribute("aria-selected", "true"); + expect(screen.getByText("This course")).toBeVisible(); + expect(replace).not.toHaveBeenCalled(); + expect(api.getPracticeSummary).toHaveBeenLastCalledWith("course-a"); +});