28 lines
1.2 KiB
TypeScript
28 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { navigateGridCell } from "../../src/state/gridNavigation";
|
|
|
|
describe("accessible grid navigation", () => {
|
|
it("moves with arrows without wrapping at edges", () => {
|
|
expect(navigateGridCell(4, 3, "ArrowRight")).toBe(5);
|
|
expect(navigateGridCell(5, 3, "ArrowRight")).toBe(5);
|
|
expect(navigateGridCell(3, 3, "ArrowLeft")).toBe(3);
|
|
expect(navigateGridCell(1, 3, "ArrowUp")).toBe(1);
|
|
expect(navigateGridCell(7, 3, "ArrowDown")).toBe(7);
|
|
});
|
|
|
|
it("supports row, grid and column-edge shortcuts", () => {
|
|
expect(navigateGridCell(4, 3, "Home")).toBe(3);
|
|
expect(navigateGridCell(4, 3, "End")).toBe(5);
|
|
expect(navigateGridCell(4, 3, "Home", true)).toBe(0);
|
|
expect(navigateGridCell(4, 3, "End", true)).toBe(8);
|
|
expect(navigateGridCell(4, 3, "PageUp")).toBe(1);
|
|
expect(navigateGridCell(4, 3, "PageDown")).toBe(7);
|
|
});
|
|
|
|
it("ignores non-navigation keys and rejects unsafe inputs", () => {
|
|
expect(navigateGridCell(0, 9, "Enter")).toBeNull();
|
|
expect(() => navigateGridCell(-1, 9, "Home")).toThrow(/outside/i);
|
|
expect(() => navigateGridCell(0, 0, "Home")).toThrow(/size/i);
|
|
});
|
|
});
|