"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const react_hooks_1 = require("@testing-library/react-hooks"); const core_plugin_api_1 = require("@backstage/core-plugin-api"); const useBrandingThemeColors_1 = require("./useBrandingThemeColors"); jest.mock("@backstage/core-plugin-api", () => (Object.assign(Object.assign({}, jest.requireActual("@backstage/core-plugin-api")), { useApi: jest.fn() }))); describe("useBrandingThemeColors", () => { it("returns the themeColors when config for them is available", () => { core_plugin_api_1.useApi.mockReturnValue({ getOptionalString: jest.fn().mockImplementation((key) => { switch (key) { case "app.branding.theme.someTheme.primaryColor": return "blue"; case "app.branding.theme.someTheme.headerColor1": return "red"; case "app.branding.theme.someTheme.headerColor2": return "yellow"; case "app.branding.theme.someTheme.navigationIndicatorColor": return "purple"; default: return ""; } }), }); const { result } = (0, react_hooks_1.renderHook)(() => (0, useBrandingThemeColors_1.useBrandingThemeColors)("someTheme")); expect(result.current.primaryColor).toBe("blue"); expect(result.current.headerColor1).toBe("red"); expect(result.current.headerColor2).toBe("yellow"); expect(result.current.navigationIndicatorColor).toBe("purple"); }); it("returns undefined when config is unavailable", () => { // Mock the useApi function to throw an error (simulate unavailable config) core_plugin_api_1.useApi.mockImplementation(jest.fn(() => { throw new Error("Custom hook error"); })); const { result } = (0, react_hooks_1.renderHook)(() => (0, useBrandingThemeColors_1.useBrandingThemeColors)("someTheme")); expect(result.current.primaryColor).toBeUndefined(); }); });