"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockAppHandlerEntity_1 = require("../Mocks/MockAppHandlerEntity");
const StartAppUC_1 = require("./StartAppUC");
const MockAppRenderingUC_1 = require("../../BaseApp/Mocks/MockAppRenderingUC");
function makeTestRig() {
    const appObjectRepo = (0, core_1.makeAppObjectRepo)();
    const handlerAO = appObjectRepo.getOrCreate("Handler");
    const mockAppHandler = new MockAppHandlerEntity_1.MockAppHandlerEntity(handlerAO);
    const mockRenderingUC = new MockAppRenderingUC_1.MockAppRenderingUC(handlerAO);
    const startApp = (0, StartAppUC_1.makeStartAppUC)(handlerAO);
    const div = document.createElement("div");
    return { mockAppHandler, startApp, div, mockRenderingUC };
}
describe("Start App Base Handler", () => {
    it("Registers as a handler when constructed", () => {
        const { startApp, mockAppHandler } = makeTestRig();
        expect(mockAppHandler.registerRequestHandler).toHaveBeenCalledWith(startApp);
    });
    it("Triggers the action for v2 of the payload", () => {
        const { startApp, div } = makeTestRig();
        startApp.action = jest.fn();
        startApp.handleRequest(2, { container: div });
        expect(startApp.action).toHaveBeenCalledWith(div);
    });
    it("Throws for an bungled payload", () => {
        const { startApp } = makeTestRig();
        expect(() => startApp.handleRequest(1, { foo: "bar" })).toThrowError();
    });
    it("Throws for an unsupported version", () => {
        const { startApp, div } = makeTestRig();
        expect(() => startApp.handleRequest(-1, { container: div })).toThrowError();
    });
    it("Does not support version 1", () => {
        const { startApp, div } = makeTestRig();
        expect(() => startApp.handleRequest(1, { container: div })).toThrowError();
    });
    it("Calls start rendering", () => {
        const { mockRenderingUC, startApp } = makeTestRig();
        const div = document.createElement("div");
        startApp.action(div);
        expect(mockRenderingUC.startRendering).toHaveBeenCalledWith(div);
    });
});
//# sourceMappingURL=StartAppUC.test.js.map