adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { test, describe, assert } from "vitest";
|
|
import { normalize_color, format_color, hsva_to_rgba } from "./utils";
|
|
|
|
describe("normalize_color", () => {
|
|
test("converts named CSS color to hex", () => {
|
|
assert.equal(normalize_color("red"), "#ff0000");
|
|
});
|
|
|
|
test("expands 3-digit hex to 6-digit", () => {
|
|
assert.equal(normalize_color("#f00"), "#ff0000");
|
|
});
|
|
|
|
test("passes through already-normalized 6-digit hex", () => {
|
|
assert.equal(normalize_color("#ff0000"), "#ff0000");
|
|
});
|
|
|
|
test("converts 8-digit hex with alpha to 6-digit hex (alpha stripped by toHexString)", () => {
|
|
assert.equal(normalize_color("#ff000080"), "#ff0000");
|
|
});
|
|
|
|
test("lowercases uppercase hex", () => {
|
|
assert.equal(normalize_color("#FF0000"), "#ff0000");
|
|
});
|
|
|
|
test("converts rgb() string to hex", () => {
|
|
assert.equal(normalize_color("rgb(255, 0, 0)"), "#ff0000");
|
|
});
|
|
|
|
test("converts hsl() string to hex", () => {
|
|
assert.equal(normalize_color("hsl(0, 100%, 50%)"), "#ff0000");
|
|
});
|
|
|
|
test("returns invalid color string unchanged", () => {
|
|
assert.equal(normalize_color("notacolor"), "notacolor");
|
|
});
|
|
|
|
test("returns empty string unchanged", () => {
|
|
assert.equal(normalize_color(""), "");
|
|
});
|
|
});
|
|
|
|
describe("format_color", () => {
|
|
test("formats color as hex", () => {
|
|
assert.equal(format_color("red", "hex"), "#ff0000");
|
|
});
|
|
|
|
test("formats color as rgb", () => {
|
|
assert.equal(format_color("#ff0000", "rgb"), "rgb(255, 0, 0)");
|
|
});
|
|
|
|
test("formats color as hsl", () => {
|
|
assert.equal(format_color("#ff0000", "hsl"), "hsl(0, 100%, 50%)");
|
|
});
|
|
});
|
|
|
|
describe("hsva_to_rgba", () => {
|
|
test("converts pure red", () => {
|
|
assert.equal(hsva_to_rgba({ h: 0, s: 1, v: 1, a: 1 }), "#ff0000");
|
|
});
|
|
|
|
test("converts with alpha (toHexString strips alpha)", () => {
|
|
assert.equal(hsva_to_rgba({ h: 0, s: 1, v: 1, a: 0.5 }), "#ff0000");
|
|
});
|
|
|
|
test("converts black", () => {
|
|
assert.equal(hsva_to_rgba({ h: 0, s: 0, v: 0, a: 1 }), "#000000");
|
|
});
|
|
|
|
test("converts white", () => {
|
|
assert.equal(hsva_to_rgba({ h: 0, s: 0, v: 1, a: 1 }), "#ffffff");
|
|
});
|
|
|
|
test("converts green (h=120)", () => {
|
|
assert.equal(hsva_to_rgba({ h: 120, s: 1, v: 1, a: 1 }), "#00ff00");
|
|
});
|
|
|
|
test("converts blue (h=240)", () => {
|
|
assert.equal(hsva_to_rgba({ h: 240, s: 1, v: 1, a: 1 }), "#0000ff");
|
|
});
|
|
});
|