import { makeAppObjectRepo, ParametricLine, Vector2 } from "@vived/core";
import { makeMockPixelToSceneRayUC } from "../../Babylon";
import { MockMouseInput } from "../../MouseInput/Mocks/MockMouseInput";
import { makeZSpaceEntity } from "../../zSpace/Entities/ZSpaceEntity";
import { HoverAppObjectUCMock } from "../Mocks/HoverAppObjectUCMock";
import { MouseHoverOnAppObject } from "./MouseHoverOnAppObject";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const zSpaceAO = appObjects.getOrCreate("zSpace");
    const zSpace = makeZSpaceEntity(zSpaceAO);
    zSpace.emulate = false;
    const selectionAO = appObjects.getOrCreate("selection");
    const mockUC = new HoverAppObjectUCMock(selectionAO);
    const mockPixelToSceneUC = makeMockPixelToSceneRayUC(appObjects);
    const mockPixelToRay = jest.fn().mockReturnValue(ParametricLine.Forward());
    mockPixelToSceneUC.pixelToSceneRay = mockPixelToRay;
    const mockMouseInput = new MockMouseInput(selectionAO);
    const controller = new MouseHoverOnAppObject(selectionAO);
    const mockAllow = jest.fn();
    mockAllow.mockReturnValue(true);
    controller.allow = mockAllow;
    return {
        mockMouseInput,
        appObjects,
        zSpace,
        controller,
        mockUC,
        mockAllow,
    };
}
describe("Hover Scene Object Mouse Controller", () => {
    it("Sends a ray to the UC on move", () => {
        const { mockUC, controller } = makeTestRig();
        const event = {
            button: -1,
            position: new Vector2(5, 6),
            event: new MouseEvent(""),
        };
        controller.onMove(event);
        expect(mockUC.tryHoverAppObject).toHaveBeenCalledWith(ParametricLine.Forward());
    });
    it("Does not send a ray to the UC on move if not allowed", () => {
        const { controller, mockAllow, mockUC } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        mockAllow.mockReturnValue(false);
        controller.onMove(evt);
        expect(mockUC.tryHoverAppObject).not.toHaveBeenCalled();
    });
    it("Warns if it is added to an app object that does not have a UC", () => {
        const { appObjects } = makeTestRig();
        const anotherAppObj = appObjects.getOrCreate("newAppObj");
        console.warn = jest.fn();
        new MouseHoverOnAppObject(anotherAppObj);
        expect(console.warn).toHaveBeenCalled();
    });
    it("Does not register itself if the object does not have a UC", () => {
        const { appObjects, mockMouseInput } = makeTestRig();
        const anotherAppObj = appObjects.getOrCreate("newAppObj");
        console.warn = jest.fn();
        mockMouseInput.registerController.mockClear();
        new MouseHoverOnAppObject(anotherAppObj);
        expect(mockMouseInput.registerController).not.toHaveBeenCalled();
    });
    it("Does not sends a ray to the UC if zSpace mouse emulate is on", () => {
        const { mockUC, controller, zSpace } = makeTestRig();
        zSpace.emulate = true;
        const event = {
            button: -1,
            position: new Vector2(5, 6),
            event: new MouseEvent(""),
        };
        controller.onMove(event);
        expect(mockUC.tryHoverAppObject).not.toHaveBeenCalledWith();
    });
});
//# sourceMappingURL=MouseHoverOnAppObject.test.js.map