import { makeAppObjectRepo, Vector2 } from "@vived/core";
import { MouseInputEntity } from "../../MouseInput";
import { CenterSceneRootOnPixelPickUC } from "../UC/CenterSceneRootOnPixelPick";
import { MouseClickToFocus } from "./MouseClickToFocus";
class MockCenterSceneRootOnPixel extends CenterSceneRootOnPixelPickUC {
    constructor() {
        super(...arguments);
        this.durationMS = 500;
        this.easeFn = (val) => {
            return val;
        };
        this.centerOnPixel = jest.fn();
    }
}
class MockMouseInput extends MouseInputEntity {
    constructor() {
        super(...arguments);
        this.setEventElement = jest.fn();
        this.clearInputElement = jest.fn();
        this.registerController = jest.fn();
        this.removeController = jest.fn();
    }
    get eventElement() {
        return;
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appAO = appObjects.getOrCreate("AO");
    const mockCenterUC = new MockCenterSceneRootOnPixel(appAO, CenterSceneRootOnPixelPickUC.type);
    const mockMouseInput = new MockMouseInput(appAO, MouseInputEntity.type);
    const controller = new MouseClickToFocus(appAO);
    return { appObjects, controller, mockCenterUC, mockMouseInput };
}
describe("Mouse Click to focus controller", () => {
    it("Registers with the mouse input when constructed", () => {
        const { mockMouseInput, controller } = makeTestRig();
        expect(mockMouseInput.registerController).toHaveBeenCalledWith(controller);
    });
    it("Triggers if the allow returns true", () => {
        const { controller, mockCenterUC } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttonup"),
        };
        controller.allow = () => {
            return true;
        };
        controller.onClick(evt);
        expect(mockCenterUC.centerOnPixel).toHaveBeenCalledWith(new Vector2(2, 3));
    });
    it("Does not trigger if allow returns false", () => {
        const { controller, mockCenterUC } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttonup"),
        };
        controller.allow = () => {
            return false;
        };
        controller.onClick(evt);
        expect(mockCenterUC.centerOnPixel).not.toHaveBeenCalled();
    });
    it("Allows if the button is 1", () => {
        const { controller } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        expect(controller.allow(evt)).toEqual(true);
    });
    it("Allows if the button is 2", () => {
        const { controller } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        expect(controller.allow(evt)).toEqual(true);
    });
    it("Does not allow if the button is 0", () => {
        const { controller } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        expect(controller.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=MouseClickToFocus.test.js.map