feat: align public Root aliases and rework progress-bar custom-value demo

- 包根补齐固定上游 82 对 Xxx/XxxRoot 同对象别名(55 个缺失 Root 别名 + Dropdown 反向别名)与 59 个 RootProps/Menu/Dropdown 类型别名;不杜撰上游没有的名称(如 CheckboxGroupRoot、ToastRootProps)
- tests/package 新增 api-root-aliases 契约:完整别名清单、82 对身份等价断言与 strict NodeNext/bundler 类型正反例
- progress-bar custom-value 演示回填公共 NumberField/Select,保持固定源文案/布局/范围/四格式与边界处理
- 修复 NumberFieldInput keydown 无条件 restore 还原同任务键入字符的缺陷,并入 number-field 回归
- 文档导航 dropdown 归位固定 meta.json 顺序并补顺序断言;修正“原生临时控件”陈述
This commit is contained in:
maoyingjie
2026-10-27 19:48:35 +08:00
parent e0dd052cc3
commit 8f51b0e097
17 changed files with 1766 additions and 63 deletions
+191 -1
View File
@@ -1,7 +1,7 @@
import { componentItems } from "../apps/docs/.vitepress/theme/navigation";
import { describe, it, expect, afterEach } from "vitest";
import { readFileSync } from "node:fs";
import { mount } from "@vue/test-utils";
import { flushPromises, mount } from "@vue/test-utils";
import { defineComponent, h, nextTick, ref } from "vue";
import {
Label,
@@ -761,3 +761,193 @@ it("isolates indicator labels from both surrounding and nested field scopes", as
);
w.unmount();
});
describe("progress-bar custom-value demo with public NumberField/Select", () => {
async function setup() {
const mod = await import("../apps/docs/demos/progress-bar-custom-value.vue");
const w = mount(mod.default as never, { attachTo: document.body });
await flushPromises();
return w;
}
const field = (w: ReturnType<typeof mount>, index: number) =>
w.findAll('[data-slot="number-field"]')[index];
const inputOf = (w: ReturnType<typeof mount>, index: number) =>
field(w, index).get("input[role=spinbutton]");
const progress = (w: ReturnType<typeof mount>) =>
w.get("[data-slot=progress-bar]");
const output = (w: ReturnType<typeof mount>) =>
w.get("[data-slot=progress-bar-output]");
const fill = (w: ReturnType<typeof mount>) =>
w.get("[data-slot=progress-bar-fill]").element as HTMLElement;
const text = (options: Intl.NumberFormatOptions, value: number) =>
new Intl.NumberFormat(undefined, options).format(value);
const percent = (value: number, min: number, max: number) =>
text({ style: "percent" }, (value - min) / (max - min));
it("keeps the fixed source values and renders NumberField/Select parts", async () => {
const w = await setup();
expect(w.findAll('[data-slot="number-field"]')).toHaveLength(3);
expect(w.findAll("input[role=spinbutton]")).toHaveLength(3);
expect(w.findAll('[data-slot="select-trigger"]')).toHaveLength(1);
expect(
w.findAll('[data-slot="number-field-increment-button"]'),
).toHaveLength(3);
const bar = progress(w);
expect(bar.attributes("aria-label")).toBe("收入");
expect(bar.attributes("aria-valuenow")).toBe("750");
expect(bar.attributes("aria-valuemin")).toBe("0");
expect(bar.attributes("aria-valuemax")).toBe("1000");
expect(output(w).text()).toBe("75%");
expect(fill(w).style.width).toBe("75%");
const labels = w.findAll("[data-slot=label]").map((n) => n.text());
expect(labels).toEqual(["进度", "选项", "值", "最小值", "最大值", "格式"]);
w.unmount();
});
it("synchronizes typed input, stepping and bounds with progress text and fill", async () => {
const w = await setup();
const valueInput = inputOf(w, 0);
await valueInput.setValue("500");
await valueInput.trigger("blur");
await flushPromises();
expect(progress(w).attributes("aria-valuenow")).toBe("500");
expect(output(w).text()).toBe("50%");
expect(fill(w).style.width).toBe("50%");
await field(w, 0)
.get('[data-slot="number-field-increment-button"]')
.trigger("click");
await flushPromises();
expect(progress(w).attributes("aria-valuenow")).toBe("501");
expect(output(w).text()).toBe(percent(501, 0, 1000));
expect(fill(w).style.width).toBe("50.1%");
await field(w, 0)
.get('[data-slot="number-field-decrement-button"]')
.trigger("click");
await flushPromises();
expect(progress(w).attributes("aria-valuenow")).toBe("500");
await valueInput.setValue("1000");
await valueInput.trigger("blur");
await flushPromises();
expect(
(
field(w, 0)
.get('[data-slot="number-field-increment-button"]')
.element as HTMLButtonElement
).disabled,
).toBe(true);
expect(output(w).text()).toBe("100%");
w.unmount();
});
it("rejects cleared and invalid drafts without NaN or display mismatch", async () => {
const w = await setup();
const valueInput = inputOf(w, 0);
for (const draft of ["", "abc", "-"]) {
await valueInput.setValue(draft);
await valueInput.trigger("blur");
await flushPromises();
expect(progress(w).attributes("aria-valuenow")).toBe("750");
expect(output(w).text()).toBe("75%");
expect(fill(w).style.width).toBe("75%");
expect((valueInput.element as HTMLInputElement).value).not.toBe("");
expect(w.text()).not.toContain("NaN");
}
w.unmount();
});
it("clamps out-of-range commits into the current range", async () => {
const w = await setup();
const valueInput = inputOf(w, 0);
await valueInput.setValue("5000");
await valueInput.trigger("blur");
await flushPromises();
expect(progress(w).attributes("aria-valuenow")).toBe("1000");
expect(output(w).text()).toBe("100%");
expect(fill(w).style.width).toBe("100%");
await valueInput.setValue("-20");
await valueInput.trigger("blur");
await flushPromises();
expect(progress(w).attributes("aria-valuenow")).toBe("0");
expect(output(w).text()).toBe("0%");
expect(fill(w).style.width).toBe("0%");
w.unmount();
});
it("re-syncs value when the dynamic bounds change", async () => {
const w = await setup();
const minInput = inputOf(w, 1);
await minInput.setValue("800");
await minInput.trigger("blur");
await flushPromises();
expect(progress(w).attributes("aria-valuemin")).toBe("800");
expect(progress(w).attributes("aria-valuenow")).toBe("800");
expect(output(w).text()).toBe("0%");
await minInput.setValue("2000");
await minInput.trigger("blur");
await flushPromises();
expect(progress(w).attributes("aria-valuemin")).toBe("999");
expect(progress(w).attributes("aria-valuenow")).toBe("999");
const maxInput = inputOf(w, 2);
await maxInput.setValue("400");
await maxInput.trigger("blur");
await flushPromises();
expect(progress(w).attributes("aria-valuemax")).toBe("1000");
expect(progress(w).attributes("aria-valuenow")).toBe("999");
w.unmount();
const fresh = await setup();
const freshMax = inputOf(fresh, 2);
await freshMax.setValue("600");
await freshMax.trigger("blur");
await flushPromises();
expect(progress(fresh).attributes("aria-valuemax")).toBe("600");
expect(progress(fresh).attributes("aria-valuenow")).toBe("600");
expect(output(fresh).text()).toBe("100%");
await freshMax.setValue("0");
await freshMax.trigger("blur");
await flushPromises();
expect(progress(fresh).attributes("aria-valuemax")).toBe("1");
expect(progress(fresh).attributes("aria-valuenow")).toBe("1");
fresh.unmount();
});
it("switches all four formats through the Select panel", async () => {
const w = await setup();
const cases: [string, Intl.NumberFormatOptions, number, number][] = [
["货币", { currency: "USD", style: "currency" }, 750, 1000],
["小数", { style: "decimal" }, 750, 1000],
["单位", { style: "unit", unit: "mile" }, 750, 1000],
["百分比", { style: "percent" }, 750, 1000],
];
for (const [label, options, value, max] of cases) {
await w.get('[data-slot="select-trigger"]').trigger("keydown", {
key: "ArrowDown",
});
await flushPromises();
const panelOptions = [
...document.querySelectorAll<HTMLElement>('[role="option"]'),
];
expect(panelOptions.map((n) => n.textContent?.trim())).toEqual([
"货币",
"百分比",
"小数",
"单位",
]);
const target = panelOptions.find((n) => n.textContent?.trim() === label)!;
target.click();
await flushPromises();
expect(document.querySelector('[role="listbox"]')).toBeNull();
expect(w.get('[data-slot="select-value"]').text()).toContain(label);
const expected =
options.style === "percent"
? percent(value, 0, max)
: text(options, value);
expect(output(w).text()).toBe(expected);
}
w.unmount();
});
});