fix: enforce public contrast and audit rank errors

This commit is contained in:
Simo committed 2026-07-11 22:06:45 +02:00
1 parent e1381c0f40
commit b695a33ead
12 files changed
+184 -29

No files matched your search

+25 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { contrastRatio, readableColor } from "@/lib/theme-contrast";
import { contrastRatio, derivePublicForegrounds, readableColor } from "@/lib/theme-contrast";
import { PRESETS } from "@/lib/theme-presets";
describe("contrastRatio", () => {
@@ -64,3 +64,27 @@ describe("readableColor", () => {
expect(readableColor("rgb(1, 2, 3)", ["#ffffff"], 4.5)).toBe("rgb(1, 2, 3)");
});
});
describe("derivePublicForegrounds", () => {
it.each(Object.entries(PRESETS))("makes every semantic pair readable for %s", (_name, preset) => {
const result = derivePublicForegrounds(preset);
for (const pair of result.pairs) {
expect(contrastRatio(pair.foreground, pair.background), pair.name).toBeGreaterThanOrEqual(4.5);
}
});
it("repairs hostile white-on-white custom colors", () => {
const result = derivePublicForegrounds({
color_background: "#ffffff", color_surface: "#ffffff", color_dropdown: "#ffffff",
color_navbar: "#ffffff", color_navbar_text: "#ffffff", color_text: "#ffffff",
color_text_muted: "#ffffff", color_primary: "#ffffff", color_accent: "#ffffff",
button_primary_color: "#ffffff", button_text_color: "#ffffff",
button_secondary_color: "#ffffff", button_secondary_text_color: "#ffffff",
button_danger_color: "#ffffff", button_danger_text_color: "#ffffff",
button_outline_color: "#ffffff", button_outline_text_color: "#ffffff",
link_color: "#ffffff", link_hover_color: "#ffffff",
});
expect(result.pairs.length).toBeGreaterThan(10);
for (const pair of result.pairs) expect(contrastRatio(pair.foreground, pair.background), pair.name).toBeGreaterThanOrEqual(4.5);
});
});