add readableColor
This commit is contained in:
@@ -82,4 +82,31 @@ describe("Text", () => {
|
||||
expect(Text.display(undefined)).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("readableColor", () => {
|
||||
it("should return #FFF for dark backgrounds", () => {
|
||||
expect(Text.readableColor("#000")).toBe("#FFF");
|
||||
expect(Text.readableColor("#123456")).toBe("#FFF");
|
||||
});
|
||||
|
||||
it("should return #111 for light backgrounds", () => {
|
||||
expect(Text.readableColor("#FFF")).toBe("#111");
|
||||
expect(Text.readableColor("#f5f5f5")).toBe("#111");
|
||||
});
|
||||
|
||||
it("should use threshold at luminance 186", () => {
|
||||
expect(Text.readableColor("#BABABA")).toBe("#111");
|
||||
expect(Text.readableColor("#B9B9B9")).toBe("#FFF");
|
||||
});
|
||||
|
||||
it("should trim whitespace and accept mixed case hex", () => {
|
||||
expect(Text.readableColor(" #AbC ")).toBe("#FFF");
|
||||
});
|
||||
|
||||
it("should return #111 for invalid colors", () => {
|
||||
expect(Text.readableColor("red")).toBe("#111");
|
||||
expect(Text.readableColor("#12")).toBe("#111");
|
||||
expect(Text.readableColor("#GGGGGG")).toBe("#111");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user