"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MouseInput_1 = require("../../MouseInput");
const CenterSceneRootOnPixelPick_1 = require("../UC/CenterSceneRootOnPixelPick");
const MouseClickToFocus_1 = require("./MouseClickToFocus");
class MockCenterSceneRootOnPixel extends CenterSceneRootOnPixelPick_1.CenterSceneRootOnPixelPickUC {
    constructor() {
        super(...arguments);
        this.durationMS = 500;
        this.easeFn = (val) => {
            return val;
        };
        this.centerOnPixel = jest.fn();
    }
}
class MockMouseInput extends MouseInput_1.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 = (0, core_1.makeAppObjectRepo)();
    const appAO = appObjects.getOrCreate("AO");
    const mockCenterUC = new MockCenterSceneRootOnPixel(appAO, CenterSceneRootOnPixelPick_1.CenterSceneRootOnPixelPickUC.type);
    const mockMouseInput = new MockMouseInput(appAO, MouseInput_1.MouseInputEntity.type);
    const controller = new MouseClickToFocus_1.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 core_1.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttonup"),
        };
        controller.allow = () => {
            return true;
        };
        controller.onClick(evt);
        expect(mockCenterUC.centerOnPixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Does not trigger if allow returns false", () => {
        const { controller, mockCenterUC } = makeTestRig();
        const evt = {
            position: new core_1.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 core_1.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 core_1.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 core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        expect(controller.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=MouseClickToFocus.test.js.map