"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const TryPreviewLandmarkUC_1 = require("./TryPreviewLandmarkUC");
const Babylon_1 = require("../../Babylon");
const LandmarkRepo_1 = require("../Entities/LandmarkRepo");
const LandmarkEntity_1 = require("../Entities/LandmarkEntity");
const Tools_1 = require("../../Tools");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const pick = {
        hit: true,
        appObjectID: "anAppObject",
        normal: core_2.Vector3.Forward(),
        worldPickPoint: core_2.Vector3.Zero(),
    };
    const mockRayPick = (0, Babylon_1.makeMockSceneRayPickUC)(appObjects);
    const mockPick = jest.fn().mockReturnValue(pick);
    mockRayPick.sceneRayPick = mockPick;
    const landmarkAO = appObjects.getOrCreate("Landmark");
    const landmark = (0, LandmarkEntity_1.makeLandmarkEntity)(landmarkAO);
    const previewUC = (0, TryPreviewLandmarkUC_1.makeTryPreviewLandmark)(landmarkAO);
    const pickedAO = appObjects.getOrCreate("anAppObject");
    (0, LandmarkRepo_1.makeLandmarkRepoEntity)(pickedAO);
    const toolRepo = (0, Tools_1.makeToolRepo)(appObjects.getOrCreate("ToolRepo"));
    toolRepo.makeTool("LANDMARK");
    toolRepo.makeTool("OTHER");
    toolRepo.triggerTool("LANDMARK");
    return {
        previewUC,
        landmark,
        mockPick,
        pick,
        toolRepo,
    };
}
describe("Try Preview Landmark Test", () => {
    it("Shows the preview", () => {
        const { landmark, previewUC } = makeTestRig();
        landmark.hideable.isHidden = true;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.hideable.isHidden).toEqual(false);
    });
    it("Sets the position to the pick pos", () => {
        const { landmark, previewUC, pick } = makeTestRig();
        pick.worldPickPoint = new core_2.Vector3(1, 2, 3);
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.position).toEqual(new core_2.Vector3(1, 2, 3));
    });
    it("Sets the rotation to the look rotation", () => {
        const { landmark, previewUC, pick } = makeTestRig();
        pick.normal = new core_2.Vector3(1, 2, 3);
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        const expectedQ = core_2.Quaternion.FromDirectionVector(new core_2.Vector3(1, 2, 3));
        expect(core_2.Quaternion.Close(landmark.rotation, expectedQ)).toEqual(true);
    });
    it("Sets the pressed value to false", () => {
        const { landmark, previewUC } = makeTestRig();
        landmark.selectable.pressed = true;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.selectable.pressed).toEqual(false);
    });
    it("Sets the pressed value to true", () => {
        const { landmark, previewUC } = makeTestRig();
        landmark.selectable.pressed = false;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), true);
        expect(landmark.selectable.pressed).toEqual(true);
    });
    it("Hides the Preview if not allowed", () => {
        const { landmark, previewUC } = makeTestRig();
        previewUC.allow = () => {
            return false;
        };
        landmark.hideable.isHidden = false;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.hideable.isHidden).toEqual(true);
    });
    it("Hides the Preview if the pick return undefined", () => {
        const { landmark, previewUC, mockPick } = makeTestRig();
        mockPick.mockReturnValue(undefined);
        landmark.hideable.isHidden = false;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.hideable.isHidden).toEqual(true);
    });
    it("Hides the Preview if the pick does not have an app object id", () => {
        const { landmark, previewUC, pick } = makeTestRig();
        pick.appObjectID = undefined;
        landmark.hideable.isHidden = false;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.hideable.isHidden).toEqual(true);
    });
    it("Hides the Preview if the pick does not have an world point", () => {
        const { landmark, previewUC, pick } = makeTestRig();
        pick.worldPickPoint = undefined;
        landmark.hideable.isHidden = false;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.hideable.isHidden).toEqual(true);
    });
    it("Hides the Preview if the pick does not have an normal", () => {
        const { landmark, previewUC, pick } = makeTestRig();
        pick.normal = undefined;
        landmark.hideable.isHidden = false;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.hideable.isHidden).toEqual(true);
    });
    it("Hides the Preview if the picked object does not have a Repo", () => {
        const { landmark, previewUC, pick } = makeTestRig();
        pick.appObjectID = "somethingElse";
        landmark.hideable.isHidden = false;
        previewUC.tryPreviewLandmark(core_2.ParametricLine.Forward(), false);
        expect(landmark.hideable.isHidden).toEqual(true);
    });
    it("Does not allow if the tool is not Callout", () => {
        const { previewUC, toolRepo } = makeTestRig();
        toolRepo.triggerTool("OTHER");
        expect(previewUC.allow()).toEqual(false);
        toolRepo.triggerTool("LANDMARK");
        expect(previewUC.allow()).toEqual(true);
    });
});
//# sourceMappingURL=TryPreviewLandmarkUC.test.js.map