import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { mount, flushPromises } from "@vue/test-utils"; import { readFileSync } from "node:fs"; import Basic from "../apps/docs/demos/color-picker-basic.vue"; import Controlled from "../apps/docs/demos/color-picker-controlled.vue"; import WithSwatches from "../apps/docs/demos/color-picker-with-swatches.vue"; import WithFields from "../apps/docs/demos/color-picker-with-fields.vue"; import WithSliders from "../apps/docs/demos/color-picker-with-sliders.vue"; import CustomStyles from "../apps/docs/demos/color-picker-custom-styles.vue"; const mounted: ReturnType[] = []; beforeEach(() => vi.stubGlobal( "ResizeObserver", class { observe() {} unobserve() {} disconnect() {} }, ), ); afterEach(async () => { mounted.splice(0).forEach((w) => w.unmount()); await flushPromises(); document.body.innerHTML = ""; vi.unstubAllGlobals(); vi.restoreAllMocks(); }); function render(component: Parameters[0]) { const w = mount(component, { attachTo: document.body }); mounted.push(w); return w; } async function open(w: ReturnType) { await w.get("[data-slot=color-picker-trigger]").trigger("click"); await flushPromises(); expect(document.querySelector("[role=dialog]")).not.toBeNull(); } const previews = [ "basic", "controlled", "with-swatches", "with-fields", "with-sliders", "custom-styles", ]; const items = () => Array.from( document.querySelectorAll("[data-slot=color-swatch-picker-item]"), ); const labels = () => Array.from(document.querySelectorAll("[data-slot=label]")).map( (node) => node.textContent?.trim(), ); describe("ColorPicker documentation demos", () => { it("keeps the six pinned previews in the fixed source order", () => { const document = readFileSync("apps/docs/components/color-picker.md", "utf8"); const names = [ ...document.matchAll(/ match[1]); expect(names).toEqual(previews); for (const name of previews) { const source = readFileSync( `apps/docs/demos/color-picker-${name}.vue`, "utf8", ); expect(source).toContain("