import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { makeBaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { makeMouseInput, } from "../../MouseInput/Entities/MouseInput";
import { makeTrySelectObjectPickUCMock } from "../Mocks/TrySelectObjectPickUCMock";
import { makeTrySubmitObjectPickUCMock } from "../Mocks/TrySubmitObjectPickUCMock";
import { MouseObjectPickMC } from "./MouseObjectPickMC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const baseApp = makeBaseAppState(appObjects.getOrCreate("App"));
    const mouseInput = makeMouseInput(appObjects.getOrCreate("Input"));
    const registerSpy = jest.spyOn(mouseInput, "registerController");
    const trySelect = makeTrySelectObjectPickUCMock(appObjects).tryWithPixel;
    const trySubmit = makeTrySubmitObjectPickUCMock(appObjects).tryWithPixel;
    const controller = new 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 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 Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt);
        expect(trySelect).toHaveBeenCalledWith(new 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 Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttonup"),
        };
        controller.onClick(evt);
        expect(trySubmit).toHaveBeenCalledWith(new Vector2(2, 3));
        expect(trySelect).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=MouseObjectPickMC.test.js.map