"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const MockMouseInput_1 = require("../../MouseInput/Mocks/MockMouseInput");
const ZSpaceEntity_1 = require("../../zSpace/Entities/ZSpaceEntity");
const SelectAppObjectUCMock_1 = require("../Mocks/SelectAppObjectUCMock");
const MouseSelectAppObject_1 = require("./MouseSelectAppObject");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const zSpaceAO = appObjects.getOrCreate("zSpace");
    const zSpace = (0, ZSpaceEntity_1.makeZSpaceEntity)(zSpaceAO);
    zSpace.emulate = false;
    const selectionAO = appObjects.getOrCreate("selection");
    const mockUC = new SelectAppObjectUCMock_1.SelectAppObjectUCMock(selectionAO);
    const mockPixelToSceneUC = (0, Babylon_1.makeMockPixelToSceneRayUC)(appObjects);
    const mockPixelToRay = jest.fn().mockReturnValue(core_1.ParametricLine.Forward());
    mockPixelToSceneUC.pixelToSceneRay = mockPixelToRay;
    const mockMouseInput = new MockMouseInput_1.MockMouseInput(selectionAO);
    const controller = new MouseSelectAppObject_1.MouseSelectAppObject(selectionAO);
    const mockAllow = jest.fn();
    mockAllow.mockReturnValue(true);
    controller.allow = mockAllow;
    return {
        mockMouseInput,
        appObjects,
        zSpace,
        controller,
        mockUC,
        mockAllow,
    };
}
describe("Select Scene Object Mouse Controller", () => {
    it("Sends a ray to the UC on select", () => {
        const { mockUC, controller } = makeTestRig();
        const event = {
            button: 0,
            position: new core_1.Vector2(5, 6),
            event: new MouseEvent(""),
        };
        controller.onClick(event);
        expect(mockUC.trySelectAppObject).toHaveBeenCalledWith(core_1.ParametricLine.Forward());
    });
    it("Does not send a ray to the UC on click if not allowed", () => {
        const { controller, mockAllow, mockUC } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        mockAllow.mockReturnValue(false);
        controller.onClick(evt);
        expect(mockUC.trySelectAppObject).not.toHaveBeenCalled();
    });
    it("Warns if it is added to an app object that does not have a UC", () => {
        const { appObjects } = makeTestRig();
        const anotherAppObj = appObjects.getOrCreate("newAppObj");
        console.warn = jest.fn();
        new MouseSelectAppObject_1.MouseSelectAppObject(anotherAppObj);
        expect(console.warn).toHaveBeenCalled();
    });
    it("Does not register itself if the object does not have a UC", () => {
        const { appObjects, mockMouseInput } = makeTestRig();
        const anotherAppObj = appObjects.getOrCreate("newAppObj");
        console.warn = jest.fn();
        mockMouseInput.registerController.mockClear();
        new MouseSelectAppObject_1.MouseSelectAppObject(anotherAppObj);
        expect(mockMouseInput.registerController).not.toHaveBeenCalled();
    });
    it("Does not send a ray to the UC if zSpace mouse emulate is on", () => {
        const { mockUC, controller, zSpace } = makeTestRig();
        zSpace.emulate = true;
        const event = {
            button: 0,
            position: new core_1.Vector2(5, 6),
            event: new MouseEvent(""),
        };
        controller.onClick(event);
        expect(mockUC.trySelectAppObject).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=MouseSelectAppObject.test.js.map