"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MouseInput_1 = require("../../MouseInput");
const FocusOnPixel_1 = require("../UC/FocusOnPixel");
const MouseDoubleClickToRecenter_1 = require("./MouseDoubleClickToRecenter");
class MockCenterSceneRootOnPixel extends FocusOnPixel_1.FocusOnPixelUC {
    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, FocusOnPixel_1.FocusOnPixelUC.type);
    const mockMouseInput = new MockMouseInput(appAO, MouseInput_1.MouseInputEntity.type);
    const controller = new MouseDoubleClickToRecenter_1.MouseDoubleClickToRecenter(appAO);
    const dateNowMock = jest.fn();
    Date.now = dateNowMock;
    dateNowMock.mockReturnValue(0);
    return { mockMouseInput, controller, mockCenterUC, dateNowMock };
}
describe("Mouse Click to focus controller", () => {
    it("Registers with the mouse input when constructed", () => {
        const { mockMouseInput, controller } = makeTestRig();
        expect(mockMouseInput.registerController).toHaveBeenCalledWith(controller);
    });
    it("Sends the pixel position after a double click if allow returns true", () => {
        const { dateNowMock, mockCenterUC, controller } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.allow = () => {
            return true;
        };
        controller.onDoubleClick(evt);
        expect(mockCenterUC.centerOnPixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Does not send if allow retuns false", () => {
        const { dateNowMock, mockCenterUC, controller } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.allow = () => {
            return false;
        };
        controller.onDoubleClick(evt);
        expect(mockCenterUC.centerOnPixel).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=MouseDoubleClickToRecenter.test.js.map