import { makeHoverLabelEntity } from "../Entities/HoverLabelEntity";
import { makeTryShowHoverLabel } from "./TryShowHoverLabel";
import { makeAppObjectRepo } from "@vived/core";
import { ParametricLine, Vector2, Vector3 } from "@vived/core";
import { makeLabelEntity } from "../../Label";
import { makeMockScenePixelPickUC, makeMockSceneRayPickUC, } from "../../Babylon";
import { makeCalloutEntity } from "../../Callouts";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = appObjects.getOrCreate("appObj");
    const label = makeLabelEntity(appObj);
    label.custom = "custom label";
    const hoverLabel = makeHoverLabelEntity(appObj);
    const showScreenSpy = jest.spyOn(hoverLabel, "showScreenHoverLabel");
    const showWorldSpy = jest.spyOn(hoverLabel, "showWorldHoverLabel");
    const hideSpy = jest.spyOn(hoverLabel, "hideHoverLabel");
    const tryShowUC = makeTryShowHoverLabel(appObj);
    const mockRayPick = makeMockSceneRayPickUC(appObjects).sceneRayPick;
    const mockPixelPick = makeMockScenePixelPickUC(appObjects).scenePixelPick;
    mockPixelPick.mockReturnValue({ appObjectID: "appObj" });
    mockRayPick.mockReturnValue({
        appObjectID: "appObj",
        worldPickPoint: new Vector3(1, 2, 3),
    });
    return {
        hoverLabel,
        label,
        tryShowUC,
        showScreenSpy,
        showWorldSpy,
        hideSpy,
        mockRayPick,
        mockPixelPick,
        appObj,
    };
}
describe("Try Showing the Screen Hover Label Use Case", () => {
    it("Calls hide if the allow hover label is set to false", () => {
        const { hoverLabel, tryShowUC, hideSpy } = makeTestRig();
        hoverLabel.allowHoverLabel = false;
        tryShowUC.tryShowScreenHoverLabel(new Vector2(1, 1));
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Calls Show Screen Hover label with the custom label and screen position", () => {
        const { hoverLabel, label, tryShowUC, showScreenSpy } = makeTestRig();
        const position = new Vector2(1, 1);
        hoverLabel.allowHoverLabel = true;
        tryShowUC.tryShowScreenHoverLabel(position);
        expect(showScreenSpy).toHaveBeenCalledWith(label.custom, position);
    });
    it("Calls Show Screen Hover label with the default label and screen position", () => {
        const { hoverLabel, label, tryShowUC, showScreenSpy } = makeTestRig();
        const position = new Vector2(1, 1);
        hoverLabel.allowHoverLabel = true;
        label.custom = "";
        label.default = "default label";
        tryShowUC.tryShowScreenHoverLabel(position);
        expect(showScreenSpy).toHaveBeenCalledWith(label.default, position);
    });
    it("Hide the hover label if the label has nothing to show", () => {
        const { hoverLabel, label, tryShowUC, hideSpy } = makeTestRig();
        const position = new Vector2(1, 1);
        hoverLabel.allowHoverLabel = true;
        label.custom = "";
        label.default = "";
        tryShowUC.tryShowScreenHoverLabel(position);
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if app object ID is unknown", () => {
        const { tryShowUC, hideSpy, mockPixelPick } = makeTestRig();
        const position = new Vector2(1, 1);
        mockPixelPick.mockReturnValue({ appObjectID: "someOtherObject" });
        tryShowUC.tryShowScreenHoverLabel(position);
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if app object ID is undefined", () => {
        const { tryShowUC, hideSpy, mockPixelPick } = makeTestRig();
        const position = new Vector2(1, 1);
        mockPixelPick.mockReturnValue({});
        tryShowUC.tryShowScreenHoverLabel(position);
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if pick is undefined", () => {
        const { tryShowUC, hideSpy, mockPixelPick } = makeTestRig();
        const position = new Vector2(1, 1);
        mockPixelPick.mockReturnValue(undefined);
        tryShowUC.tryShowScreenHoverLabel(position);
        expect(hideSpy).toHaveBeenCalled();
    });
});
describe("Try Showing the World Hover Label Use Case", () => {
    it("Calls hide if the allow hover label is set to false", () => {
        const { hoverLabel, tryShowUC, hideSpy } = makeTestRig();
        hoverLabel.allowHoverLabel = false;
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Calls Show Screen Hover label with the custom label and screen position", () => {
        const { hoverLabel, label, tryShowUC, showWorldSpy } = makeTestRig();
        hoverLabel.allowHoverLabel = true;
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(showWorldSpy).toHaveBeenCalledWith(label.custom, new Vector3(1, 2, 3));
    });
    it("Calls Show Screen Hover label with the default label and screen position", () => {
        const { hoverLabel, label, tryShowUC, showWorldSpy } = makeTestRig();
        hoverLabel.allowHoverLabel = true;
        label.custom = "";
        label.default = "default label";
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(showWorldSpy).toHaveBeenCalledWith(label.default, new Vector3(1, 2, 3));
    });
    it("Hide the hover label if the label has nothing to show", () => {
        const { hoverLabel, label, tryShowUC, hideSpy } = makeTestRig();
        hoverLabel.allowHoverLabel = true;
        label.custom = "";
        label.default = "";
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if app object ID is unknown", () => {
        const { tryShowUC, hideSpy, mockRayPick } = makeTestRig();
        mockRayPick.mockReturnValue({
            appObjectID: "someOtherObject",
            worldPickPoint: new Vector3(1, 2, 3),
        });
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if app object ID is undefined", () => {
        const { tryShowUC, hideSpy, mockRayPick } = makeTestRig();
        mockRayPick.mockReturnValue({
            worldPickPoint: new Vector3(1, 2, 3),
        });
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the world pick is undefined", () => {
        const { tryShowUC, hideSpy, mockRayPick } = makeTestRig();
        mockRayPick.mockReturnValue({
            appObjectID: "appObj",
        });
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if pick is undefined", () => {
        const { tryShowUC, hideSpy, mockRayPick } = makeTestRig();
        mockRayPick.mockReturnValue(undefined);
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hides the hover label if it hits a callout with a point", () => {
        const { hoverLabel, tryShowUC, hideSpy, appObj } = makeTestRig();
        makeCalloutEntity(appObj);
        hoverLabel.allowHoverLabel = true;
        tryShowUC.tryShowScreenHoverLabel(Vector2.One());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hides the hover label if it hits a callout with a ray", () => {
        const { hoverLabel, tryShowUC, hideSpy, appObj } = makeTestRig();
        makeCalloutEntity(appObj);
        hoverLabel.allowHoverLabel = true;
        tryShowUC.tryShowWorldHoverLabel(ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
});
//# sourceMappingURL=TryShowHoverLabel.test.js.map