"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockAppHandlerEntity_1 = require("../Mocks/MockAppHandlerEntity");
const StartZSpaceUC_1 = require("./StartZSpaceUC");
const MockCheckZSpaceDisplaySizeUC_1 = require("../../zSpace/Mocks/MockCheckZSpaceDisplaySizeUC");
const zSpace_1 = require("../../zSpace");
const MockRenderToXR_1 = require("../../XR/Mocks/MockRenderToXR");
const MockXRSession_1 = require("../../XR/Mocks/MockXRSession");
const Stylus_1 = require("../../Stylus");
function makeTestRig() {
    const appObjectRepo = (0, core_1.makeAppObjectRepo)();
    const appObj = appObjectRepo.getOrCreate("Handler");
    const mockAppHandler = new MockAppHandlerEntity_1.MockAppHandlerEntity(appObj);
    const zSpaceEntity = (0, zSpace_1.makeZSpaceEntity)(appObj);
    const mockRenderUC = new MockRenderToXR_1.MockRenderToXR(appObj);
    const mockCheckZSpaceDisplaySize = new MockCheckZSpaceDisplaySizeUC_1.MockCheckZSpaceDisplaySizeUC(appObj);
    const mockEmulate = (0, Stylus_1.makeMockEmulateStylusUC)(appObjectRepo);
    const startZSpace = (0, StartZSpaceUC_1.makeStartZSpaceUC)(appObj);
    return {
        mockAppHandler,
        startZSpace,
        mockCheckZSpaceDisplaySize,
        zSpaceEntity,
        mockRenderUC,
        mockEmulate,
    };
}
describe("Set is authoring Base Handler", () => {
    it("Registers as a handler when constructed", () => {
        const { mockAppHandler, startZSpace } = makeTestRig();
        expect(mockAppHandler.registerRequestHandler).toHaveBeenCalledWith(startZSpace);
    });
    it("Triggers the action for v3", () => {
        const { startZSpace } = makeTestRig();
        startZSpace.action = jest.fn();
        startZSpace.handleRequest(3, {
            session: { foo: "bar" },
            emulate: true,
        });
        expect(startZSpace.action).toHaveBeenCalledWith({ foo: "bar" }, true);
    });
    it("Throws for an bungled payload", () => {
        const { startZSpace } = makeTestRig();
        expect(() => startZSpace.handleRequest(3, { foo: "bar" })).toThrowError();
    });
    it("Throws for an unsupported version", () => {
        const { startZSpace } = makeTestRig();
        expect(() => startZSpace.handleRequest(-1, {
            session: { foo: "bar" },
        })).toThrowError();
    });
    it("Warns if it cannot parse the xr session", () => {
        const { startZSpace } = makeTestRig();
        startZSpace.warn = jest.fn();
        startZSpace.action(null, false);
        expect(startZSpace.warn).toHaveBeenCalled();
    });
    it("Warns if it can't find the zSpace entity session", () => {
        const { startZSpace, zSpaceEntity } = makeTestRig();
        startZSpace.warn = jest.fn();
        zSpaceEntity.dispose();
        console.warn = jest.fn();
        startZSpace.action(new MockXRSession_1.MockXRSession(), false);
        expect(startZSpace.warn).toHaveBeenCalled();
    });
    it("Sets the zSpace Device to Inspire by default", () => {
        const { startZSpace, zSpaceEntity } = makeTestRig();
        const spy = jest.spyOn(zSpaceEntity.display, "setForDevice");
        startZSpace.action(new MockXRSession_1.MockXRSession(), false);
        expect(spy).toHaveBeenCalledWith(zSpace_1.ZSpaceDevice.INSPIRE);
    });
    it("Starts the rendering", () => {
        const { startZSpace, mockRenderUC } = makeTestRig();
        startZSpace.action(new MockXRSession_1.MockXRSession(), false);
        expect(mockRenderUC.startRenderingXR).toHaveBeenCalled();
    });
    it("Set enabled to true", () => {
        const { startZSpace, zSpaceEntity } = makeTestRig();
        const spy = jest.spyOn(zSpaceEntity, "enabled", "set");
        startZSpace.action(new MockXRSession_1.MockXRSession(), false);
        expect(spy).toHaveBeenCalledWith(true);
    });
    it("Sets emulation to true if is passed in", () => {
        const { startZSpace, zSpaceEntity } = makeTestRig();
        expect(zSpaceEntity.emulate).toEqual(false);
        startZSpace.action({}, true);
        expect(zSpaceEntity.emulate).toEqual(true);
    });
    it("Checks the zspace display size if not emulating", () => {
        const { startZSpace, mockCheckZSpaceDisplaySize } = makeTestRig();
        const mockSession = new MockXRSession_1.MockXRSession();
        startZSpace.action(mockSession, false);
        expect(mockCheckZSpaceDisplaySize.checkDisplayFromXRSession).toHaveBeenCalledWith(mockSession);
    });
    it("Does not check the zspace display size if emulating", () => {
        const { startZSpace, mockCheckZSpaceDisplaySize } = makeTestRig();
        startZSpace.action(new MockXRSession_1.MockXRSession(), true);
        expect(mockCheckZSpaceDisplaySize.checkDisplayFromXRSession).not.toHaveBeenCalled();
    });
    it("Kicks off the stylus emulator", () => {
        const { startZSpace, mockEmulate } = makeTestRig();
        startZSpace.action(new MockXRSession_1.MockXRSession(), true);
        expect(mockEmulate.startEmulating).toHaveBeenCalled();
    });
});
//# sourceMappingURL=StartZSpaceUC.test.js.map