Files
heroui-vue/tests/choice-demos.test.ts
2026-10-22 09:15:27 +08:00

97 lines
2.6 KiB
TypeScript

import { expect, it, vi } from "vitest";
import { mount } from "@vue/test-utils";
import { nextTick, type Component } from "vue";
import { readFileSync } from "node:fs";
const demos = import.meta.glob<{ default: Component }>(
"../apps/docs/demos/{checkbox,checkbox-group,radio-group}-*.vue",
);
it("mounts all 37 baseline choice demos without render warnings or missing controls", async () => {
expect(Object.keys(demos)).toHaveLength(37);
const warn = vi.spyOn(console, "warn"),
error = vi.spyOn(console, "error");
try {
for (const [name, load] of Object.entries(demos)) {
const component = await load();
const w = mount(component.default, { attachTo: document.body });
try {
await nextTick();
expect(
w.findAll("input[data-choice-input]").length,
name,
).toBeGreaterThan(0);
} finally {
w.unmount();
}
}
expect(warn).not.toHaveBeenCalled();
expect(error).not.toHaveBeenCalled();
} finally {
warn.mockRestore();
error.mockRestore();
}
});
it("keeps all source previews in the documented order and uses Vue/Tabler demos", () => {
const expected = {
checkbox: [
"basic",
"variants",
"full-rounded",
"disabled",
"external-label",
"with-description",
"default-selected",
"invalid",
"controlled",
"indeterminate",
"form",
"render-props",
"render-function",
"custom-indicator",
"custom-styles",
],
"checkbox-group": [
"basic",
"on-surface",
"disabled",
"indeterminate",
"controlled",
"validation",
"features-and-addons",
"with-custom-indicator",
"render-function",
"custom-styles",
],
"radio-group": [
"basic",
"horizontal",
"variants",
"on-surface",
"disabled",
"controlled",
"uncontrolled",
"validation",
"delivery-and-payment",
"custom-indicator",
"render-function",
"custom-styles",
],
};
for (const [name, parts] of Object.entries(expected)) {
const markdown = readFileSync(`apps/docs/components/${name}.md`, "utf8");
expect(
[...markdown.matchAll(/<ComponentPreview\b[^>]*?name="([^"]+)"/g)].map(
(m) => m[1],
),
).toEqual(parts.map((part) => `${name}-${part}`));
for (const part of parts) {
const source = readFileSync(
`apps/docs/demos/${name}-${part}.vue`,
"utf8",
);
expect(source).not.toContain("<svg");
expect(source).not.toContain("className=");
expect(source).not.toContain("onChange=");
}
}
});