Fix default theme fallback when an invalid theme is passed (#15)
* fix(color): invalid theme fallback to default Fixes: #4641 * test(color): add test case for invalid theme fallback to default * style(color): add back the tab space * test(color): fix color default theme * fix(color): use 'in' instead of '.hasOwnProperty' * fix new test * format code --------- Co-authored-by: mikyll <righi.michy@gmail.com>
This commit is contained in:
+2
-1
@@ -83,7 +83,8 @@ const getCardColors = ({
|
||||
theme,
|
||||
}) => {
|
||||
const defaultTheme = themes["default"];
|
||||
const isThemeProvided = theme !== null && theme !== undefined;
|
||||
const isThemeProvided =
|
||||
theme !== null && theme !== undefined && theme in themes;
|
||||
|
||||
// @ts-ignore
|
||||
const selectedTheme = isThemeProvided ? themes[theme] : defaultTheme;
|
||||
|
||||
@@ -73,4 +73,18 @@ describe("Test color.js", () => {
|
||||
borderColor: "#fff",
|
||||
});
|
||||
});
|
||||
|
||||
it("getCardColors: should fallback to default theme if theme is invalid", () => {
|
||||
let colors = getCardColors({
|
||||
theme: "invalidTheme",
|
||||
});
|
||||
expect(colors).toStrictEqual({
|
||||
titleColor: "#2f80ed",
|
||||
textColor: "#434d58",
|
||||
iconColor: "#4c71f2",
|
||||
ringColor: "#2f80ed",
|
||||
bgColor: "#fffefe",
|
||||
borderColor: "#e4e2e2",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user