555 lines
22 KiB
TypeScript
555 lines
22 KiB
TypeScript
import { afterEach, describe, it, expect, vi } from "vitest";
|
|
import { mount, flushPromises } from "@vue/test-utils";
|
|
import { defineComponent, shallowRef } from "vue";
|
|
import Area from "../packages/vue/tests/fixtures/ColorAreaFoundation.vue";
|
|
import Picker from "../packages/vue/tests/fixtures/ColorPickerFoundation.vue";
|
|
import {
|
|
Color,
|
|
parseColor,
|
|
colorAxes,
|
|
copyColor,
|
|
} from "../packages/vue/src/components/color/value";
|
|
import { colorAreaBackground } from "../packages/vue/src/components/color/gradient";
|
|
const wrappers: ReturnType<typeof mount>[] = [];
|
|
afterEach(() => {
|
|
wrappers.splice(0).forEach((w) => w.unmount());
|
|
document.body.innerHTML = "";
|
|
vi.restoreAllMocks();
|
|
});
|
|
function fixture(attrs = "", setup = () => ({}), children = "") {
|
|
const w = mount(
|
|
defineComponent({
|
|
components: { Area, Picker },
|
|
setup,
|
|
template: `<form><Picker name="color" ${attrs}>${children}</Picker></form>`,
|
|
}),
|
|
{ attachTo: document.body },
|
|
);
|
|
wrappers.push(w);
|
|
return w;
|
|
}
|
|
const events = (w: ReturnType<typeof mount>) =>
|
|
(w.getComponent(Picker).emitted("change") ?? []).map(
|
|
([v]) => v as Color | null,
|
|
);
|
|
const ends = (w: ReturnType<typeof mount>) =>
|
|
w.getComponent(Picker).emitted("changeEnd") ?? [];
|
|
const x = (w: ReturnType<typeof mount>) =>
|
|
w.get<HTMLInputElement>('[data-axis="x"]');
|
|
const y = (w: ReturnType<typeof mount>) =>
|
|
w.get<HTMLInputElement>('[data-axis="y"]');
|
|
async function key(
|
|
w: ReturnType<typeof mount>,
|
|
key: string,
|
|
up = true,
|
|
extra = {},
|
|
axis = "x",
|
|
) {
|
|
const input = w.get(`[data-axis="${axis}"]`);
|
|
await input.trigger("keydown", { key, ...extra });
|
|
if (up) await input.trigger("keyup", { key, ...extra });
|
|
await flushPromises();
|
|
}
|
|
const data = (w: ReturnType<typeof mount>) =>
|
|
new FormData(w.get("form").element as HTMLFormElement).getAll("color");
|
|
function geometry(w: ReturnType<typeof mount>, selector = "[data-color-area]") {
|
|
const node = w.get<HTMLElement>(selector).element;
|
|
let captured: number | undefined;
|
|
Object.defineProperties(node, {
|
|
offsetWidth: { get: () => 224, configurable: true },
|
|
offsetHeight: { get: () => 224, configurable: true },
|
|
});
|
|
vi.spyOn(node, "getBoundingClientRect").mockReturnValue({
|
|
left: 0,
|
|
top: 0,
|
|
width: 224,
|
|
height: 224,
|
|
right: 224,
|
|
bottom: 224,
|
|
x: 0,
|
|
y: 0,
|
|
toJSON: () => ({}),
|
|
});
|
|
node.setPointerCapture = vi.fn((id) => {
|
|
captured = id;
|
|
});
|
|
node.hasPointerCapture = vi.fn((id) => captured === id);
|
|
node.releasePointerCapture = vi.fn(() => {
|
|
captured = undefined;
|
|
});
|
|
return node;
|
|
}
|
|
async function pointer(node: Element, type: string, extra = {}) {
|
|
const e = new Event(type, { bubbles: true, cancelable: true });
|
|
Object.assign(e, {
|
|
pointerId: 1,
|
|
pointerType: "mouse",
|
|
isPrimary: true,
|
|
button: 0,
|
|
clientX: 112,
|
|
clientY: 112,
|
|
...extra,
|
|
});
|
|
node.dispatchEvent(e);
|
|
await flushPromises();
|
|
return e;
|
|
}
|
|
describe("immutable private color value boundary", () => {
|
|
it("parses shorthand alpha, comma and CSS space/slash forms without using DOM", () => {
|
|
expect(parseColor("#f008").toString("hexa")).toBe("#FF000088");
|
|
expect(parseColor("rgb(100% 0% 0% / 50%)").toString("rgba")).toBe(
|
|
"rgba(255, 0, 0, 0.5)",
|
|
);
|
|
expect(parseColor("hsl(-120, 100%, 50%)").toString("hex")).toBe("#0000FF");
|
|
expect(parseColor("hsva(240, 100%, 100%, .25)").getColorSpace()).toBe(
|
|
"hsb",
|
|
);
|
|
});
|
|
it("rejects malformed/trailing/non-finite values, unsupported names and foreign objects", () => {
|
|
for (const value of [
|
|
"rgb(1,2,3) junk",
|
|
"rgb(1,,2,3)",
|
|
"hsl(NaN 0% 0%)",
|
|
"rebeccapurple",
|
|
"var(--accent)",
|
|
"#12",
|
|
"rgb(1 2)",
|
|
])
|
|
expect(() => parseColor(value)).toThrow();
|
|
expect(
|
|
() => new Color({ space: "rgb", r: Infinity, g: 0, b: 0, alpha: 1 }),
|
|
).toThrow();
|
|
expect(() =>
|
|
copyColor({
|
|
space: "rgb",
|
|
r: 0,
|
|
g: 0,
|
|
b: 0,
|
|
alpha: 1,
|
|
} as unknown as Color),
|
|
).toThrow();
|
|
});
|
|
it("clamps finite inputs and keeps fractional channels internally", () => {
|
|
const value = parseColor("hsb(240, 23.45678%, 70.12345%, 0.4321)");
|
|
expect(value.getChannelValue("saturation")).toBe(23.45678);
|
|
expect(
|
|
value.withChannelValue("saturation", 200).getChannelValue("saturation"),
|
|
).toBe(100);
|
|
expect(value.withAlpha(-1).getChannelValue("alpha")).toBe(0);
|
|
expect(value.getChannelRange("alpha")).toMatchObject({
|
|
maxValue: 1,
|
|
step: 0.01,
|
|
});
|
|
});
|
|
it("keeps black/gray hue, converts polar spaces directly and never mutates a parent", () => {
|
|
const original = parseColor("hsb(270, 0%, 50%)");
|
|
expect(original.toFormat("hsl").getChannelValue("hue")).toBe(270);
|
|
const next = original.withChannelValue("saturation", 100);
|
|
expect(next.toString("hex")).toBe("#400080");
|
|
expect(original.getChannelValue("saturation")).toBe(0);
|
|
const wire = Color.toWire(original);
|
|
wire.alpha = 0;
|
|
expect(original.getChannelValue("alpha")).toBe(1);
|
|
expect(Object.isFrozen(original)).toBe(true);
|
|
});
|
|
it("round trips representative RGB/HSL/HSB colors without hex quantization", () => {
|
|
for (const raw of [
|
|
"rgb(12.25, 69.125, 223.75, .12345)",
|
|
"hsl(207.5, 72.25%, 41.125%, .75)",
|
|
"hsb(342.25, 70.125%, 88.75%)",
|
|
]) {
|
|
const color = parseColor(raw).toFormat("rgb");
|
|
for (const space of ["hsl", "hsb"] as const) {
|
|
const restored = color.toFormat(space).toFormat("rgb");
|
|
for (const channel of ["red", "green", "blue", "alpha"] as const)
|
|
expect(restored.getChannelValue(channel)).toBeCloseTo(
|
|
color.getChannelValue(channel),
|
|
7,
|
|
);
|
|
}
|
|
}
|
|
});
|
|
it("resolves legal space defaults and rejects duplicate/mismatched axes", () => {
|
|
expect(colorAxes(parseColor("#f00"))).toMatchObject({
|
|
space: "rgb",
|
|
x: "red",
|
|
y: "green",
|
|
});
|
|
expect(colorAxes(parseColor("hsl(200, 50%, 50%)"))).toMatchObject({
|
|
space: "hsl",
|
|
x: "hue",
|
|
y: "saturation",
|
|
});
|
|
expect(colorAxes(parseColor("hsb(240, 50%, 50%)"))).toMatchObject({
|
|
space: "hsb",
|
|
x: "hue",
|
|
y: "saturation",
|
|
});
|
|
expect(colorAxes(parseColor("#f00"), "rgb")).toMatchObject({
|
|
x: "red",
|
|
y: "green",
|
|
});
|
|
expect(() =>
|
|
colorAxes(parseColor("#f00"), "hsl", "saturation", "saturation"),
|
|
).toThrow();
|
|
expect(() => colorAxes(parseColor("#f00"), "rgb", "hue", "blue")).toThrow();
|
|
});
|
|
it("builds every ordered axis pair in three spaces with real nonempty gradients", () => {
|
|
for (const space of ["rgb", "hsl", "hsb"] as const) {
|
|
const c = parseColor("hsb(210,60%,70%)").toFormat(space);
|
|
for (const a of c.getChannels())
|
|
for (const b of c.getChannels()) {
|
|
if (a === b) continue;
|
|
const style = colorAreaBackground(c, space, a, b);
|
|
expect(style.backgroundImage).toContain("linear-gradient");
|
|
expect(style.backgroundImage).not.toContain("NaN");
|
|
if (a === "hue" || b === "hue")
|
|
expect(style.backgroundImage.split("rgb").length).toBeGreaterThan(
|
|
6,
|
|
);
|
|
}
|
|
}
|
|
});
|
|
it("orients reversed axes and RTL backgrounds consistently with coordinates", () => {
|
|
const c = parseColor("hsb(240,50%,50%)");
|
|
expect(
|
|
colorAreaBackground(c, "hsb", "brightness", "saturation").backgroundImage,
|
|
).toContain("linear-gradient(to right, #000000, transparent)");
|
|
expect(
|
|
colorAreaBackground(c, "hsb", "saturation", "brightness", "rtl")
|
|
.backgroundImage,
|
|
).toContain("linear-gradient(to left, rgb(255, 255, 255), transparent)");
|
|
});
|
|
});
|
|
describe("one accepted color owner for picker children", () => {
|
|
it("shares area, hue, text and swatch state and creates only one native submission", async () => {
|
|
const w = fixture();
|
|
await key(w, "ArrowRight");
|
|
expect(events(w)).toHaveLength(1);
|
|
expect(x(w).element.value).toBe("51");
|
|
expect(w.get("[data-color-output]").text()).toBe("hsb(240, 51%, 50%)");
|
|
expect(data(w)).toHaveLength(1);
|
|
expect(w.findAll('[name="color"]')).toHaveLength(1);
|
|
expect(ends(w)).toHaveLength(1);
|
|
});
|
|
it("restores rejected coordinates, siblings and native values and allows identical retries", async () => {
|
|
const value = parseColor("hsb(240,50%,50%)");
|
|
const w = fixture(':model-value="value"', () => ({ value }));
|
|
for (let i = 0; i < 2; i++) await key(w, "ArrowRight");
|
|
expect(events(w).map((v) => v!.getChannelValue("saturation"))).toEqual([
|
|
51, 51,
|
|
]);
|
|
expect(x(w).element.value).toBe("50");
|
|
expect(ends(w)).toHaveLength(2);
|
|
expect((ends(w)[0]![0] as Color).getChannelValue("saturation")).toBe(51);
|
|
expect(data(w)).toEqual([value.toString("hexa")]);
|
|
});
|
|
it("preserves gray hue across a sibling hue change and area saturation edit", async () => {
|
|
const w = fixture('default-value="hsb(240,0%,50%)"');
|
|
const hue = w.get<HTMLInputElement>("[data-color-hue]");
|
|
hue.element.value = "270";
|
|
await hue.trigger("input");
|
|
await hue.trigger("change");
|
|
x(w).element.value = "100";
|
|
await x(w).trigger("input");
|
|
await x(w).trigger("change");
|
|
expect(events(w).at(-1)!.toString("hex")).toBe("#400080");
|
|
expect(w.get("[data-color-output]").text()).toContain("270");
|
|
});
|
|
it("keeps keyboard repetitions in one transaction and commits once after release", async () => {
|
|
const w = fixture();
|
|
await key(w, "ArrowRight", false);
|
|
await key(w, "ArrowRight", false, { repeat: true });
|
|
expect(ends(w)).toHaveLength(0);
|
|
await x(w).trigger("keyup", { key: "ArrowRight" });
|
|
expect(ends(w)).toHaveLength(1);
|
|
expect(x(w).element.value).toBe("52");
|
|
});
|
|
it("supports each native axis, Home/End, page keys, shift and RTL", async () => {
|
|
const w = fixture("", () => ({}), '<Area dir="rtl" color-space="hsb"/>');
|
|
await key(w, "ArrowRight");
|
|
expect(x(w).element.value).toBe("49");
|
|
await key(w, "ArrowUp", true, { shiftKey: true }, "y");
|
|
expect(y(w).element.value).toBe("60");
|
|
await key(w, "PageDown", true, {}, "y");
|
|
expect(y(w).element.value).toBe("50");
|
|
await key(w, "Home");
|
|
expect(x(w).element.value).toBe("59");
|
|
await key(w, "End");
|
|
expect(x(w).element.value).toBe("49");
|
|
});
|
|
it("honors native consumer cancellation and disabled/readonly inherited permissions", async () => {
|
|
const w = fixture("", () => ({}), "<Area @keydown.prevent/>");
|
|
await key(w, "ArrowRight");
|
|
expect(events(w)).toHaveLength(0);
|
|
for (const attrs of ["is-disabled", "is-read-only"]) {
|
|
const other = fixture(attrs);
|
|
await key(other, "ArrowRight");
|
|
expect(events(other)).toHaveLength(0);
|
|
}
|
|
});
|
|
it("keeps model precision and serializes an explicit hexa form boundary", async () => {
|
|
const value = parseColor("hsb(240,50.123%,50.567%,.321)");
|
|
const w = fixture(':default-value="value"', () => ({ value }));
|
|
expect(x(w).element.value).toBe("50.123");
|
|
await key(w, "ArrowUp", true, {}, "y");
|
|
expect(events(w)[0]!.getChannelValue("alpha")).toBe(0.321);
|
|
expect(events(w)[0]!.getChannelValue("saturation")).toBe(50.123);
|
|
expect(data(w)).toEqual([events(w)[0]!.toString("hexa")]);
|
|
});
|
|
it("cancels keyboard transaction on external replacement and does not end a stale gesture", async () => {
|
|
const value = shallowRef(parseColor("hsb(240,50%,50%)"));
|
|
const w = fixture('v-model="value"', () => ({ value }));
|
|
await key(w, "ArrowRight", false);
|
|
value.value = parseColor("hsb(90,25%,75%)");
|
|
await flushPromises();
|
|
await x(w).trigger("keyup", { key: "ArrowRight" });
|
|
expect(ends(w)).toHaveLength(0);
|
|
expect(x(w).element.value).toBe("25");
|
|
});
|
|
it("allows a child to opt out with an explicit value, then inherit again when removed", async () => {
|
|
const props = shallowRef<Record<string, unknown>>({
|
|
modelValue: "hsb(10,20%,30%)",
|
|
});
|
|
const w = fixture("", () => ({ props }), '<Area v-bind="props"/>');
|
|
await key(w, "ArrowRight");
|
|
expect(events(w)).toHaveLength(0);
|
|
expect(x(w).element.value).toBe("20");
|
|
props.value = {};
|
|
await flushPromises();
|
|
await key(w, "ArrowRight");
|
|
expect(events(w)).toHaveLength(1);
|
|
expect(x(w).element.value).toBe("51");
|
|
});
|
|
it("resets one owner and all children, with cancelled and controlled reset preserved", async () => {
|
|
const w = fixture();
|
|
await key(w, "ArrowRight");
|
|
(w.get("form").element as HTMLFormElement).reset();
|
|
await flushPromises();
|
|
expect(x(w).element.value).toBe("50");
|
|
expect(events(w)).toHaveLength(1);
|
|
w.get("form").element.addEventListener("reset", (e) => e.preventDefault());
|
|
await key(w, "ArrowRight");
|
|
(w.get("form").element as HTMLFormElement).reset();
|
|
await flushPromises();
|
|
expect(x(w).element.value).toBe("51");
|
|
const value = shallowRef(parseColor("hsb(20,30%,40%)"));
|
|
const controlled = fixture('v-model="value"', () => ({ value }));
|
|
await key(controlled, "ArrowRight");
|
|
(controlled.get("form").element as HTMLFormElement).reset();
|
|
await flushPromises();
|
|
expect(x(controlled).element.value).toBe("31");
|
|
});
|
|
it("rejects invalid text and restores a controlled native range input after AT input", async () => {
|
|
const w = fixture('model-value="hsb(240,50%,50%)"');
|
|
const text = w.get<HTMLInputElement>("[data-color-text]");
|
|
await text.setValue("rgb(1,2,3)junk");
|
|
expect(events(w)).toHaveLength(0);
|
|
expect(text.element.value).toBe("#404080FF");
|
|
x(w).element.value = "80";
|
|
await x(w).trigger("input");
|
|
await x(w).trigger("change");
|
|
await flushPromises();
|
|
expect(x(w).element.value).toBe("50");
|
|
expect(events(w)).toHaveLength(1);
|
|
expect(ends(w)).toHaveLength(1);
|
|
});
|
|
});
|
|
describe("private color area pointer ownership", () => {
|
|
it("captures the stable root, ignores other pointers and commits the last proposal once", async () => {
|
|
const w = fixture();
|
|
const root = geometry(w);
|
|
await pointer(root, "pointerdown", { clientX: 56, clientY: 56 });
|
|
await pointer(root, "pointermove", {
|
|
clientX: 168,
|
|
clientY: 112,
|
|
pointerId: 2,
|
|
});
|
|
await pointer(root, "pointermove", { clientX: 168, clientY: 112 });
|
|
await pointer(root, "pointerup", { clientX: 168, clientY: 112 });
|
|
expect(root.setPointerCapture).toHaveBeenCalledWith(1);
|
|
expect(events(w).map((v) => v!.getChannelValue("saturation"))).toEqual([
|
|
25, 75,
|
|
]);
|
|
expect(ends(w)).toHaveLength(1);
|
|
expect(root.releasePointerCapture).toHaveBeenCalledWith(1);
|
|
});
|
|
it("retains thumb grab offset and releases capture on lost/cancelled/disabled/unmounted interactions", async () => {
|
|
const disabled = shallowRef(false);
|
|
const w = fixture(':is-disabled="disabled"', () => ({ disabled }));
|
|
const root = geometry(w);
|
|
const handle = w.get("[data-color-thumb]").element;
|
|
await pointer(handle, "pointerdown", { clientX: 116, clientY: 116 });
|
|
expect(events(w)).toHaveLength(0);
|
|
await pointer(root, "pointermove", { clientX: 138.4, clientY: 116 });
|
|
expect(events(w)[0]!.getChannelValue("saturation")).toBeCloseTo(60);
|
|
await pointer(root, "pointercancel");
|
|
expect(ends(w)).toHaveLength(0);
|
|
await pointer(root, "pointerdown");
|
|
disabled.value = true;
|
|
await flushPromises();
|
|
expect(root.releasePointerCapture).toHaveBeenCalled();
|
|
expect(ends(w)).toHaveLength(0);
|
|
disabled.value = false;
|
|
await flushPromises();
|
|
await pointer(root, "pointerdown");
|
|
w.unmount();
|
|
expect(root.hasPointerCapture?.(1)).toBe(false);
|
|
});
|
|
it("preserves the accepted thumb under rejected pointer updates and retries on a new drag", async () => {
|
|
const w = fixture('model-value="hsb(240,50%,50%)"');
|
|
const root = geometry(w);
|
|
for (let n = 0; n < 2; n++) {
|
|
await pointer(root, "pointerdown", { clientX: 168 });
|
|
await pointer(root, "pointerup", { clientX: 168 });
|
|
}
|
|
expect(events(w)).toHaveLength(2);
|
|
expect(ends(w)).toHaveLength(2);
|
|
expect(w.get("[data-color-thumb]").attributes("style")).toContain(
|
|
"left: 50%",
|
|
);
|
|
});
|
|
it("does not start from cancelled/nonprimary/right pointers and ignores zero geometry", async () => {
|
|
const w = fixture("", () => ({}), "<Area @pointerdown.prevent/>");
|
|
const root = geometry(w);
|
|
await pointer(root, "pointerdown");
|
|
expect(events(w)).toHaveLength(0);
|
|
expect(root.setPointerCapture).not.toHaveBeenCalled();
|
|
const other = fixture();
|
|
const node = geometry(other);
|
|
await pointer(node, "pointerdown", { button: 2 });
|
|
await pointer(node, "pointerdown", { isPrimary: false });
|
|
await pointer(node, "pointerdown", { ctrlKey: true });
|
|
vi.spyOn(node, "getBoundingClientRect").mockReturnValue({
|
|
left: 0,
|
|
top: 0,
|
|
width: 0,
|
|
height: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
x: 0,
|
|
y: 0,
|
|
toJSON: () => ({}),
|
|
});
|
|
await pointer(node, "pointerdown");
|
|
expect(events(other)).toHaveLength(0);
|
|
});
|
|
it("does not let a disabled sibling cancel another area's active capture", async () => {
|
|
const disabled = shallowRef(false);
|
|
const w = fixture(
|
|
"",
|
|
() => ({ disabled }),
|
|
'<Area data-first :is-disabled="disabled"/><Area data-second/>',
|
|
);
|
|
const second = geometry(w, "[data-second]");
|
|
await pointer(second, "pointerdown", { clientX: 168 });
|
|
disabled.value = true;
|
|
await flushPromises();
|
|
await pointer(second, "pointerup", { clientX: 168 });
|
|
expect(ends(w)).toHaveLength(1);
|
|
expect(second.releasePointerCapture).toHaveBeenCalledWith(1);
|
|
});
|
|
it("cancels the old provider gesture when a child switches to its own controlled owner", async () => {
|
|
const props = shallowRef<Record<string, unknown>>({});
|
|
const w = fixture("", () => ({ props }), '<Area v-bind="props"/>');
|
|
const root = geometry(w);
|
|
await pointer(root, "pointerdown", { clientX: 168 });
|
|
props.value = { modelValue: "hsb(20,30%,40%)" };
|
|
await flushPromises();
|
|
await pointer(root, "pointerup", { clientX: 168 });
|
|
expect(ends(w)).toHaveLength(0);
|
|
expect(w.getComponent(Picker).vm.state.active.value).toBeUndefined();
|
|
expect(root.hasPointerCapture?.(1)).toBe(false);
|
|
expect(x(w).element.value).toBe("30");
|
|
});
|
|
it("maps the content box correctly with different ancestor scales and borders", async () => {
|
|
const w = fixture();
|
|
const root = geometry(w);
|
|
root.style.border = "4px solid black";
|
|
vi.spyOn(root, "getBoundingClientRect").mockReturnValue({
|
|
left: 100,
|
|
top: 200,
|
|
width: 448,
|
|
height: 224,
|
|
right: 548,
|
|
bottom: 424,
|
|
x: 100,
|
|
y: 200,
|
|
toJSON: () => ({}),
|
|
});
|
|
await pointer(root, "pointerdown", { clientX: 216, clientY: 258 });
|
|
await pointer(root, "pointerup", { clientX: 216, clientY: 258 });
|
|
expect(events(w)[0]!.getChannelValue("saturation")).toBeCloseTo(25);
|
|
expect(events(w)[0]!.getChannelValue("brightness")).toBeCloseTo(75);
|
|
});
|
|
it("cancels capture on window blur without manufacturing changeEnd", async () => {
|
|
const w = fixture();
|
|
const root = geometry(w);
|
|
await pointer(root, "pointerdown");
|
|
window.dispatchEvent(new Event("blur"));
|
|
await flushPromises();
|
|
expect(root.hasPointerCapture?.(1)).toBe(false);
|
|
expect(ends(w)).toHaveLength(0);
|
|
});
|
|
it("uses two native named axes and restores an uncontrolled standalone area on reset", async () => {
|
|
const w = mount(
|
|
defineComponent({
|
|
components: { Area },
|
|
template:
|
|
'<form><Area default-value="hsb(240,50%,50%)" x-name="s" y-name="b"/></form>',
|
|
}),
|
|
{ attachTo: document.body },
|
|
);
|
|
wrappers.push(w);
|
|
await key(w, "ArrowUp");
|
|
const form = w.get("form").element as HTMLFormElement;
|
|
expect(new FormData(form).get("s")).toBe("50");
|
|
expect(new FormData(form).get("b")).toBe("51");
|
|
form.reset();
|
|
await flushPromises();
|
|
expect(x(w).element.value).toBe("50");
|
|
expect(y(w).element.value).toBe("50");
|
|
});
|
|
it("restores accepted native axes on controlled reset even when Vue props do not change", async () => {
|
|
const value = shallowRef("hsb(240,50%,50%)");
|
|
const w = mount(
|
|
defineComponent({
|
|
components: { Area },
|
|
setup: () => ({ value }),
|
|
template:
|
|
'<form><Area :model-value="value" x-name="s" y-name="b"/></form>',
|
|
}),
|
|
{ attachTo: document.body },
|
|
);
|
|
wrappers.push(w);
|
|
value.value = "hsb(240,70%,80%)";
|
|
await flushPromises();
|
|
(w.get("form").element as HTMLFormElement).reset();
|
|
await flushPromises();
|
|
expect(x(w).element.value).toBe("70");
|
|
expect(y(w).element.value).toBe("80");
|
|
expect(w.getComponent(Area).emitted("change")).toBeUndefined();
|
|
});
|
|
it("keeps one Tab entry and moves focus to the axis operated by the keyboard", async () => {
|
|
const w = fixture();
|
|
expect(x(w).attributes("tabindex")).toBe("0");
|
|
expect(y(w).attributes("tabindex")).toBe("-1");
|
|
await key(w, "ArrowUp");
|
|
expect(document.activeElement).toBe(y(w).element);
|
|
expect(x(w).attributes("tabindex")).toBe("-1");
|
|
expect(y(w).attributes("tabindex")).toBe("0");
|
|
await key(w, "ArrowRight", true, {}, "y");
|
|
expect(document.activeElement).toBe(x(w).element);
|
|
expect(x(w).element.value).toBe("51");
|
|
expect(y(w).element.value).toBe("51");
|
|
});
|
|
it("uses channel-specific page steps, alpha units and explicit formatted output", () => {
|
|
expect(parseColor("#123456").getChannelRange("red").pageSize).toBe(17);
|
|
const color = parseColor("hsb(240,50%,50%,.5)");
|
|
expect(color.getChannelRange("hue").pageSize).toBe(15);
|
|
expect(color.toString("hsb")).toBe("hsb(240, 50%, 50%)");
|
|
expect(color.toString("hsba")).toBe("hsba(240, 50%, 50%, 0.5)");
|
|
expect(color.formatChannelValue("alpha", "en-US")).toBe("50%");
|
|
});
|
|
});
|