import { makeAppObjectRepo } from "@vived/core";
import { MockKeyboardInput } from "../../KeyboardInput/Mocks/MockKeyboardInput";
import { makeToolRepo } from "../Entities/ToolRepository";
import { ToolHotkeys } from "./ToolHotkeys";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("App");
    const toolRepo = makeToolRepo(ao);
    toolRepo.makeToolFromData({
        toolType: "Tool1",
        isDefault: false,
        label: "Tool 1",
        shortcutLabel: "T1",
        hotkeys: [{ keyCode: "1" }],
    });
    toolRepo.makeToolFromData({
        toolType: "Tool2",
        isDefault: true,
        label: "Tool 2",
        shortcutLabel: "T2",
        hotkeys: [{ keyCode: "1", shift: true }],
    });
    const keyboardInput = new MockKeyboardInput(ao);
    const element = document.createElement("div");
    keyboardInput.setEventElement(element);
    const controller = new ToolHotkeys(ao);
    return { toolRepo, keyboardInput, controller, element };
}
describe("Tool Hotkey Controller", () => {
    it("Registers with the keyboard input", () => {
        const { keyboardInput, controller } = makeTestRig();
        expect(keyboardInput.registerController).toHaveBeenCalledWith(controller);
    });
    it("Sets a tool active when a key is submitted on down", () => {
        const { toolRepo, controller } = makeTestRig();
        toolRepo.triggerTool = jest.fn();
        const evt = makeKeyEvent("1");
        controller.onKeyDown(evt);
        expect(toolRepo.triggerTool).toHaveBeenCalledWith("Tool1");
    });
    it("Sets the correct tool active when a key and modifier are submitted on down", () => {
        const { toolRepo, controller } = makeTestRig();
        toolRepo.triggerTool = jest.fn();
        const evt = makeKeyEvent("1", false, true);
        controller.onKeyDown(evt);
        expect(toolRepo.triggerTool).toHaveBeenCalledWith("Tool2");
    });
    it("Does not call if the key is not found", () => {
        const { toolRepo, controller } = makeTestRig();
        toolRepo.triggerTool = jest.fn();
        const evt = makeKeyEvent("2", false, true);
        controller.onKeyDown(evt);
        expect(toolRepo.triggerTool).not.toHaveBeenCalled();
    });
});
function makeKeyEvent(code, ctrlKey = false, shiftKey = false, metaKey = false) {
    return new KeyboardEvent("keydown", {
        code,
        ctrlKey,
        shiftKey,
        metaKey,
    });
}
//# sourceMappingURL=ToolHotkeys.test.js.map