import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine, Quaternion, Vector3 } from "@vived/core";
import { makeTryPreviewLandmark } from "./TryPreviewLandmarkUC";
import { makeMockSceneRayPickUC } from "../../Babylon";
import { makeLandmarkRepoEntity } from "../Entities/LandmarkRepo";
import { makeLandmarkEntity } from "../Entities/LandmarkEntity";
import { makeToolRepo } from "../../Tools";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const pick = {
        hit: true,
        appObjectID: "anAppObject",
        normal: Vector3.Forward(),
        worldPickPoint: Vector3.Zero(),
    };
    const mockRayPick = makeMockSceneRayPickUC(appObjects);
    const mockPick = jest.fn().mockReturnValue(pick);
    mockRayPick.sceneRayPick = mockPick;
    const landmarkAO = appObjects.getOrCreate("Landmark");
    const landmark = makeLandmarkEntity(landmarkAO);
    const previewUC = makeTryPreviewLandmark(landmarkAO);
    const pickedAO = appObjects.getOrCreate("anAppObject");
    makeLandmarkRepoEntity(pickedAO);
    const toolRepo = 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(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 Vector3(1, 2, 3);
        previewUC.tryPreviewLandmark(ParametricLine.Forward(), false);
        expect(landmark.position).toEqual(new Vector3(1, 2, 3));
    });
    it("Sets the rotation to the look rotation", () => {
        const { landmark, previewUC, pick } = makeTestRig();
        pick.normal = new Vector3(1, 2, 3);
        previewUC.tryPreviewLandmark(ParametricLine.Forward(), false);
        const expectedQ = Quaternion.FromDirectionVector(new Vector3(1, 2, 3));
        expect(Quaternion.Close(landmark.rotation, expectedQ)).toEqual(true);
    });
    it("Sets the pressed value to false", () => {
        const { landmark, previewUC } = makeTestRig();
        landmark.selectable.pressed = true;
        previewUC.tryPreviewLandmark(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(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(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(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(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(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(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(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