import { makeAppObjectRepo } from "@vived/core";
import { Vector2, Vector3 } from "@vived/core";
import { HoverLabelMode, makeHoverLabelEntity } from "./HoverLabelEntity";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObject = appObjects.getOrCreate("HoverLabelAO");
    const hoverLabel = makeHoverLabelEntity(appObject);
    const observer = jest.fn();
    hoverLabel.addChangeObserver(observer);
    return {
        appObjects,
        hoverLabel,
        observer,
    };
}
describe("Hover Label Entity", () => {
    it("Shows a screen hover label", () => {
        const { hoverLabel } = makeTestRig();
        expect(hoverLabel.show).toEqual(false);
        expect(hoverLabel.allowHoverLabel).toEqual(true);
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        expect(hoverLabel.show).toEqual(true);
    });
    it("Notifies when a new label is set", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify if there is no change in the set label", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        observer.mockClear();
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        expect(observer).not.toHaveBeenCalled();
    });
    it("Notifies when cleared", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        observer.mockClear();
        hoverLabel.hideHoverLabel();
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify if there is nothing to hide", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.hideHoverLabel();
        hoverLabel.hideHoverLabel();
        hoverLabel.hideHoverLabel();
        expect(observer).not.toHaveBeenCalled();
    });
    it("Allows a observer to be unsubscribed", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.removeChangeObserver(observer);
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        hoverLabel.hideHoverLabel();
        expect(observer).not.toHaveBeenCalled();
    });
    it("Gets a hover label", () => {
        const { hoverLabel } = makeTestRig();
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        expect(hoverLabel.label).toEqual("HoverLabel");
    });
    it("Notifies if the allow flag changes", () => {
        const { hoverLabel, observer } = makeTestRig();
        expect(hoverLabel.allowHoverLabel).toEqual(true);
        hoverLabel.allowHoverLabel = false;
        expect(observer).toHaveBeenCalled();
        expect(hoverLabel.allowHoverLabel).toEqual(false);
        observer.mockClear();
        hoverLabel.allowHoverLabel = true;
        expect(observer).toHaveBeenCalled();
        expect(hoverLabel.allowHoverLabel).toEqual(true);
    });
    it("Does not notify if the allow flag is set but does not change", () => {
        const { hoverLabel, observer } = makeTestRig();
        expect(hoverLabel.allowHoverLabel).toEqual(true);
        hoverLabel.allowHoverLabel = true;
        hoverLabel.allowHoverLabel = true;
        hoverLabel.allowHoverLabel = true;
        expect(observer).not.toHaveBeenCalled();
    });
    it("Does not show if the allow is set to false", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.allowHoverLabel = false;
        observer.mockClear();
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        expect(observer).not.toHaveBeenCalled();
        expect(hoverLabel.show).toEqual(false);
    });
    it("Hides the current label if the allow hover labels is set to false", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        observer.mockClear();
        expect(hoverLabel.show).toEqual(true);
        hoverLabel.allowHoverLabel = false;
        expect(observer).toHaveBeenCalled();
        expect(hoverLabel.show).toEqual(false);
    });
    it("Sets the mode to Screen when the label is set with 2D", () => {
        const { hoverLabel } = makeTestRig();
        expect(hoverLabel.mode).toEqual(HoverLabelMode.NONE);
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        expect(hoverLabel.mode).toEqual(HoverLabelMode.SCREEN);
    });
    it("Sets the mode to None when the label is hidden", () => {
        const { hoverLabel } = makeTestRig();
        hoverLabel.showScreenHoverLabel("HoverLabel", new Vector2(5, 6));
        expect(hoverLabel.mode).toEqual(HoverLabelMode.SCREEN);
        hoverLabel.hideHoverLabel();
        expect(hoverLabel.mode).toEqual(HoverLabelMode.NONE);
    });
    it("Shows the world Hover Label", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.showWorldHoverLabel("HoverLabel", new Vector3(5, 6, 7));
        expect(hoverLabel.show).toEqual(true);
        expect(hoverLabel.label).toEqual("HoverLabel");
        expect(hoverLabel.transform.worldPosition).toEqual(new Vector3(5, 6, 7));
        expect(hoverLabel.mode).toEqual(HoverLabelMode.WORLD);
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Does not shows the world Hover Label if not allowed", () => {
        const { hoverLabel } = makeTestRig();
        hoverLabel.allowHoverLabel = false;
        hoverLabel.showWorldHoverLabel("HoverLabel", new Vector3(5, 6, 7));
        expect(hoverLabel.show).toEqual(false);
    });
    it("Only notifies when there is a change", () => {
        const { hoverLabel, observer } = makeTestRig();
        hoverLabel.showWorldHoverLabel("HoverLabel", new Vector3(5, 6, 7));
        hoverLabel.showWorldHoverLabel("HoverLabel", new Vector3(5, 6, 7));
        hoverLabel.showWorldHoverLabel("HoverLabel", new Vector3(5, 6, 7));
        hoverLabel.showWorldHoverLabel("HoverLabel", new Vector3(5, 6, 7));
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Sets the local position to zero when hiding", () => {
        const { hoverLabel } = makeTestRig();
        hoverLabel.showWorldHoverLabel("HoverLabel", new Vector3(5, 6, 7));
        hoverLabel.hideHoverLabel();
        expect(hoverLabel.transform.localPosition).toEqual(Vector3.Zero());
    });
});
//# sourceMappingURL=HoverLabelEntity.test.js.map