import { afterEach, describe, expect, it, vi } from "vitest"; import { mount, flushPromises } from "@vue/test-utils"; import { defineComponent } from "vue"; import { ComboBox, ComboBoxInputGroup, ComboBoxPopover, ComboBoxTrigger, Input, ListBox, ListBoxItem, Autocomplete, AutocompleteTrigger, AutocompletePopover, AutocompleteFilter, SearchField, SearchFieldInput, } from "../packages/vue/src"; import { createBaseContains } from "../packages/vue/src/components/collection/match"; const components = { ComboBox, ComboBoxInputGroup, ComboBoxPopover, ComboBoxTrigger, Input, ListBox, ListBoxItem, Autocomplete, AutocompleteTrigger, AutocompletePopover, AutocompleteFilter, SearchField, SearchFieldInput, }; const roots: ReturnType[] = []; afterEach(() => { roots.splice(0).forEach((w) => w.unmount()); document.body.innerHTML = ""; vi.restoreAllMocks(); }); function view(template: string) { const w = mount(defineComponent({ components, template }), { attachTo: document.body, }); roots.push(w); return w; } describe("public picker integration", () => { it("retains Vue string template refs on the actual composed Input and clears them on removal", async () => { const w = view( 'Alpha', ); await flushPromises(); expect((w.vm.$refs.consumerInput as { $el: Element }).$el).toBe( w.get("input[role=combobox]").element, ); w.unmount(); roots.splice(roots.indexOf(w), 1); expect(w.vm.$refs.consumerInput).toBeNull(); }); it("retains a string template ref on the teleported search input", async () => { const w = view( 'ChooseAlpha', ); await flushPromises(); expect((w.vm.$refs.consumerSearch as { $el: Element }).$el).toBe( document.querySelector("input[role=combobox]"), ); }); it("preserves an accessible name declared on the inner SearchField root", async () => { view( 'ChooseAlpha', ); await flushPromises(); expect( document .querySelector("input[role=combobox]") ?.getAttribute("aria-label"), ).toBe("Search options"); }); it("respects a caller-disabled Autocomplete trigger before opening", async () => { const w = view( 'ChooseAlpha', ); await w.get('[data-slot="autocomplete-trigger"]').trigger("click"); expect( w.get('[data-slot="autocomplete-trigger"]').attributes("aria-expanded"), ).toBe("false"); expect( w.get('[data-slot="autocomplete-trigger"]').attributes("aria-disabled"), ).toBe("true"); }); }); it.each([ ["tr", "İstanbul", "istanbul", true], ["tr", "Isparta", "ısparta", true], ["tr", "Isparta", "isparta", false], ["de", "Fußgänger", "fuss", true], ["en", "Café", "cafe\u0301", true], ])("locale filter %s: %s / %s", (locale, text, query, expected) => { expect(createBaseContains(locale)(text, query)).toBe(expected); });