69 lines
2.8 KiB
TypeScript
69 lines
2.8 KiB
TypeScript
import { describe, expect, it, beforeEach } from "vitest";
|
|
|
|
// Unit test the pure logic of shortcut formatting and defaults
|
|
// (We test the non-hook parts since hooks require a React render context)
|
|
|
|
const STORAGE_KEY = "retrotoon-viewport-shortcuts";
|
|
|
|
describe("ShortcutsContext - pure logic", () => {
|
|
beforeEach(() => {
|
|
// Clear localStorage mock
|
|
if (typeof globalThis.localStorage !== "undefined") {
|
|
globalThis.localStorage.removeItem(STORAGE_KEY);
|
|
}
|
|
});
|
|
|
|
it("defines 6 default shortcuts for all view modes", () => {
|
|
const DEFAULT_MODES = ["composite", "original", "side_by_side", "split", "overlay", "onion"];
|
|
const DEFAULT_KEYS = ["1", "2", "3", "4", "5", "6"];
|
|
|
|
expect(DEFAULT_MODES).toHaveLength(6);
|
|
expect(DEFAULT_KEYS).toHaveLength(6);
|
|
|
|
// Verify each mode has a unique key
|
|
const uniqueKeys = new Set(DEFAULT_KEYS);
|
|
expect(uniqueKeys.size).toBe(6);
|
|
});
|
|
|
|
it("VIEW_MODE_LABELS covers all 6 modes", async () => {
|
|
const { VIEW_MODE_LABELS } = await import("../client/src/contexts/ShortcutsContext");
|
|
|
|
expect(VIEW_MODE_LABELS.composite).toBe("Composite");
|
|
expect(VIEW_MODE_LABELS.original).toBe("Original");
|
|
expect(VIEW_MODE_LABELS.side_by_side).toBe("Côte à côte");
|
|
expect(VIEW_MODE_LABELS.split).toBe("Split");
|
|
expect(VIEW_MODE_LABELS.overlay).toBe("Superposition");
|
|
expect(VIEW_MODE_LABELS.onion).toBe("Onion Skin");
|
|
});
|
|
|
|
it("formatKeyLabel produces correct labels for modifier combinations", async () => {
|
|
const { formatKeyLabel } = await import("../client/src/contexts/ShortcutsContext");
|
|
|
|
expect(formatKeyLabel("a", false, false, false)).toBe("A");
|
|
expect(formatKeyLabel("1", false, false, false)).toBe("1");
|
|
expect(formatKeyLabel("a", true, false, false)).toBe("Ctrl+A");
|
|
expect(formatKeyLabel("b", true, true, false)).toBe("Ctrl+Shift+B");
|
|
expect(formatKeyLabel("F1", false, false, false)).toBe("F1");
|
|
expect(formatKeyLabel("a", true, true, true)).toBe("Ctrl+Shift+Alt+A");
|
|
});
|
|
|
|
it("formatKeyLabel handles special keys", async () => {
|
|
const { formatKeyLabel } = await import("../client/src/contexts/ShortcutsContext");
|
|
|
|
expect(formatKeyLabel("ArrowUp", false, false, false)).toBe("ArrowUp");
|
|
expect(formatKeyLabel("Enter", true, false, false)).toBe("Ctrl+Enter");
|
|
expect(formatKeyLabel("Escape", false, false, true)).toBe("Alt+Escape");
|
|
});
|
|
|
|
it("localStorage key is correctly defined", () => {
|
|
expect(STORAGE_KEY).toBe("retrotoon-viewport-shortcuts");
|
|
});
|
|
|
|
it("ShortcutsProvider and useShortcuts are exported", async () => {
|
|
const mod = await import("../client/src/contexts/ShortcutsContext");
|
|
expect(mod.ShortcutsProvider).toBeDefined();
|
|
expect(mod.useShortcuts).toBeDefined();
|
|
expect(mod.formatKeyLabel).toBeDefined();
|
|
expect(mod.VIEW_MODE_LABELS).toBeDefined();
|
|
});
|
|
});
|