hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; |
| 2 | import { afterEach, beforeEach, expect, test, vi } from "vitest"; |
| 3 | import { CommandPalette } from "@/components/layout/command-palette"; |
| 4 | import { PreferencesProvider } from "@/stores/preferences-context"; |
| 5 | |
| 6 | vi.mock("@tanstack/solid-router", () => ({ useNavigate: () => vi.fn() })); |
| 7 | vi.mock("@/stores/auth-context", () => ({ |
| 8 | useAuth: () => ({ |
| 9 | user: () => ({ id: "u-1", username: "teacher", role: "teacher" }), |
| 10 | loading: () => false, |
| 11 | error: () => undefined, |
| 12 | }), |
| 13 | })); |
| 14 | vi.mock("@/stores/modules-context", () => ({ |
| 15 | useModules: () => ({ enabled: () => null, loading: () => false, isEnabled: () => true, refresh: () => {} }), |
| 16 | })); |
| 17 | vi.mock("@/api/users", () => ({ getUserSearch: vi.fn(async () => ({ items: [], total: 0, limit: 10, offset: 0 })) })); |
| 18 | vi.mock("@/api/classes", () => ({ getMyClasses: vi.fn(async () => ({ items: [], total: 0, limit: 10, offset: 0 })) })); |
| 19 | |
| 20 | beforeEach(() => { |
| 21 | vi.spyOn(window, "scrollTo").mockImplementation(() => {}); |
| 22 | Element.prototype.scrollIntoView = vi.fn(); |
| 23 | }); |
| 24 | afterEach(() => { |
| 25 | cleanup(); |
| 26 | vi.restoreAllMocks(); |
| 27 | }); |
| 28 | |
| 29 | test("the palette is a combobox whose active option follows the arrow keys", async () => { |
| 30 | render(() => ( |
| 31 | <PreferencesProvider> |
| 32 | <CommandPalette open onOpenChange={() => {}} /> |
| 33 | </PreferencesProvider> |
| 34 | )); |
| 35 | |
| 36 | const field = await screen.findByRole("combobox"); |
| 37 | const list = screen.getByRole("listbox"); |
| 38 | expect(field.getAttribute("aria-controls")).toBe(list.id); |
| 39 | |
| 40 | const options = screen.getAllByRole("option"); |
| 41 | expect(options.length).toBeGreaterThan(1); |
| 42 | expect(field.getAttribute("aria-activedescendant")).toBe(options[0].id); |
| 43 | expect(options[0].getAttribute("aria-selected")).toBe("true"); |
| 44 | |
| 45 | fireEvent.keyDown(field, { key: "ArrowDown" }); |
| 46 | expect(field.getAttribute("aria-activedescendant")).toBe(options[1].id); |
| 47 | expect(options[1].getAttribute("aria-selected")).toBe("true"); |
| 48 | }); |