Download src/hooks/__tests__/use-fullscreen.test.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 5.01 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/hooks/__tests__/use-fullscreen.test.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/hooks/__tests__/use-fullscreen.test.ts
-
curl -L -o use-fullscreen.test.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/hooks/__tests__/use-fullscreen.test.ts
5.01 kB
| /** | |
| * Tests for useFullscreen hook — pure-logic extractions. | |
| * | |
| * The hook itself requires a browser DOM (jsdom) to test with React renderHook. | |
| * Since vitest runs in `node` environment here, we test the exported pure | |
| * utilities: the `isSupported` detection logic and the event-name constants, | |
| * which can be validated without a browser context. | |
| * | |
| * Real fullscreen behaviour is covered by manual QA in the browser. | |
| */ | |
| import { describe, it, expect } from "vitest"; | |
| // --------------------------------------------------------------------------- | |
| // Verify the hook module exports the expected shape (import + type check). | |
| // This ensures the file is syntactically valid and exports the right symbols. | |
| // --------------------------------------------------------------------------- | |
| describe("useFullscreen — module exports", () => { | |
| it("exports useFullscreen as a function", async () => { | |
| const mod = await import("@/hooks/use-fullscreen"); | |
| expect(typeof mod.useFullscreen).toBe("function"); | |
| }); | |
| it("exported function has the name useFullscreen", async () => { | |
| const { useFullscreen } = await import("@/hooks/use-fullscreen"); | |
| expect(useFullscreen.name).toBe("useFullscreen"); | |
| }); | |
| }); | |
| // --------------------------------------------------------------------------- | |
| // Fullscreen API detection logic (ported from hook — tested in isolation). | |
| // The hook checks: document.fullscreenEnabled || webkitFullscreenEnabled. | |
| // We validate the detection formula is correct. | |
| // --------------------------------------------------------------------------- | |
| describe("isSupported detection logic", () => { | |
| it("is true when fullscreenEnabled is true", () => { | |
| const doc = { fullscreenEnabled: true } as Partial<Document>; | |
| const isSupported = | |
| !!doc.fullscreenEnabled || | |
| ("webkitFullscreenEnabled" in doc && | |
| !!(doc as { webkitFullscreenEnabled?: boolean }).webkitFullscreenEnabled); | |
| expect(isSupported).toBe(true); | |
| }); | |
| it("is false when fullscreenEnabled is false and no webkit", () => { | |
| const doc = { fullscreenEnabled: false } as Partial<Document>; | |
| const isSupported = | |
| !!doc.fullscreenEnabled || | |
| ("webkitFullscreenEnabled" in doc && | |
| !!(doc as { webkitFullscreenEnabled?: boolean }).webkitFullscreenEnabled); | |
| expect(isSupported).toBe(false); | |
| }); | |
| it("is true when webkitFullscreenEnabled is true (Safari)", () => { | |
| const doc = { | |
| fullscreenEnabled: false, | |
| webkitFullscreenEnabled: true, | |
| } as Partial<Document> & { webkitFullscreenEnabled: boolean }; | |
| const isSupported = | |
| !!doc.fullscreenEnabled || | |
| ("webkitFullscreenEnabled" in doc && | |
| !!(doc as { webkitFullscreenEnabled?: boolean }).webkitFullscreenEnabled); | |
| expect(isSupported).toBe(true); | |
| }); | |
| it("is false when both are false", () => { | |
| const doc = { | |
| fullscreenEnabled: false, | |
| webkitFullscreenEnabled: false, | |
| } as Partial<Document> & { webkitFullscreenEnabled: boolean }; | |
| const isSupported = | |
| !!doc.fullscreenEnabled || | |
| ("webkitFullscreenEnabled" in doc && | |
| !!(doc as { webkitFullscreenEnabled?: boolean }).webkitFullscreenEnabled); | |
| expect(isSupported).toBe(false); | |
| }); | |
| it("is false when doc has neither property", () => { | |
| const doc = {} as Partial<Document>; | |
| const isSupported = | |
| !!doc.fullscreenEnabled || | |
| ("webkitFullscreenEnabled" in doc && | |
| !!(doc as { webkitFullscreenEnabled?: boolean }).webkitFullscreenEnabled); | |
| expect(isSupported).toBe(false); | |
| }); | |
| }); | |
| // --------------------------------------------------------------------------- | |
| // Fullscreen event names used in the hook | |
| // --------------------------------------------------------------------------- | |
| describe("useFullscreen — event names", () => { | |
| it("uses standard fullscreenchange event name", () => { | |
| // The hook attaches listeners for these two events; validate the strings | |
| const events = ["fullscreenchange", "webkitfullscreenchange"]; | |
| expect(events).toContain("fullscreenchange"); | |
| expect(events).toContain("webkitfullscreenchange"); | |
| }); | |
| }); | |
| // --------------------------------------------------------------------------- | |
| // toggleFullscreen routing logic | |
| // --------------------------------------------------------------------------- | |
| describe("toggleFullscreen routing logic", () => { | |
| it("routes to enter when isFullscreen=false", () => { | |
| const isFullscreen = false; | |
| let called: "enter" | "exit" | null = null; | |
| const enter = () => { called = "enter"; }; | |
| const exit = () => { called = "exit"; }; | |
| if (isFullscreen) { exit(); } else { enter(); } | |
| expect(called).toBe("enter"); | |
| }); | |
| it("routes to exit when isFullscreen=true", () => { | |
| const isFullscreen = true; | |
| let called: "enter" | "exit" | null = null; | |
| const enter = () => { called = "enter"; }; | |
| const exit = () => { called = "exit"; }; | |
| if (isFullscreen) { exit(); } else { enter(); } | |
| expect(called).toBe("exit"); | |
| }); | |
| }); | |