145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
193 lines
6.2 KiB
TypeScript
193 lines
6.2 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { mount } from "@vue/test-utils";
|
|
import { defineComponent, nextTick, ref } from "vue";
|
|
import { Header, HeaderRoot, ListBoxSection } from "../packages/vue/src";
|
|
|
|
import HeaderBasicDemo from "../apps/docs/demos/header-basic.vue";
|
|
import HeaderCollectionGroupingDemo from "../apps/docs/demos/header-collection-grouping.vue";
|
|
import HeaderCustomClassDemo from "../apps/docs/demos/header-custom-class.vue";
|
|
import HeaderSemanticDemo from "../apps/docs/demos/header-semantic.vue";
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = "";
|
|
});
|
|
|
|
describe("Header basics", () => {
|
|
it("renders a native header with baseline class and data-slot", () => {
|
|
const w = mount(Header, {
|
|
props: {},
|
|
slots: { default: "操作" },
|
|
attachTo: document.body,
|
|
});
|
|
const root = w.get('[data-slot="header"]');
|
|
expect(root.element.tagName).toBe("HEADER");
|
|
expect(root.classes().join(" ")).toContain("hv-header");
|
|
expect(root.text()).toBe("操作");
|
|
w.unmount();
|
|
});
|
|
|
|
it("exports Header as HeaderRoot alias", () => {
|
|
expect(Header).toBe(HeaderRoot);
|
|
});
|
|
|
|
it("supports as override without inventing heading levels", () => {
|
|
const w = mount(Header, {
|
|
props: { as: "div" },
|
|
slots: { default: "分组" },
|
|
attachTo: document.body,
|
|
});
|
|
const root = w.get('[data-slot="header"]');
|
|
expect(root.element.tagName).toBe("DIV");
|
|
expect(root.attributes("role")).toBeUndefined();
|
|
expect(root.attributes("aria-level")).toBeUndefined();
|
|
w.unmount();
|
|
});
|
|
|
|
it("merges class and attrs, including dynamic add/update/delete/re-add", async () => {
|
|
const extra = ref<Record<string, unknown>>({});
|
|
const w = mount(
|
|
defineComponent({
|
|
components: { Header },
|
|
setup: () => ({ extra }),
|
|
template: `<Header v-bind="extra" class="base-header">分组</Header>`,
|
|
}),
|
|
{ attachTo: document.body },
|
|
);
|
|
let root = w.get('[data-slot="header"]');
|
|
expect(root.classes()).toContain("hv-header");
|
|
expect(root.classes()).toContain("base-header");
|
|
|
|
extra.value = {
|
|
"data-testid": "h1",
|
|
"aria-label": "分组标题",
|
|
id: "group-title",
|
|
};
|
|
await nextTick();
|
|
root = w.get('[data-slot="header"]');
|
|
expect(root.attributes("data-testid")).toBe("h1");
|
|
expect(root.attributes("aria-label")).toBe("分组标题");
|
|
expect(root.attributes("id")).toBe("group-title");
|
|
|
|
extra.value = { "data-testid": "h2", title: "updated" };
|
|
await nextTick();
|
|
root = w.get('[data-slot="header"]');
|
|
expect(root.attributes("data-testid")).toBe("h2");
|
|
expect(root.attributes("title")).toBe("updated");
|
|
expect(root.attributes("aria-label")).toBeUndefined();
|
|
expect(root.attributes("id")).toBeUndefined();
|
|
|
|
extra.value = {};
|
|
await nextTick();
|
|
root = w.get("[data-slot=header]");
|
|
expect(root.attributes("data-testid")).toBeUndefined();
|
|
expect(root.attributes("title")).toBeUndefined();
|
|
|
|
extra.value = { style: { color: "red" } };
|
|
await nextTick();
|
|
root = w.get("[data-slot=header]");
|
|
expect(root.attributes("style")).toContain("color: red");
|
|
w.unmount();
|
|
});
|
|
|
|
it("updates default slot content and keeps multiple instances independent", async () => {
|
|
const label = ref("A 组");
|
|
const w = mount(
|
|
defineComponent({
|
|
components: { Header },
|
|
setup: () => ({ label }),
|
|
template: `
|
|
<div>
|
|
<Header data-testid="one">{{ label }}</Header>
|
|
<Header data-testid="two">B 组</Header>
|
|
</div>
|
|
`,
|
|
}),
|
|
{ attachTo: document.body },
|
|
);
|
|
expect(w.get('[data-testid="one"]').text()).toBe("A 组");
|
|
expect(w.get('[data-testid="two"]').text()).toBe("B 组");
|
|
|
|
label.value = "A 组已更新";
|
|
await nextTick();
|
|
expect(w.get('[data-testid="one"]').text()).toBe("A 组已更新");
|
|
expect(w.get('[data-testid="two"]').text()).toBe("B 组");
|
|
w.unmount();
|
|
});
|
|
});
|
|
|
|
describe("Header demos", () => {
|
|
it("mounts all self-authored demos without Vue warnings", async () => {
|
|
const warnings: string[] = [];
|
|
const spy = vi.spyOn(console, "warn").mockImplementation((...args) => {
|
|
warnings.push(args.map(String).join(" "));
|
|
});
|
|
for (const demo of [
|
|
HeaderBasicDemo,
|
|
HeaderCollectionGroupingDemo,
|
|
HeaderCustomClassDemo,
|
|
HeaderSemanticDemo,
|
|
]) {
|
|
const w = mount(demo, { attachTo: document.body });
|
|
await nextTick();
|
|
expect(w.html().length).toBeGreaterThan(0);
|
|
expect(w.find('[data-slot="header"]').exists()).toBe(true);
|
|
w.unmount();
|
|
}
|
|
spy.mockRestore();
|
|
expect(warnings).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("Header collection grouping", () => {
|
|
it("registers its id as the MenuSection group label", async () => {
|
|
const { MenuSection } = await import("../packages/vue/src");
|
|
const w = mount(
|
|
defineComponent({
|
|
components: { MenuSection, Header },
|
|
template: `
|
|
<MenuSection>
|
|
<Header>视图</Header>
|
|
<div>item</div>
|
|
</MenuSection>
|
|
`,
|
|
}),
|
|
{ attachTo: document.body },
|
|
);
|
|
await nextTick();
|
|
const header = w.get('[data-slot="header"]');
|
|
const headerId = header.attributes("id");
|
|
expect(headerId).toBeTruthy();
|
|
const group = w.get('[data-slot="menu-section"]');
|
|
expect(group.attributes("aria-labelledby")).toBe(headerId);
|
|
w.unmount();
|
|
});
|
|
|
|
it("links ListBoxSection aria-labelledby to the scanned Header id", () => {
|
|
const w = mount(
|
|
defineComponent({
|
|
components: { ListBoxSection, Header },
|
|
template: `
|
|
<ListBoxSection>
|
|
<Header>今天</Header>
|
|
<div>item</div>
|
|
</ListBoxSection>
|
|
`,
|
|
}),
|
|
{ attachTo: document.body },
|
|
);
|
|
const header = w.get('[data-slot="header"]');
|
|
const headerId = header.attributes("id");
|
|
expect(headerId).toBeTruthy();
|
|
const group = w.get('[data-slot="list-box-section"]');
|
|
expect(group.attributes("aria-labelledby")).toBe(headerId);
|
|
w.unmount();
|
|
});
|
|
});
|
|
|
|
describe("Header types", () => {
|
|
it("exposes HeaderProps alias", () => {
|
|
const ok: InstanceType<typeof HeaderRoot>["$props"] = { as: "header" };
|
|
expect(ok.as).toBe("header");
|
|
});
|
|
});
|