"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const HoverLabelEntity_1 = require("../Entities/HoverLabelEntity");
const TryShowHoverLabel_1 = require("./TryShowHoverLabel");
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Label_1 = require("../../Label");
const Babylon_1 = require("../../Babylon");
const Callouts_1 = require("../../Callouts");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = appObjects.getOrCreate("appObj");
    const label = (0, Label_1.makeLabelEntity)(appObj);
    label.custom = "custom label";
    const hoverLabel = (0, HoverLabelEntity_1.makeHoverLabelEntity)(appObj);
    const showScreenSpy = jest.spyOn(hoverLabel, "showScreenHoverLabel");
    const showWorldSpy = jest.spyOn(hoverLabel, "showWorldHoverLabel");
    const hideSpy = jest.spyOn(hoverLabel, "hideHoverLabel");
    const tryShowUC = (0, TryShowHoverLabel_1.makeTryShowHoverLabel)(appObj);
    const mockPixelPick = (0, Babylon_1.makeMockScenePixelPickUC)(appObjects).scenePixelPick;
    mockPixelPick.mockReturnValue({ appObjectID: "appObj" });
    const mockRayPick = (0, Babylon_1.makeMockSceneRayPickUC)(appObjects);
    const mockPick = jest.fn().mockReturnValue({
        appObjectID: "appObj",
        worldPickPoint: new core_2.Vector3(1, 2, 3),
    });
    mockRayPick.sceneRayPick = mockPick;
    return {
        hoverLabel,
        label,
        tryShowUC,
        showScreenSpy,
        showWorldSpy,
        hideSpy,
        mockPick,
        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 core_2.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 core_2.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 core_2.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 core_2.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 core_2.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 core_2.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 core_2.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(core_2.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(core_2.ParametricLine.Forward());
        expect(showWorldSpy).toHaveBeenCalledWith(label.custom, new core_2.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(core_2.ParametricLine.Forward());
        expect(showWorldSpy).toHaveBeenCalledWith(label.default, new core_2.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(core_2.ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if app object ID is unknown", () => {
        const { tryShowUC, hideSpy, mockPick } = makeTestRig();
        mockPick.mockReturnValue({
            appObjectID: "someOtherObject",
            worldPickPoint: new core_2.Vector3(1, 2, 3),
        });
        tryShowUC.tryShowWorldHoverLabel(core_2.ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if app object ID is undefined", () => {
        const { tryShowUC, hideSpy, mockPick } = makeTestRig();
        mockPick.mockReturnValue({
            worldPickPoint: new core_2.Vector3(1, 2, 3),
        });
        tryShowUC.tryShowWorldHoverLabel(core_2.ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the world pick is undefined", () => {
        const { tryShowUC, hideSpy, mockPick } = makeTestRig();
        mockPick.mockReturnValue({
            appObjectID: "appObj",
        });
        tryShowUC.tryShowWorldHoverLabel(core_2.ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hide the hover label if pick is undefined", () => {
        const { tryShowUC, hideSpy, mockPick } = makeTestRig();
        mockPick.mockReturnValue(undefined);
        tryShowUC.tryShowWorldHoverLabel(core_2.ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hides the hover label if it hits a callout with a point", () => {
        const { hoverLabel, tryShowUC, hideSpy, appObj } = makeTestRig();
        (0, Callouts_1.makeCalloutEntity)(appObj);
        hoverLabel.allowHoverLabel = true;
        tryShowUC.tryShowScreenHoverLabel(core_2.Vector2.One());
        expect(hideSpy).toHaveBeenCalled();
    });
    it("Hides the hover label if it hits a callout with a ray", () => {
        const { hoverLabel, tryShowUC, hideSpy, appObj } = makeTestRig();
        (0, Callouts_1.makeCalloutEntity)(appObj);
        hoverLabel.allowHoverLabel = true;
        tryShowUC.tryShowWorldHoverLabel(core_2.ParametricLine.Forward());
        expect(hideSpy).toHaveBeenCalled();
    });
});
//# sourceMappingURL=TryShowHoverLabel.test.js.map