feat: migrate AlertDialog and Drawer with reviewed overlay lifecycles

This commit is contained in:
maoyingjie
2026-10-23 18:34:07 +08:00
parent 9f44ffb310
commit 0ec20aaa6a
83 changed files with 5871 additions and 3 deletions
+42
View File
@@ -0,0 +1,42 @@
import { afterEach, expect, it, vi } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { defineComponent, h, nextTick } from "vue";
const demos = import.meta.glob(
"../apps/docs/demos/{alert-dialog,drawer}-*.vue",
);
const wrappers: ReturnType<typeof mount>[] = [];
afterEach(async () => {
wrappers.splice(0).forEach((w) => w.unmount());
await flushPromises();
vi.restoreAllMocks();
document.body.innerHTML = "";
});
it("all 23 overlay demos coexist in one Vue app without duplicate IDs or warnings", async () => {
const entries = await Promise.all(
Object.values(demos).map(
async (load) =>
((await load()) as { default: Parameters<typeof h>[0] }).default,
),
);
expect(entries).toHaveLength(23);
const warnings = vi.spyOn(console, "warn").mockImplementation(() => {});
const wrapper = mount(
defineComponent({
render: () =>
h(
"main",
entries.map((demo, i) => h("section", { "data-demo": i }, [h(demo)])),
),
}),
{ attachTo: document.body },
);
wrappers.push(wrapper);
await flushPromises();
await nextTick();
expect(wrapper.findAll("section[data-demo]")).toHaveLength(23);
expect(wrapper.findAll("button").length).toBeGreaterThan(23);
const ids = [...document.querySelectorAll("[id]")].map((el) => el.id);
expect(new Set(ids).size).toBe(ids.length);
expect(warnings).not.toHaveBeenCalled();
});