"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const BaseAppState_1 = require("../../BaseApp/Entity/BaseAppState");
const TouchInput_1 = require("../../TouchController/Entities/TouchInput");
const TrySelectObjectPickUCMock_1 = require("../Mocks/TrySelectObjectPickUCMock");
const TrySubmitObjectPickUCMock_1 = require("../Mocks/TrySubmitObjectPickUCMock");
const TouchObjectPickTC_1 = require("./TouchObjectPickTC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const baseApp = (0, BaseAppState_1.makeBaseAppState)(appObjects.getOrCreate("App"));
    const touchInput = (0, TouchInput_1.makeTouchInput)(appObjects.getOrCreate("Input"));
    const registerSpy = jest.spyOn(touchInput, "registerController");
    const trySelect = (0, TrySelectObjectPickUCMock_1.makeTrySelectObjectPickUCMock)(appObjects).tryWithPixel;
    const trySubmit = (0, TrySubmitObjectPickUCMock_1.makeTrySubmitObjectPickUCMock)(appObjects).tryWithPixel;
    const controller = new TouchObjectPickTC_1.TouchObjectPickTC(appObjects.getOrCreate("AO"));
    return { controller, baseApp, registerSpy, trySelect, trySubmit };
}
function mockTouchInputEvent(touchPositions) {
    const mockEvt = new TouchEvent("");
    const touchCount = touchPositions.length;
    let sumPos = core_2.Vector2.Zero();
    const touches = touchPositions.map((pos, i) => {
        sumPos = core_2.Vector2.Add(sumPos, pos);
        return {
            id: i,
            position: pos,
        };
    });
    const avgPos = touchCount === 0
        ? core_2.Vector2.Zero()
        : new core_2.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 core_2.Vector2(2, 3)]);
        controller.onTap(input);
        expect(trySubmit).not.toHaveBeenCalled();
        expect(trySelect).toHaveBeenCalledWith(new core_2.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 core_2.Vector2(2, 3)]);
        controller.onTap(input);
        expect(trySubmit).toHaveBeenCalledWith(new core_2.Vector2(2, 3));
        expect(trySelect).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=TouchObjectPickTC.test.js.map