import { makeAppObjectRepo, ParametricLine, Vector2 } from "@vived/core";
import { makeMockPixelToSceneRayUC } from "../../Babylon";
import { makeMockTryAddNewLandmarkUC } from "../Mocks/MockTryAddNewLandmarkUC";
import { makeMockTryPreviewLandmarkUC } from "../Mocks/MockTryPreviewLandmarkUC";
import { makeMouseLandmark } from "./MouseLandmark";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const mockPixelToSceneRayUC = makeMockPixelToSceneRayUC(appObjects);
    mockPixelToSceneRayUC.pixelToSceneRay = jest.fn(() => {
        return new ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        });
    });
    const tryAddLandmarkUc = makeMockTryAddNewLandmarkUC(appObjects);
    const tryPreviewLandmarkUc = makeMockTryPreviewLandmarkUC(appObjects);
    const controller = makeMouseLandmark(appObjects.getOrCreate("Controller"));
    return {
        controller,
        mockPixelToSceneRayUC,
        tryAddLandmarkUc,
        tryPreviewLandmarkUc,
    };
}
describe("MouseLandmark Controller Test", () => {
    it("Tries to show on move", () => {
        const { tryPreviewLandmarkUc, mockPixelToSceneRayUC, controller } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onMove(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        }), false);
    });
    it("Test OnMove with mouse down", () => {
        const { tryPreviewLandmarkUc, mockPixelToSceneRayUC, controller } = makeTestRig();
        const evt1 = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt1);
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onMove(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        }), true);
    });
    it("Test OnDown", () => {
        const { tryPreviewLandmarkUc, mockPixelToSceneRayUC, controller } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        }), true);
    });
    it("Triggers OnUp when mouse down starts with button 0", () => {
        const { tryAddLandmarkUc, mockPixelToSceneRayUC, controller, tryPreviewLandmarkUc, } = makeTestRig();
        const evt_start = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt_start);
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onUp(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryAddLandmarkUc.addFromRay).toHaveBeenCalledWith(new ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        }));
        expect(tryPreviewLandmarkUc.hidePreview).toHaveBeenCalled();
    });
    it("Does not trigger OnUp when mouse down starts with button 1", () => {
        const { mockPixelToSceneRayUC, controller, tryAddLandmarkUc } = makeTestRig();
        const evt_start = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt_start);
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        controller.onUp(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).not.toHaveBeenCalled();
        expect(tryAddLandmarkUc.tryAddLandmark).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=MouseLandmark.test.js.map