"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 MouseInput_1 = require("../../MouseInput/Entities/MouseInput");
const TrySelectObjectPickUCMock_1 = require("../Mocks/TrySelectObjectPickUCMock");
const TrySubmitObjectPickUCMock_1 = require("../Mocks/TrySubmitObjectPickUCMock");
const MouseObjectPickMC_1 = require("./MouseObjectPickMC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const baseApp = (0, BaseAppState_1.makeBaseAppState)(appObjects.getOrCreate("App"));
    const mouseInput = (0, MouseInput_1.makeMouseInput)(appObjects.getOrCreate("Input"));
    const registerSpy = jest.spyOn(mouseInput, "registerController");
    const trySelect = (0, TrySelectObjectPickUCMock_1.makeTrySelectObjectPickUCMock)(appObjects).tryWithPixel;
    const trySubmit = (0, TrySubmitObjectPickUCMock_1.makeTrySubmitObjectPickUCMock)(appObjects).tryWithPixel;
    const controller = new MouseObjectPickMC_1.MouseObjectPickMC(appObjects.getOrCreate("AO"));
    return { controller, baseApp, registerSpy, trySelect, trySubmit };
}
describe("Mouse Object Pick Controller", () => {
    it("Registers with the mouse input when constructed", () => {
        const { registerSpy, controller } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(controller);
    });
    it("Doesn't trigger the UC when the click is not button 0", () => {
        const { baseApp, controller, trySelect } = makeTestRig();
        baseApp.isAuthoring = true;
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt);
        expect(trySelect).not.toHaveBeenCalled();
    });
    it("Triggers the Select Object Pick UC when the click is button 0 and authoring", () => {
        const { baseApp, controller, trySubmit, trySelect } = makeTestRig();
        baseApp.isAuthoring = true;
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt);
        expect(trySelect).toHaveBeenCalledWith(new core_2.Vector2(2, 3));
        expect(trySubmit).not.toHaveBeenCalled();
    });
    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 evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt);
        expect(trySubmit).toHaveBeenCalledWith(new core_2.Vector2(2, 3));
        expect(trySelect).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=MouseObjectPickMC.test.js.map