import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { makeBaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { makeTouchInput, } from "../../TouchController/Entities/TouchInput";
import { makeTrySelectObjectPickUCMock } from "../Mocks/TrySelectObjectPickUCMock";
import { makeTrySubmitObjectPickUCMock } from "../Mocks/TrySubmitObjectPickUCMock";
import { TouchObjectPickTC } from "./TouchObjectPickTC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const baseApp = makeBaseAppState(appObjects.getOrCreate("App"));
    const touchInput = makeTouchInput(appObjects.getOrCreate("Input"));
    const registerSpy = jest.spyOn(touchInput, "registerController");
    const trySelect = makeTrySelectObjectPickUCMock(appObjects).tryWithPixel;
    const trySubmit = makeTrySubmitObjectPickUCMock(appObjects).tryWithPixel;
    const controller = new TouchObjectPickTC(appObjects.getOrCreate("AO"));
    return { controller, baseApp, registerSpy, trySelect, trySubmit };
}
function mockTouchInputEvent(touchPositions) {
    const mockEvt = new TouchEvent("");
    const touchCount = touchPositions.length;
    let sumPos = Vector2.Zero();
    const touches = touchPositions.map((pos, i) => {
        sumPos = Vector2.Add(sumPos, pos);
        return {
            id: i,
            position: pos,
        };
    });
    const avgPos = touchCount === 0
        ? Vector2.Zero()
        : new Vector2(sumPos.x / touchCount, sumPos.y / touchCount);
    return {
        event: mockEvt,
        touchCenter: avgPos,
        touchCount,
        touches,
    };
}
describe("TouchObjectPick Controller", () => {
    it("Registers with the mouse input when constructed", () => {
        const { registerSpy, controller } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(controller);
    });
    it("Triggers the Select Object Pick UC when tapped and authoring", () => {
        const { baseApp, controller, trySubmit, trySelect } = makeTestRig();
        baseApp.isAuthoring = true;
        const input = mockTouchInputEvent([new Vector2(2, 3)]);
        controller.onTap(input);
        expect(trySubmit).not.toHaveBeenCalled();
        expect(trySelect).toHaveBeenCalledWith(new Vector2(2, 3));
    });
    it("Triggers the Submit Object Pick UC when the click is button 0 and not authoring", () => {
        const { controller, baseApp, trySubmit, trySelect } = makeTestRig();
        baseApp.isAuthoring = false;
        const input = mockTouchInputEvent([new Vector2(2, 3)]);
        controller.onTap(input);
        expect(trySubmit).toHaveBeenCalledWith(new Vector2(2, 3));
        expect(trySelect).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=TouchObjectPickTC.test.js.map