Add theme tests

This commit is contained in:
Andrew Kingston 2024-10-24 10:22:43 +01:00
parent 249f44dc11
commit 889b216a93
No known key found for this signature in database
2 changed files with 29 additions and 1 deletions

View File

@ -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)
})
})

View File

@ -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) {