"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const MockTryAddNewLandmarkUC_1 = require("../Mocks/MockTryAddNewLandmarkUC");
const MockTryPreviewLandmarkUC_1 = require("../Mocks/MockTryPreviewLandmarkUC");
const MouseLandmark_1 = require("./MouseLandmark");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const mockPixelToSceneRayUC = (0, Babylon_1.makeMockPixelToSceneRayUC)(appObjects);
    mockPixelToSceneRayUC.pixelToSceneRay = jest.fn(() => {
        return new core_1.ParametricLine({
            x0: 1,
            y0: 1,
            z0: 1,
            a: 1,
            b: 1,
            c: 1,
        });
    });
    const tryAddLandmarkUc = (0, MockTryAddNewLandmarkUC_1.makeMockTryAddNewLandmarkUC)(appObjects);
    const tryPreviewLandmarkUc = (0, MockTryPreviewLandmarkUC_1.makeMockTryPreviewLandmarkUC)(appObjects);
    const controller = (0, MouseLandmark_1.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 core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onMove(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new core_1.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 core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt1);
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onMove(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new core_1.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 core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryPreviewLandmarkUc.tryPreviewLandmark).toHaveBeenCalledWith(new core_1.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 core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt_start);
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onUp(evt);
        expect(mockPixelToSceneRayUC.pixelToSceneRay).toHaveBeenCalled();
        expect(tryAddLandmarkUc.addFromRay).toHaveBeenCalledWith(new core_1.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 core_1.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt_start);
        const evt = {
            position: new core_1.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