"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const MockTryAddNewLandmarkUC_1 = require("../Mocks/MockTryAddNewLandmarkUC");
const MockTryPreviewLandmarkUC_1 = require("../Mocks/MockTryPreviewLandmarkUC");
const TouchLandmark_1 = require("./TouchLandmark");
class MockPixelToSceneRayUC extends Babylon_1.PixelToSceneRayUC {
    constructor() {
        super(...arguments);
        this.pixelToSceneRay = jest.fn(() => {
            return new core_2.ParametricLine({
                x0: 1,
                y0: 1,
                z0: 1,
                a: 1,
                b: 1,
                c: 1,
            });
        });
    }
}
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("AO");
    const mockPixelToSceneRayUC = new MockPixelToSceneRayUC(ao, MockPixelToSceneRayUC.type);
    const tryAddLandmarkUc = (0, MockTryAddNewLandmarkUC_1.makeMockTryAddNewLandmarkUC)(appObjects);
    const tryPreviewLandmarkUc = (0, MockTryPreviewLandmarkUC_1.makeMockTryPreviewLandmarkUC)(appObjects);
    const landmarkController = (0, TouchLandmark_1.makeTouchLandmark)(appObjects.getOrCreate("Controller"));
    return {
        landmarkController,
        mockPixelToSceneRayUC,
        tryAddLandmarkUc,
        tryPreviewLandmarkUc,
    };
}
function mockTouchInputEvent(touchPositions) {
    const mockEvt = new TouchEvent("");
    const touchCount = touchPositions.length;
    let sumPos = core_2.Vector2.Zero();
    const touches = touchPositions.map((pos, i) => {
        sumPos = core_2.Vector2.Add(sumPos, pos);
        return {
            id: i,
            position: pos,
        };
    });
    const avgPos = touchCount === 0
        ? core_2.Vector2.Zero()
        : new core_2.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 core_2.Vector2(0, 0), new core_2.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 core_2.Vector2(0, 0)]);
        landmarkController.onTouchStart(input);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new core_2.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 core_2.Vector2(0, 0), new core_2.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 core_2.Vector2(0, 0)]);
        landmarkController.onTouchMove(input);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new core_2.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 core_2.Vector2(0, 0), new core_2.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 core_2.Vector2(0, 0)]);
        landmarkController.onTouchEnd(input);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryAddLandmarkUc.addFromRay).toHaveBeenCalledWith(new core_2.ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        }));
        expect(tryPreviewLandmarkUc.hidePreview).toHaveBeenCalled();
    });
});
//# sourceMappingURL=TouchLandmark.test.js.map