feat: establish shared color state and area interaction foundation
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { describe, it, expect, afterEach } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent } from "vue";
|
||||
import {
|
||||
ColorAreaRoot,
|
||||
ColorAreaArea,
|
||||
ColorAreaThumb,
|
||||
parseColor,
|
||||
getChannelRange,
|
||||
getChannelValue,
|
||||
getAreaBackgroundStyle,
|
||||
} from "../packages/vue/tests/fixtures/color-probe";
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
});
|
||||
function area() {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { ColorAreaRoot, ColorAreaArea, ColorAreaThumb },
|
||||
template:
|
||||
'<ColorAreaRoot model-value="hsb(240, 50%, 50%)" color-space="hsb" x-channel="saturation" y-channel="brightness"><ColorAreaArea><ColorAreaThumb/></ColorAreaArea></ColorAreaRoot>',
|
||||
}),
|
||||
);
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
describe("Reka 2.11 installed color capability audit (not public acceptance)", () => {
|
||||
it("emits hex and leaves a rejected channel at its optimistic thumb position", async () => {
|
||||
const w = area();
|
||||
await w.get('[role="slider"]').trigger("keydown", { key: "ArrowRight" });
|
||||
await flushPromises();
|
||||
expect(
|
||||
w.getComponent(ColorAreaRoot).emitted("update:modelValue")?.[0]?.[0],
|
||||
).toMatch(/^#/);
|
||||
expect(w.get('[role="slider"]').attributes("aria-valuenow")).toBe("51");
|
||||
});
|
||||
it("does not emit keyboard changeEnd after releasing an arrow", async () => {
|
||||
const w = area();
|
||||
await w.get('[role="slider"]').trigger("keydown", { key: "ArrowRight" });
|
||||
await w.get('[role="slider"]').trigger("keyup", { key: "ArrowRight" });
|
||||
expect(w.getComponent(ColorAreaRoot).emitted("changeEnd")).toBeUndefined();
|
||||
});
|
||||
it("uses percent alpha channel metadata while color storage uses a fraction", () => {
|
||||
expect(getChannelRange("alpha").max).toBe(100);
|
||||
expect(parseColor("#ff000080").alpha).toBeCloseTo(128 / 255);
|
||||
});
|
||||
it("loses achromatic HSB hue through the generic hue getter", () => {
|
||||
expect(getChannelValue(parseColor("hsb(240, 0%, 50%)"), "hue")).toBe(0);
|
||||
});
|
||||
it("accepts functional trailing junk and out-of-range values without normalization", () => {
|
||||
expect(parseColor("rgb(999, 0, 0) trailing")).toMatchObject({ r: 999 });
|
||||
});
|
||||
it("does not parse the four-digit alpha shorthand", () => {
|
||||
expect(() => parseColor("#f008")).toThrow();
|
||||
});
|
||||
it("falls back to no hue layer when hue is the y axis", () => {
|
||||
const style = getAreaBackgroundStyle(
|
||||
parseColor("hsb(240, 50%, 50%)"),
|
||||
"saturation",
|
||||
"hue",
|
||||
"hsb",
|
||||
);
|
||||
expect(style.backgroundImage).not.toContain("#ff0000, #ffff00");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user