"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockDispatcher_1 = require("../Mocks/MockDispatcher");
const RegisterExternalStylesheetsUC_1 = require("./RegisterExternalStylesheetsUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const dispatcherAO = appObjects.getOrCreate("dispatcher");
    const mockDispatcher = new MockDispatcher_1.MockDispatcher(dispatcherAO);
    const uc = (0, RegisterExternalStylesheetsUC_1.makeRegisterExternalStylesheetsUC)(dispatcherAO);
    return {
        uc,
        mockDispatcher,
        appObjects,
    };
}
describe("Registers external stylesheets", () => {
    it("Gets the UC", () => {
        const { uc, appObjects } = makeTestRig();
        expect(RegisterExternalStylesheetsUC_1.RegisterExternalStylesheetsUC.get(appObjects)).toEqual(uc);
    });
    it("Finds and dispatches to the UC", () => {
        const { appObjects, uc } = makeTestRig();
        uc.doDispatch = jest.fn();
        (0, RegisterExternalStylesheetsUC_1.registerExternalStylesheets)(["stylesheet"], appObjects);
        expect(uc.doDispatch).toHaveBeenCalledWith(["stylesheet"]);
    });
    it("Dispatches the correct type", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch(["stylesheet"]);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][0]).toEqual("REGISTER_EXTERNAL_STYLESHEETS");
    });
    it("Dispatches the correct version", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch(["stylesheet"]);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        expect(mockDispatcher.formRequestAndDispatch.mock.calls[0][1]).toEqual(1);
    });
    it("Dispatches the stylesheets in the payload", () => {
        const { uc, mockDispatcher } = makeTestRig();
        uc.doDispatch(["stylesheet"]);
        expect(mockDispatcher.formRequestAndDispatch).toHaveBeenCalledTimes(1);
        const payload = mockDispatcher.formRequestAndDispatch.mock.calls[0][2];
        expect(payload).toEqual({ stylesheets: ["stylesheet"] });
    });
});
//# sourceMappingURL=RegisterExternalStylesheetsUC.test.js.map