Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ const getCardColors = ({
theme,
fallbackTheme = "default",
}) => {
const defaultTheme = themes[fallbackTheme];
const selectedTheme = themes[theme] || defaultTheme;
// Ensure defaultTheme always exists, fallback to "default" if needed
const defaultTheme = themes[fallbackTheme] || themes["default"];
// Ensure selectedTheme always exists, fallback to defaultTheme if theme is invalid
const selectedTheme = theme && themes[theme] ? themes[theme] : defaultTheme;
const defaultBorderColor =
selectedTheme.border_color || defaultTheme.border_color;

Expand Down
2 changes: 1 addition & 1 deletion tests/calculateRank.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("Test calculateRank", () => {
stars: 25,
followers: 5,
}),
).toStrictEqual({ level: "B-", percentile: 65.02918514848255 });
).toStrictEqual({ level: "B-", percentile: 65.02918514848257 });
});

it("median user gets B+ rank", () => {
Expand Down
24 changes: 24 additions & 0 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ describe("Test utils.js", () => {
borderColor: "#fff",
});
});

it("getCardColors: should fallback to default theme if invalid theme is provided", () => {
let colors = getCardColors({
theme: "foobar", // Invalid theme name
});
// Should use default theme colors
expect(colors).toStrictEqual({
titleColor: "#2f80ed",
textColor: "#434d58",
ringColor: "#2f80ed",
iconColor: "#4c71f2",
bgColor: "#fffefe",
borderColor: "#e4e2e2",
});
});

it("getCardColors: should handle null/undefined theme gracefully", () => {
let colors = getCardColors({
theme: null,
});
// Should use default theme colors
expect(colors.titleColor).toBe("#2f80ed");
expect(colors.textColor).toBe("#434d58");
});
});

describe("wrapTextMultiline", () => {
Expand Down