Fix custom theme support for short hex & rgba hex strings (#29726)
* Fix custom theme support for hex colours other than 6-char Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
779543fa0f
commit
1430fd5af6
@@ -135,6 +135,54 @@ describe("theme", () => {
|
||||
expect(spy.mock.calls[0][0].textContent).toMatchSnapshot();
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it("should handle 4-char rgba hex strings", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue([
|
||||
{
|
||||
name: "blue",
|
||||
colors: {
|
||||
"sidebar-color": "#abcd",
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const spy = jest.fn();
|
||||
jest.spyOn(document.body, "style", "get").mockReturnValue({
|
||||
setProperty: spy,
|
||||
} as any);
|
||||
await new Promise((resolve) => {
|
||||
setTheme("custom-blue").then(resolve);
|
||||
lightCustomTheme.onload!({} as Event);
|
||||
});
|
||||
expect(spy).toHaveBeenCalledWith("--sidebar-color", "#abcd");
|
||||
expect(spy).toHaveBeenCalledWith("--sidebar-color-0pct", "#aabbcc00");
|
||||
expect(spy).toHaveBeenCalledWith("--sidebar-color-15pct", "#aabbcc21");
|
||||
expect(spy).toHaveBeenCalledWith("--sidebar-color-50pct", "#aabbcc6f");
|
||||
});
|
||||
|
||||
it("should handle 6-char rgb hex strings", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue([
|
||||
{
|
||||
name: "blue",
|
||||
colors: {
|
||||
"sidebar-color": "#abcdef",
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const spy = jest.fn();
|
||||
jest.spyOn(document.body, "style", "get").mockReturnValue({
|
||||
setProperty: spy,
|
||||
} as any);
|
||||
await new Promise((resolve) => {
|
||||
setTheme("custom-blue").then(resolve);
|
||||
lightCustomTheme.onload!({} as Event);
|
||||
});
|
||||
expect(spy).toHaveBeenCalledWith("--sidebar-color", "#abcdef");
|
||||
expect(spy).toHaveBeenCalledWith("--sidebar-color-0pct", "#abcdef00");
|
||||
expect(spy).toHaveBeenCalledWith("--sidebar-color-15pct", "#abcdef26");
|
||||
expect(spy).toHaveBeenCalledWith("--sidebar-color-50pct", "#abcdef80");
|
||||
});
|
||||
});
|
||||
|
||||
describe("enumerateThemes", () => {
|
||||
|
||||
Reference in New Issue
Block a user