import { makeAppObjectRepo, ParametricLine } from "@vived/core";
import { makeMockSceneRayPickUC } from "../../Babylon";
import { makeBaseAppState } from "../../BaseApp";
import { makeSelectable } from "../Entities/Selectable";
import { makeSelection } from "../Entities/Selection";
import { HoverAppObjectUC, makeHoverAppObject } from "./HoverAppObjectUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const baseAppObj = appObjects.getOrCreate("baseAppObj");
    const selection = makeSelection(baseAppObj);
    const selectabelAppObj = appObjects.getOrCreate("selectableAppObj");
    const selectable = makeSelectable(selectabelAppObj);
    selection.addSelectable(selectable);
    const mockRayPick = makeMockSceneRayPickUC(appObjects);
    const mockPick = jest.fn().mockReturnValue({ appObjectID: "hideableObj" });
    mockRayPick.sceneRayPick = mockPick;
    const baseApp = makeBaseAppState(appObjects.getOrCreate("BaseApp"));
    baseApp.isAuthoring = true;
    const hoverSceneObject = makeHoverAppObject(baseAppObj);
    return {
        appObjects,
        hoverSceneObject,
        selectable,
        selection,
        mockPick,
        registerSpy,
        baseApp,
    };
}
describe("Hover Scene Object UC", () => {
    it("Hovers by ID", () => {
        const { hoverSceneObject, selection } = makeTestRig();
        expect(selection.hoveredObjectId).toEqual(null);
        hoverSceneObject.hoverAppObject("selectableAppObj", true);
        expect(selection.hoveredObjectId).toEqual("selectableAppObj");
    });
    it("Un-Hovers by ID", () => {
        const { hoverSceneObject, selection } = makeTestRig();
        hoverSceneObject.hoverAppObject("selectableAppObj", true);
        expect(selection.hoveredObjectId).toEqual("selectableAppObj");
        hoverSceneObject.hoverAppObject("selectableAppObj", false);
        expect(selection.hoveredObjectId).toEqual(null);
    });
    it("Only un-hovers if the id is currently hovered", () => {
        const { hoverSceneObject, selection } = makeTestRig();
        hoverSceneObject.hoverAppObject("selectableAppObj", true);
        hoverSceneObject.hoverAppObject("some other id", false);
        expect(selection.hoveredObjectId).toEqual("selectableAppObj");
    });
    it("Sets the hovered object ID if it pick on it", () => {
        const { hoverSceneObject, selection, mockPick } = makeTestRig();
        mockPick.mockReturnValue({ appObjectID: "selectableAppObj" });
        expect(selection.hoveredObjectId).toEqual(null);
        hoverSceneObject.tryHoverAppObject(ParametricLine.Forward()); // Ray doesn't matter since we hijack the pick
        expect(selection.hoveredObjectId).toEqual("selectableAppObj");
    });
    it("Sets the hovered to null if the pick doesn't hit anything", () => {
        const { hoverSceneObject, selection, mockPick } = makeTestRig();
        mockPick.mockReturnValue({});
        hoverSceneObject.hoverAppObject("selectableAppObj", true);
        hoverSceneObject.tryHoverAppObject(ParametricLine.Forward()); // Ray doesn't matter since we hijack the pick
        expect(selection.hoveredObjectId).toEqual(null);
    });
    it("Sets the hovered to null if the pick doesn't an app object", () => {
        const { hoverSceneObject, selection, mockPick } = makeTestRig();
        mockPick.mockReturnValue({ appObjectID: "something weired" });
        hoverSceneObject.hoverAppObject("selectableAppObj", true);
        hoverSceneObject.tryHoverAppObject(ParametricLine.Forward()); // Ray doesn't matter since we hijack the pick
        expect(selection.hoveredObjectId).toEqual(null);
    });
    it("Sets the hovered to null if the pick doesn't a selectable object", () => {
        const { hoverSceneObject, selection, mockPick, appObjects } = makeTestRig();
        appObjects.getOrCreate("unselectableAppObject");
        mockPick.mockReturnValue({ appObjectID: "unselectableAppObject" });
        hoverSceneObject.hoverAppObject("selectableAppObj", true);
        hoverSceneObject.tryHoverAppObject(ParametricLine.Forward()); // Ray doesn't matter since we hijack the pick
        expect(selection.hoveredObjectId).toEqual(null);
    });
    it("Gets the singleton", () => {
        const { hoverSceneObject, appObjects } = makeTestRig();
        expect(HoverAppObjectUC.get(appObjects)).toEqual(hoverSceneObject);
    });
    it("Registers as the singleton", () => {
        const { hoverSceneObject, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(hoverSceneObject);
    });
    it("Allows while authoring", () => {
        const { hoverSceneObject, baseApp } = makeTestRig();
        baseApp.isAuthoring = true;
        expect(hoverSceneObject.allowHover()).toEqual(true);
        expect(hoverSceneObject.allowTryHover()).toEqual(true);
        baseApp.isAuthoring = false;
        expect(hoverSceneObject.allowHover()).toEqual(false);
        expect(hoverSceneObject.allowTryHover()).toEqual(false);
    });
});
//# sourceMappingURL=HoverAppObjectUC.test.js.map