mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 13:19:45 +08:00
fix(practice): return library practice to its scoped collection
This commit is contained in:
@@ -137,7 +137,7 @@ function ScopedPracticePage({ mode, initialImport }: { mode: "practice" | "libra
|
||||
>
|
||||
{!libraryOnly && <div className="mb-4 flex items-center gap-3 text-xs"><a href="/learning/practice" className="underline">{t("All workspaces")}</a><WorkspaceLabel row={{ content_workspace_id: activeWorkspaceId() }} /></div>}
|
||||
{session ? (
|
||||
<PracticeSession ids={session} onClose={closeSession} />
|
||||
<PracticeSession ids={session} onClose={closeSession} backLabel={libraryOnly ? t("Back to library") : undefined} />
|
||||
) : (
|
||||
<>
|
||||
{notice && (
|
||||
|
||||
@@ -28,10 +28,12 @@ export function PracticeSession({
|
||||
ids,
|
||||
questions,
|
||||
onClose,
|
||||
backLabel,
|
||||
}: {
|
||||
ids?: number[]
|
||||
questions?: PracticeRef[]
|
||||
onClose: () => void
|
||||
backLabel?: string
|
||||
}) {
|
||||
const [queue, setQueue] = useState<PracticeRef[]>(
|
||||
() => 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"
|
||||
>
|
||||
<ArrowLeft size={15} />
|
||||
{t('Back to practice')}
|
||||
{backLabel ?? t('Back to practice')}
|
||||
</button>
|
||||
<p className="text-xs text-muted-foreground" aria-live="polite">
|
||||
{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')}
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
@@ -27,6 +27,7 @@ vi.mock("@/components/space/question-bank", () => ({
|
||||
vi.mock("@/lib/practice-api", async original => ({
|
||||
...(await original<typeof api>()),
|
||||
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(<SpaceQuestionsPage />);
|
||||
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(<SpaceQuestionsPage />);
|
||||
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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user