Files
t3code/apps/web/src/appearanceContrast.test.ts
T
t3-code[bot]andmaria 6e9c57f7ba feat(web): add appearance contrast control (#7906)
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: maria <[email protected]>
2026-08-22 18:00:21 -04:00

54 lines
1.9 KiB
TypeScript

import { describe, expect, it, vi } from "vite-plus/test";
import { applyAppearanceContrast } from "./appearanceContrast";
function makeRoot() {
const setProperty = vi.fn();
return {
root: { style: { setProperty } } as unknown as HTMLElement,
setProperty,
};
}
describe("applyAppearanceContrast", () => {
it("boosts semantic contrast above the default", () => {
const { root, setProperty } = makeRoot();
applyAppearanceContrast(root, 135);
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-base", "100%");
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-boost", "35%");
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-border-boost", "8.75%");
});
it("supports the maximum contrast boost", () => {
const { root, setProperty } = makeRoot();
applyAppearanceContrast(root, 200);
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-base", "100%");
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-boost", "100%");
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-border-boost", "25%");
});
it("softens semantic contrast below the default", () => {
const { root, setProperty } = makeRoot();
applyAppearanceContrast(root, 70);
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-base", "70%");
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-boost", "0%");
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-border-boost", "0%");
});
it("disables contrast mixing at the default", () => {
const { root, setProperty } = makeRoot();
applyAppearanceContrast(root, 100);
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-base", "100%");
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-boost", "0%");
expect(setProperty).toHaveBeenCalledWith("--appearance-contrast-border-boost", "0%");
});
});