import { makeAppObjectRepo } from "@vived/core";
import { makeToolEntity, ToolEntity, ToolState } from "./ToolEntity";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const toolAO = appObjects.getOrCreate("tool1");
    const tool = makeToolEntity(toolAO);
    const observer = jest.fn();
    tool.addChangeObserver(observer);
    return { tool, observer, appObjects };
}
describe("Tool Entity", () => {
    it("Gets the tool by ID", () => {
        const { tool, appObjects } = makeTestRig();
        expect(ToolEntity.get("tool1", appObjects)).toEqual(tool);
    });
    it("Sets the type to the app ID", () => {
        const { tool } = makeTestRig();
        expect(tool.toolType).toEqual("tool1");
    });
    it("Sets the hotkeys", () => {
        const { tool, observer } = makeTestRig();
        tool.hotkeys = [{ keyCode: "keyCode", meta: true }];
        expect(tool.hotkeys).toEqual([{ keyCode: "keyCode", meta: true }]);
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Sets the label and notifies if there is a change", () => {
        const { tool, observer } = makeTestRig();
        tool.label = "Hello World";
        tool.label = "Hello World";
        tool.label = "Hello World";
        tool.label = "Hello World";
        expect(tool.label).toEqual("Hello World");
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Sets the shortcut label and notifies if there is a change", () => {
        const { tool, observer } = makeTestRig();
        tool.shortcutLabel = "Hello World";
        tool.shortcutLabel = "Hello World";
        tool.shortcutLabel = "Hello World";
        tool.shortcutLabel = "Hello World";
        expect(tool.shortcutLabel).toEqual("Hello World");
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Notifies only when the state changes", () => {
        const { tool, observer } = makeTestRig();
        expect(tool.state).toEqual(ToolState.ENABLED);
        tool.state = ToolState.ENABLED;
        tool.state = ToolState.ENABLED;
        tool.state = ToolState.ENABLED;
        expect(observer).not.toHaveBeenCalled();
        tool.state = ToolState.ACTIVE;
        expect(observer).toHaveBeenCalled();
        expect(tool.state).toEqual(ToolState.ACTIVE);
    });
    it("Checks for a hotkey", () => {
        const { tool } = makeTestRig();
        tool.hotkeys = [{ keyCode: "keyCode", meta: true }];
        expect(tool.isMyHotkey({ keyCode: "keyCode" })).toEqual(false);
        expect(tool.isMyHotkey({ keyCode: "keyCode", meta: true })).toEqual(true);
        expect(tool.isMyHotkey({ keyCode: "keyCode", meta: true, alt: false })).toEqual(true);
        expect(tool.isMyHotkey({ keyCode: "keyCode", meta: true, alt: true })).toEqual(false);
        expect(tool.isMyHotkey({ keyCode: "keyCode", meta: true, control: false })).toEqual(true);
        expect(tool.isMyHotkey({ keyCode: "keyCode", meta: true, control: true })).toEqual(false);
        expect(tool.isMyHotkey({ keyCode: "keyCode", meta: true, shift: false })).toEqual(true);
        expect(tool.isMyHotkey({ keyCode: "keyCode", meta: true, shift: true })).toEqual(false);
    });
    it("Sets the is action flag if an action is passed in", () => {
        const { tool } = makeTestRig();
        const mockAction = jest.fn();
        expect(tool.isAction).toEqual(false);
        tool.registerAction(mockAction);
        expect(tool.isAction).toEqual(true);
    });
    it("Triggers actions", () => {
        const { tool } = makeTestRig();
        const mockAction = jest.fn();
        tool.registerAction(mockAction);
        tool.triggerActions();
        expect(mockAction).toHaveBeenCalled();
    });
});
//# sourceMappingURL=ToolEntity.test.js.map