"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const MouseInput_1 = require("../../MouseInput");
const TryStickAppObjectUCMock_1 = require("../Mocks/TryStickAppObjectUCMock");
const DoubleClickToStickMC_1 = require("./DoubleClickToStickMC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const mouseInput = (0, MouseInput_1.makeMouseInput)(appObjects.getOrCreate("Input"));
    const registerSpy = jest.spyOn(mouseInput, "registerController");
    const controller = new DoubleClickToStickMC_1.DoubleClickToStickMC(appObjects.getOrCreate("AO"));
    const tryStickMock = (0, TryStickAppObjectUCMock_1.makeTryStickAppObjectUCMock)(appObjects);
    const dateNowMock = jest.fn();
    Date.now = dateNowMock;
    dateNowMock.mockReturnValue(0);
    return {
        registerSpy,
        controller,
        tryStickMock,
        dateNowMock,
    };
}
describe("Mouse Click to stick controller", () => {
    it("Registers with the mouse input when constructed", () => {
        const { registerSpy, controller } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(controller);
    });
    it("Triggers the try stick", () => {
        const { tryStickMock, controller, dateNowMock } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt);
        dateNowMock.mockReturnValue(controller.maxClickTimeMS);
        controller.onClick(evt);
        expect(tryStickMock.tryWithPixel).toHaveBeenCalledWith(new core_2.Vector2(2, 3));
    });
    it("Does not send if the double click takes too long", () => {
        const { dateNowMock, tryStickMock, controller } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt);
        dateNowMock.mockReturnValue(controller.maxClickTimeMS + 1);
        controller.onClick(evt);
        expect(tryStickMock.tryWithPixel).not.toHaveBeenCalled();
    });
    it("Does not send if the double click has too much movement", () => {
        const { tryStickMock, controller } = makeTestRig();
        const evt1 = {
            position: new core_2.Vector2(0, 0),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        const evt2 = {
            position: new core_2.Vector2(1 + controller.maxClickDistancePx, 0),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt1);
        controller.onClick(evt2);
        expect(tryStickMock.tryWithPixel).not.toHaveBeenCalled();
    });
    it("Does send if the double click has a little movement", () => {
        const { tryStickMock, controller } = makeTestRig();
        const evt1 = {
            position: new core_2.Vector2(0, 0),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        const evt2 = {
            position: new core_2.Vector2(controller.maxClickDistancePx, 0),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt1);
        controller.onClick(evt2);
        expect(tryStickMock.tryWithPixel).toHaveBeenCalled();
    });
    it("Does not send if the double click is not button 0", () => {
        const { tryStickMock, controller } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt);
        controller.onClick(evt);
        expect(tryStickMock.tryWithPixel).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=DoubleClickToStickMC.test.js.map