diff --git a/packages/shared-core/src/tests/themes.ts b/packages/shared-core/src/tests/themes.ts new file mode 100644 index 0000000000..89c6910ad5 --- /dev/null +++ b/packages/shared-core/src/tests/themes.ts @@ -0,0 +1,28 @@ +import { getThemeClassNames, ensureValidTheme } from "../themes" +import { Theme } from "@budibase/types" + +describe("theme class names", () => { + it("generates class names for a theme without base theme", () => { + expect(getThemeClassNames(Theme.LIGHT)).toStrictEqual("spectrum--light") + }) + it("generates class names for a theme with base theme", () => { + expect(getThemeClassNames(Theme.NORD)).toStrictEqual( + "spectrum--darkest spectrum--nord" + ) + }) +}) + +describe("theme validity checking", () => { + it("handles no theme", () => { + expect(ensureValidTheme(undefined)).toStrictEqual(Theme.DARKEST) + }) + it("allows specifiying a fallback", () => { + expect(ensureValidTheme(undefined, Theme.NORD)).toStrictEqual(Theme.NORD) + }) + it("migrates lightest to light", () => { + expect(ensureValidTheme(Theme.LIGHTEST)).toStrictEqual(Theme.LIGHT) + }) + it("migrates dark to darkest", () => { + expect(ensureValidTheme(Theme.DARK)).toStrictEqual(Theme.DARKEST) + }) +}) diff --git a/packages/shared-core/src/themes.ts b/packages/shared-core/src/themes.ts index 1d1875d4e9..d70f188426 100644 --- a/packages/shared-core/src/themes.ts +++ b/packages/shared-core/src/themes.ts @@ -17,7 +17,7 @@ export const getThemeClassNames = (theme: Theme): string => { // Ensures a theme value is a valid option export const ensureValidTheme = ( - theme: Theme, + theme?: Theme, fallback: Theme = Theme.DARKEST ): Theme => { if (!theme) {