forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

answer-sheet-view.test.tsx40 lines, 1.4 KiBHistoryRawDownload
1import { cleanup, render, screen, waitFor } from "@solidjs/testing-library";
2import { afterEach, expect, test, vi } from "vitest";
3import { ApiError } from "@/api/client";
4import { AnswerSheetView } from "@/components/exams/answer-sheet-view";
5import { PreferencesProvider } from "@/stores/preferences-context";
6
7const { getExamQuestions, getStudentAttempts, getStudentAnswers } = vi.hoisted(() => ({
8 getExamQuestions: vi.fn(),
9 getStudentAttempts: vi.fn(),
10 getStudentAnswers: vi.fn(),
11}));
12
13vi.mock("@/api/exams", () => ({
14 getExamQuestions,
15 getStudentAttempts,
16 getStudentAnswers,
17}));
18
19afterEach(() => {
20 cleanup();
21 vi.clearAllMocks();
22});
23
24test("an answer sheet without an attempt displays the known student name, not the UUID", async () => {
25 const userId = "123e4567-e89b-42d3-a456-426614174000";
26 getExamQuestions.mockResolvedValue({ items: [] });
27 getStudentAttempts.mockResolvedValue([]);
28 getStudentAnswers.mockRejectedValue(new ApiError(404, "not found"));
29
30 render(() => (
31 <PreferencesProvider>
32 <AnswerSheetView examId="exam-1" userId={userId} userLabel="Elif Yıldız" />
33 </PreferencesProvider>
34 ));
35
36 await waitFor(() => expect(getStudentAnswers).toHaveBeenCalledWith("exam-1", userId));
37 await screen.findByText(/Not started|Başlamadı/);
38 expect(screen.getByText("Elif Yıldız")).toBeTruthy();
39 expect(document.body.textContent).not.toContain(userId);
40});