import { describe, expect, it } from "vitest"; import { mount, flushPromises } from "@vue/test-utils"; import { readFileSync } from "node:fs"; const demos = import.meta.glob("../apps/docs/demos/date-field-*.vue", { eager: true, import: "default", }); const expected = [ "basic", "with-prefix-icon", "with-suffix-icon", "with-prefix-and-suffix", "variants", "on-surface", "with-description", "required", "disabled", "full-width", "invalid", "granularity", "controlled", "form-example", "with-validation", "render-function", "custom-styles", ]; describe("DateField documentation", () => { it("includes every pinned preview and uses the displayed SFC as its implementation", () => { const md = readFileSync("apps/docs/components/date-field.md", "utf8"); expect( [...md.matchAll(/ match[1], ), ).toEqual(expected); expect(md).not.toContain("[!toc]"); expect(Object.keys(demos)).toHaveLength(17); }); it("mounts all seventeen examples without warnings or missing date controls", async () => { const warnings: string[] = []; for (const demo of Object.values(demos)) { const w = mount(demo as never, { global: { config: { warnHandler: (message) => warnings.push(message) }, }, }); await flushPromises(); expect(w.find('[data-slot="date-field"]').exists()).toBe(true); expect(w.find('[data-slot="date-input-group-segment"]').exists()).toBe( true, ); w.unmount(); } expect(warnings).toEqual([]); }); }); it("the controlled example's action buttons update and clear the real date", async () => { const component = demos["../apps/docs/demos/date-field-controlled.vue"]; const w = mount(component as never); try { await w.get("button").trigger("click"); await flushPromises(); expect( (w.get('[data-slot="date-field-value"]').element as HTMLInputElement) .value, ).toMatch(/^\d{4}-\d{2}-\d{2}$/); expect(w.get('[data-slot="description"]').text()).not.toContain("(空)"); await w.findAll("button")[1].trigger("click"); await flushPromises(); expect(w.get('[data-slot="description"]').text()).toContain("(空)"); expect(w.findAll('[data-placeholder="true"]')).toHaveLength(3); } finally { w.unmount(); } });