hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { cleanup, render, screen, waitFor } from "@solidjs/testing-library"; |
| 2 | import { afterEach, expect, test, vi } from "vitest"; |
| 3 | import { ApiError } from "@/api/client"; |
| 4 | import { AnswerSheetView } from "@/components/exams/answer-sheet-view"; |
| 5 | import { PreferencesProvider } from "@/stores/preferences-context"; |
| 6 | |
| 7 | const { getExamQuestions, getStudentAttempts, getStudentAnswers } = vi.hoisted(() => ({ |
| 8 | getExamQuestions: vi.fn(), |
| 9 | getStudentAttempts: vi.fn(), |
| 10 | getStudentAnswers: vi.fn(), |
| 11 | })); |
| 12 | |
| 13 | vi.mock("@/api/exams", () => ({ |
| 14 | getExamQuestions, |
| 15 | getStudentAttempts, |
| 16 | getStudentAnswers, |
| 17 | })); |
| 18 | |
| 19 | afterEach(() => { |
| 20 | cleanup(); |
| 21 | vi.clearAllMocks(); |
| 22 | }); |
| 23 | |
| 24 | test("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 | }); |