Files
heroui-vue/tests/package/consume-list-box.mjs
T

53 lines
1.5 KiB
JavaScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { createSSRApp, h } from "vue";
import { renderToString } from "@vue/server-renderer";
import {
ListBox,
ListBoxItem,
ListBoxItemIndicator,
ListBoxSection,
Header,
Label,
Description,
listboxVariants,
listboxItemVariants,
} from "@heroui-vue/components";
const html = await renderToString(
createSSRApp({
render: () =>
h(ListBox, { modelValue: [0], "aria-label": "People" }, () => [
h(ListBoxSection, {}, () => [
h(Header, {}, () => "Team"),
h(ListBoxItem, { id: 0 }, () => [
h(Label, {}, () => "Bob"),
h(Description, {}, () => "Details"),
h(ListBoxItemIndicator),
]),
]),
h(ListBoxItem, { id: "0" }, () => "Fred"),
]),
}),
);
assert.equal((html.match(/aria-selected="true"/g) ?? []).length, 1);
assert(html.includes('role="group"'));
assert(html.includes('aria-labelledby="'));
assert(html.includes('aria-describedby="'));
assert(listboxVariants().includes("hv-list-box"));
assert(
listboxItemVariants().indicator().includes("hv-list-box-item__indicator"),
);
const css = readFileSync(
new URL(import.meta.resolve("@heroui-vue/styles/css")),
"utf8",
);
for (const name of [
".hv-list-box",
".hv-list-box-item",
".hv-list-box-section",
])
assert(css.includes(name));
console.log(
"ListBox independent tarball: ESM, SSR, typed selection, labels and CSS passed.",
);