Files
heroui-vue/tests/package/consume-select.mjs
T

71 lines
1.9 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 {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectClearButton,
SelectPopover,
ListBox,
ListBoxItem,
Label,
selectVariants,
} from "@heroui-vue/components";
const html = await renderToString(
createSSRApp({
render: () =>
h(
Select,
{
defaultValue: [0, "0", ""],
selectionMode: "multiple",
name: "choices",
},
() => [
h(Label, {}, () => "Choice"),
h(SelectTrigger, {}, () => [
h(SelectValue),
h(SelectClearButton),
h(SelectIndicator),
]),
h(SelectPopover, {}, () =>
h(ListBox, {}, () => [
h(ListBoxItem, { id: 0, textValue: "Numeric" }, () => "Numeric"),
h(ListBoxItem, { id: "0", textValue: "String" }, () => "String"),
h(ListBoxItem, { id: "", textValue: "Empty" }, () => "Empty"),
]),
),
],
),
}),
);
assert(html.includes("Numeric, String, Empty"));
assert(html.includes('name="choices"'));
assert.equal((html.match(/data-index="\d" selected/g) ?? []).length, 3);
assert(!html.includes('role="listbox"'));
assert(html.includes('aria-haspopup="listbox"'));
assert(
selectVariants({ variant: "secondary" })
.base()
.includes("hv-select--secondary"),
);
const css = readFileSync(
new URL(import.meta.resolve("@heroui-vue/styles/css")),
"utf8",
);
for (const part of [
".hv-select",
".hv-select__trigger",
".hv-select__value",
".hv-select__clear-button",
".hv-select__indicator",
".hv-select__popover",
])
assert(css.includes(part));
console.log(
"Select independent tarball: ESM, SSR labels, raw native values, variants and CSS passed.",
);