import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine, Vector2 } from "@vived/core";
import { PixelToSceneRayUC } from "../../Babylon";
import { makeMockTryAddNewLandmarkUC } from "../Mocks/MockTryAddNewLandmarkUC";
import { makeMockTryPreviewLandmarkUC } from "../Mocks/MockTryPreviewLandmarkUC";
import { makeTouchLandmark } from "./TouchLandmark";
class MockPixelToSceneRayUC extends PixelToSceneRayUC {
    constructor() {
        super(...arguments);
        this.pixelToSceneRay = jest.fn(() => {
            return new ParametricLine({
                x0: 1,
                y0: 1,
                z0: 1,
                a: 1,
                b: 1,
                c: 1,
            });
        });
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("AO");
    const mockPixelToSceneRayUC = new MockPixelToSceneRayUC(ao, MockPixelToSceneRayUC.type);
    const tryAddLandmarkUc = makeMockTryAddNewLandmarkUC(appObjects);
    const tryPreviewLandmarkUc = makeMockTryPreviewLandmarkUC(appObjects);
    const landmarkController = makeTouchLandmark(appObjects.getOrCreate("Controller"));
    return {
        landmarkController,
        mockPixelToSceneRayUC,
        tryAddLandmarkUc,
        tryPreviewLandmarkUc,
    };
}
function mockTouchInputEvent(touchPositions) {
    const mockEvt = new TouchEvent("");
    const touchCount = touchPositions.length;
    let sumPos = Vector2.Zero();
    const touches = touchPositions.map((pos, i) => {
        sumPos = Vector2.Add(sumPos, pos);
        return {
            id: i,
            position: pos,
        };
    });
    const avgPos = touchCount === 0
        ? Vector2.Zero()
        : new Vector2(sumPos.x / touchCount, sumPos.y / touchCount);
    return {
        event: mockEvt,
        touchCenter: avgPos,
        touchCount,
        touches,
    };
}
describe("Touch Landmark TouchStart", () => {
    it("Test TouchStart return when there are more than one touch", () => {
        const { landmarkController, mockPixelToSceneRayUC, tryPreviewLandmarkUc } = makeTestRig();
        const input = mockTouchInputEvent([new Vector2(0, 0), new Vector2(0, 0)]);
        landmarkController.onTouchStart(input);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).not.toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).not.toHaveBeenCalled();
    });
    it("Test TouchStart", () => {
        const { landmarkController, mockPixelToSceneRayUC, tryPreviewLandmarkUc } = makeTestRig();
        const input = mockTouchInputEvent([new Vector2(0, 0)]);
        landmarkController.onTouchStart(input);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        }), true);
    });
});
describe("Touch Landmark TouchMove", () => {
    it("Test TouchStart return when there are more than two", () => {
        const { landmarkController, mockPixelToSceneRayUC, tryPreviewLandmarkUc } = makeTestRig();
        const input = mockTouchInputEvent([new Vector2(0, 0), new Vector2(1, 0)]);
        landmarkController.onTouchMove(input);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).not.toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).not.toHaveBeenCalled();
    });
    it("Test TouchMove", () => {
        const { landmarkController, mockPixelToSceneRayUC, tryPreviewLandmarkUc } = makeTestRig();
        const input = mockTouchInputEvent([new Vector2(0, 0)]);
        landmarkController.onTouchMove(input);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        }), true);
    });
});
describe("Touch Landmark TouchEnd", () => {
    it("Test TouchEnd return when there are more than two", () => {
        const { landmarkController, mockPixelToSceneRayUC, tryAddLandmarkUc } = makeTestRig();
        const input = mockTouchInputEvent([new Vector2(0, 0), new Vector2(1, 0)]);
        landmarkController.onTouchEnd(input);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).not.toHaveBeenCalled();
        expect(tryAddLandmarkUc.addFromRay).not.toHaveBeenCalled();
    });
    it("Test TouchEnd", () => {
        const { landmarkController, mockPixelToSceneRayUC, tryAddLandmarkUc, tryPreviewLandmarkUc, } = makeTestRig();
        const input = mockTouchInputEvent([new Vector2(0, 0)]);
        landmarkController.onTouchEnd(input);
        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();
    });
});
//# sourceMappingURL=TouchLandmark.test.js.map