"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 PressAppObjectUC_1 = require("./PressAppObjectUC");
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 pressSceneObject = (0, PressAppObjectUC_1.makePressAppObject)(baseAppObj);
    return {
        appObjects,
        pressSceneObject,
        selectable,
        selection,
        mockPick,
        registerSpy,
        baseApp,
    };
}
describe("Press Scene Object UC", () => {
    it("Presses by ID", () => {
        const { pressSceneObject, selection } = makeTestRig();
        expect(selection.pressedObjectId).toEqual(null);
        pressSceneObject.pressAppObject("selectableAppObj", true);
        expect(selection.pressedObjectId).toEqual("selectableAppObj");
    });
    it("Un-Presses by ID", () => {
        const { pressSceneObject, selection } = makeTestRig();
        pressSceneObject.pressAppObject("selectableAppObj", true);
        expect(selection.pressedObjectId).toEqual("selectableAppObj");
        pressSceneObject.pressAppObject("selectableAppObj", false);
        expect(selection.pressedObjectId).toEqual(null);
    });
    it("Only un-presses if the id is currently pressed", () => {
        const { pressSceneObject, selection } = makeTestRig();
        pressSceneObject.pressAppObject("selectableAppObj", true);
        pressSceneObject.pressAppObject("some other id", false);
        expect(selection.pressedObjectId).toEqual("selectableAppObj");
    });
    it("Sets the pressed object ID if it pick on it", () => {
        const { pressSceneObject, selection, mockPick } = makeTestRig();
        mockPick.mockReturnValue({ appObjectID: "selectableAppObj" });
        expect(selection.pressedObjectId).toEqual(null);
        pressSceneObject.tryPressAppObject(core_1.ParametricLine.Forward()); // Ray doesn't matter since we hijack the pick
        expect(selection.pressedObjectId).toEqual("selectableAppObj");
    });
    it("Sets the pressed to null if the pick doesn't hit anything", () => {
        const { pressSceneObject, selection, mockPick } = makeTestRig();
        mockPick.mockReturnValue({});
        pressSceneObject.pressAppObject("selectableAppObj", true);
        pressSceneObject.tryPressAppObject(core_1.ParametricLine.Forward()); // Ray doesn't matter since we hijack the pick
        expect(selection.pressedObjectId).toEqual(null);
    });
    it("Sets the pressed to null if the pick doesn't an app object", () => {
        const { pressSceneObject, selection, mockPick } = makeTestRig();
        mockPick.mockReturnValue({ appObjectID: "something weired" });
        pressSceneObject.pressAppObject("selectableAppObj", true);
        pressSceneObject.tryPressAppObject(core_1.ParametricLine.Forward()); // Ray doesn't matter since we hijack the pick
        expect(selection.pressedObjectId).toEqual(null);
    });
    it("Sets the pressed to null if the pick doesn't a selectable object", () => {
        const { pressSceneObject, selection, mockPick, appObjects } = makeTestRig();
        appObjects.getOrCreate("unselectableAppObject");
        mockPick.mockReturnValue({ appObjectID: "unselectableAppObject" });
        pressSceneObject.pressAppObject("selectableAppObj", true);
        pressSceneObject.tryPressAppObject(core_1.ParametricLine.Forward()); // Ray doesn't matter since we hijack the pick
        expect(selection.pressedObjectId).toEqual(null);
    });
    it("Gets the singleton", () => {
        const { pressSceneObject, appObjects } = makeTestRig();
        expect(PressAppObjectUC_1.PressAppObjectUC.get(appObjects)).toEqual(pressSceneObject);
    });
    it("Registers as the singleton", () => {
        const { pressSceneObject, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(pressSceneObject);
    });
    it("Allows while authoring", () => {
        const { pressSceneObject, baseApp } = makeTestRig();
        baseApp.isAuthoring = true;
        expect(pressSceneObject.allowPress()).toEqual(true);
        expect(pressSceneObject.allowTryPress()).toEqual(true);
        baseApp.isAuthoring = false;
        expect(pressSceneObject.allowPress()).toEqual(false);
        expect(pressSceneObject.allowTryPress()).toEqual(false);
    });
});
//# sourceMappingURL=PressAppObjectUC.test.js.map