// @vitest-environment node import { describe, expect, it } from "vitest"; import { createSSRApp, defineComponent, h } from "vue"; import { renderToString } from "@vue/server-renderer"; import Foundation from "../packages/vue/tests/fixtures/CollectionFoundation.vue"; import SelectFoundation from "../packages/vue/tests/fixtures/SelectFoundation.vue"; import { useCollectionRegistry } from "../packages/vue/src/components/collection/registry"; import { useCollectionSelection } from "../packages/vue/src/components/collection/selection"; describe("collection foundation in real node SSR", () => { it("renders typed selection without browser globals", async () => { expect(typeof window).toBe("undefined"); const html = await renderToString( createSSRApp(Foundation, { multiple: true, modelValue: [0] }), ); expect(html).toContain('role="listbox"'); expect(html.match(/aria-selected="true"/g)).toHaveLength(1); expect(html.match(/role="option"/g)).toHaveLength(3); }); it("keeps instance registries isolated with no DOM access", async () => { const Component = defineComponent({ setup() { const registry = useCollectionRegistry(); registry.register({ key: () => 0, element: () => undefined, textValue: () => "Zero", disabled: () => false, }); const state = useCollectionSelection({ mode: () => "single", controlled: () => false, value: () => undefined, defaultValue: [0], onChange: () => {}, }); return () => h("output", `${registry.ordered().length}:${state.keys.value[0]}`); }, }); const html = await renderToString( createSSRApp({ render: () => h("main", [h(Component), h(Component)]) }), ); expect(html).toBe("
1:01:0
"); }); it("records that raw closed Select cannot SSR its selected item label", async () => { const html = await renderToString( createSSRApp(SelectFoundation, { defaultValue: 0, name: "choice" }), ); expect(html).toContain('role="combobox"'); expect(html).not.toContain("Numeric zero"); // ItemText registers options on mount; SSR cannot discover closed descendants. expect(html).not.toContain('