| 123456789101112131415161718 |
- import { describe, expect, it } from "vitest";
- import { arrowDirection } from "../src/keys.js";
- describe("arrowDirection (raw input → adjacent tile delta)", () => {
- it("maps the four arrow keys to grid deltas", () => {
- expect(arrowDirection("key:ArrowUp")).toEqual({ dx: 0, dy: -1 });
- expect(arrowDirection("key:ArrowDown")).toEqual({ dx: 0, dy: 1 });
- expect(arrowDirection("key:ArrowLeft")).toEqual({ dx: -1, dy: 0 });
- expect(arrowDirection("key:ArrowRight")).toEqual({ dx: 1, dy: 0 });
- });
- it("rejects non-arrow and malformed inputs", () => {
- expect(arrowDirection("key:Space")).toBeUndefined();
- expect(arrowDirection("pointer:click:1:2")).toBeUndefined();
- expect(arrowDirection("key:")).toBeUndefined();
- expect(arrowDirection("")).toBeUndefined();
- });
- });
|