import { makeAppObjectRepo } from "@vived/core";
import { makeThemeColors, ThemeColorType } from "../../ThemeColors";
import { MockAppHandlerEntity } from "../Mocks/MockAppHandlerEntity";
import { makeSetThemeColorUC } from "./SetThemeColorUC";
function makeTestRig() {
    const appObjectRepo = makeAppObjectRepo();
    const handlerAO = appObjectRepo.getOrCreate("Handler");
    const mockAppHandler = new MockAppHandlerEntity(handlerAO);
    const themeColors = makeThemeColors(handlerAO);
    const setTheme = 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 = ThemeColorType.primary;
        const type2 = 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