forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

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

instance-options.test.ts32 lines, 1.2 KiBHistoryRawDownload
1import { beforeEach, expect, test, vi } from "vitest";
2import { loadInstanceOptions } from "./instance-options";
3import { resetInstanceLabelCache } from "./instance-labels";
4
5const { getClasses, getClassInstances } = vi.hoisted(() => ({
6 getClasses: vi.fn(),
7 getClassInstances: vi.fn(),
8}));
9
10vi.mock("@/api/classes", () => ({ getClasses, getClassInstances }));
11vi.mock("@/api/instances", () => ({ getMyInstances: vi.fn() }));
12
13beforeEach(() => {
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
24test("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});