import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { createSSRApp, h } from "vue"; import { renderToString } from "@vue/server-renderer"; import * as lib from "@heroui-vue/components"; for (const name of [ "ComboBox", "ComboBoxInputGroup", "ComboBoxTrigger", "ComboBoxValue", "ComboBoxPopover", "Autocomplete", "AutocompleteTrigger", "AutocompleteValue", "AutocompleteIndicator", "AutocompleteClearButton", "AutocompletePopover", "AutocompleteFilter", "comboBoxVariants", "autocompleteVariants", ]) assert(lib[name], name); const items = [ { id: "cat", textValue: "猫" }, { id: "dog", textValue: "狗" }, ]; const html = await renderToString( createSSRApp({ render: () => h("main", [ h( lib.ComboBox, { "aria-label": "动物", defaultSelectedKey: "cat", name: "animal" }, { default: () => [ h(lib.Label, null, () => "动物"), h(lib.ComboBoxInputGroup, null, { default: () => [h(lib.Input, {}), h(lib.ComboBoxTrigger)], }), h(lib.ComboBoxPopover, null, { default: () => h(lib.ListBox, null, { default: () => items.map((item) => h( lib.ListBoxItem, { id: item.id, key: item.id, textValue: item.textValue, }, () => item.textValue, ), ), }), }), ], }, ), h( lib.Autocomplete, { "aria-label": "州", name: "state", defaultValue: "dog" }, { default: () => [ h(lib.AutocompleteTrigger, null, { default: () => [ h(lib.AutocompleteValue), h(lib.AutocompleteClearButton), h(lib.AutocompleteIndicator), ], }), h(lib.AutocompletePopover, null, { default: () => h(lib.AutocompleteFilter, null, { default: () => [ h( lib.SearchField, { "aria-label": "搜索" }, { default: () => h(lib.SearchFieldGroup, null, { default: () => [h(lib.SearchFieldInput)], }), }, ), h(lib.ListBox, null, { default: () => items.map((item) => h( lib.ListBoxItem, { id: item.id, key: item.id, textValue: item.textValue, }, () => item.textValue, ), ), }), ], }), }), ], }, ), ]), }), ); assert(html.includes('data-slot="combo-box"'), "combo-box root"); assert(html.includes('role="combobox"'), "combobox input role"); assert(html.includes('data-slot="combo-box-trigger"'), "combo box trigger"); assert(html.includes('name="animal"'), "combo box form name"); assert(html.includes('data-slot="autocomplete"'), "autocomplete root"); assert( html.includes('data-slot="autocomplete-trigger"'), "autocomplete trigger", ); assert(html.includes('role="button"'), "autocomplete trigger is a button"); assert(html.includes('name="state"'), "autocomplete form name"); assert(html.includes("猫"), "combo box preselected label"); const css = readFileSync( "node_modules/@heroui-vue/styles/dist/styles.css", "utf8", ); for (const rule of [ ".hv-combo-box", ".hv-combo-box__input-group", ".hv-combo-box__trigger", ".hv-combo-box__popover", ".hv-combo-box__value", ".hv-autocomplete", ".hv-autocomplete__trigger", ".hv-autocomplete__value", ".hv-autocomplete__indicator", ".hv-autocomplete__clear-button", ".hv-autocomplete__popover", ".hv-autocomplete--secondary", ]) assert(css.includes(rule), `missing CSS ${rule}`); assert( lib .comboBoxVariants({ fullWidth: true }) .base() .includes("hv-combo-box--full-width"), ); assert( lib .autocompleteVariants({ variant: "secondary" }) .base() .includes("hv-autocomplete--secondary"), ); console.log("B02 pickers consumption OK");