hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { beforeEach, expect, test, vi } from "vitest"; |
| 2 | import { loadInstanceOptions } from "./instance-options"; |
| 3 | import { resetInstanceLabelCache } from "./instance-labels"; |
| 4 | |
| 5 | const { getClasses, getClassInstances } = vi.hoisted(() => ({ |
| 6 | getClasses: vi.fn(), |
| 7 | getClassInstances: vi.fn(), |
| 8 | })); |
| 9 | |
| 10 | vi.mock("@/api/classes", () => ({ getClasses, getClassInstances })); |
| 11 | vi.mock("@/api/instances", () => ({ getMyInstances: vi.fn() })); |
| 12 | |
| 13 | beforeEach(() => { |
| 14 | resetInstanceLabelCache(); |
| 15 | getClasses.mockReset().mockResolvedValue({ items: [ |
| 16 | { id: "c1", name: "9-A", grade_level: 9 }, |
| 17 | { id: "c2", name: "9-B", grade_level: 9 }, |
| 18 | ] }); |
| 19 | getClassInstances.mockReset().mockImplementation(async (id: string) => ({ items: [ |
| 20 | { id: `i-${id}`, course: "math", class: id, title: "Math" }, |
| 21 | ] })); |
| 22 | }); |
| 23 | |
| 24 | test("manager pickers reuse the school section walk across visits", async () => { |
| 25 | const first = await loadInstanceOptions("manager"); |
| 26 | const second = await loadInstanceOptions("manager"); |
| 27 | |
| 28 | expect(first.map((row) => row.label)).toEqual(["Math — 9-A", "Math — 9-B"]); |
| 29 | expect(second).toEqual(first); |
| 30 | expect(getClasses).toHaveBeenCalledTimes(1); |
| 31 | expect(getClassInstances).toHaveBeenCalledTimes(2); |
| 32 | }); |