"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const ThemeColors_1 = require("../../ThemeColors");
const MockAppHandlerEntity_1 = require("../Mocks/MockAppHandlerEntity");
const SetThemeColorUC_1 = require("./SetThemeColorUC");
function makeTestRig() {
    const appObjectRepo = (0, core_1.makeAppObjectRepo)();
    const handlerAO = appObjectRepo.getOrCreate("Handler");
    const mockAppHandler = new MockAppHandlerEntity_1.MockAppHandlerEntity(handlerAO);
    const themeColors = (0, ThemeColors_1.makeThemeColors)(handlerAO);
    const setTheme = (0, SetThemeColorUC_1.makeSetThemeColorUC)(handlerAO);
    return { mockAppHandler, setTheme, themeColors };
}
function makeBasicDTO() {
    return {
        colors: { primary: "primary", onPrimary: "onPrimary" },
    };
}
describe("Set Theme Colors base handler", () => {
    it("Registers as a handler when constructed", () => {
        const { mockAppHandler, setTheme } = makeTestRig();
        expect(mockAppHandler.registerRequestHandler).toHaveBeenCalledWith(setTheme);
    });
    it("Converts the payload into the DTO for the action", () => {
        const { setTheme } = makeTestRig();
        setTheme.action = jest.fn();
        const expectDTO = makeBasicDTO();
        const payload = {
            colors: { primary: "primary", onPrimary: "onPrimary" },
        };
        setTheme.handleRequest(1, payload);
        expect(setTheme.action).toHaveBeenCalledWith(expectDTO);
    });
    it("Throws for an unsupported version", () => {
        const { setTheme } = makeTestRig();
        const mockCallback = jest.fn();
        const payload = {
            assetID: "anAsset",
            callback: mockCallback,
        };
        expect(() => setTheme.handleRequest(-1, payload)).toThrowError();
    });
    it("Throws if the payload is bungled", () => {
        const { setTheme } = makeTestRig();
        setTheme.action = jest.fn();
        const payload = {
            foo: "bar",
        };
        expect(() => setTheme.handleRequest(1, payload)).toThrowError();
    });
    it("Sets the theme colors", () => {
        const { themeColors, setTheme } = makeTestRig();
        const type1 = ThemeColors_1.ThemeColorType.primary;
        const type2 = ThemeColors_1.ThemeColorType.secondary;
        const colors = {
            [type1]: "#ffffff",
            [type2]: "#000000",
        };
        setTheme.action({ colors });
        expect(themeColors.getColorForType(type1).hex).toEqual(colors[type1]);
        expect(themeColors.getColorForType(type2).hex).toEqual(colors[type2]);
    });
});
//# sourceMappingURL=SetThemeColorUC.test.js.map