"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const BaseApp_1 = require("../../BaseApp");
const Selectable_1 = require("../Entities/Selectable");
const Selection_1 = require("../Entities/Selection");
const HoverAppObjectUC_1 = require("./HoverAppObjectUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const baseAppObj = appObjects.getOrCreate("baseAppObj");
    const selection = (0, Selection_1.makeSelection)(baseAppObj);
    const selectabelAppObj = appObjects.getOrCreate("selectableAppObj");
    const selectable = (0, Selectable_1.makeSelectable)(selectabelAppObj);
    selection.addSelectable(selectable);
    const mockRayPick = (0, Babylon_1.makeMockSceneRayPickUC)(appObjects);
    const mockPick = jest.fn().mockReturnValue({ appObjectID: "hideableObj" });
    mockRayPick.sceneRayPick = mockPick;
    const baseApp = (0, BaseApp_1.makeBaseAppState)(appObjects.getOrCreate("BaseApp"));
    baseApp.isAuthoring = true;
    const hoverSceneObject = (0, HoverAppObjectUC_1.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(core_1.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(core_1.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(core_1.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(core_1.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_1.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