import { makeAppObjectRepo, Vector2 } from "@vived/core";
import { MouseInputEntity } from "../../MouseInput";
import { FocusOnPixelUC } from "../UC/FocusOnPixel";
import { MouseDoubleClickToRecenter } from "./MouseDoubleClickToRecenter";
class MockCenterSceneRootOnPixel extends FocusOnPixelUC {
    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, FocusOnPixelUC.type);
    const mockMouseInput = new MockMouseInput(appAO, MouseInputEntity.type);
    const controller = new 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 Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.allow = () => {
            return true;
        };
        controller.onDoubleClick(evt);
        expect(mockCenterUC.centerOnPixel).toHaveBeenCalledWith(new Vector2(2, 3));
    });
    it("Does not send if allow retuns false", () => {
        const { dateNowMock, mockCenterUC, controller } = makeTestRig();
        const evt = {
            position: new 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