feat: migrate Modal Popover and Tooltip with shared overlay foundation
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { readFileSync } from "node:fs";
|
||||
const demos = import.meta.glob(
|
||||
"../apps/docs/demos/{modal,popover,tooltip}-*.vue",
|
||||
{ eager: true, import: "default" },
|
||||
);
|
||||
const docs = import.meta.glob("./fixtures/overlay-*-structure.vue", {
|
||||
eager: true,
|
||||
import: "default",
|
||||
});
|
||||
import type { Component } from "vue";
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
it("matches the exact baseline 14/6/6 preview inventory and compiles/mounts their shared SFCs", async () => {
|
||||
vi.stubGlobal(
|
||||
"ResizeObserver",
|
||||
class {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
},
|
||||
);
|
||||
const errors = vi.spyOn(console, "error").mockImplementation(() => {}),
|
||||
warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
try {
|
||||
for (const family of ["modal", "popover", "tooltip"]) {
|
||||
const baseline = readFileSync(
|
||||
`../heroui/apps/docs/content/docs/cn/react/components/(overlays)/${family}.mdx`,
|
||||
"utf8",
|
||||
);
|
||||
const current = readFileSync(`apps/docs/components/${family}.md`, "utf8");
|
||||
const names = [
|
||||
...baseline.matchAll(/<ComponentPreview\s+name="([^"]+)"/g),
|
||||
].map((m) => m[1]);
|
||||
expect(
|
||||
[...current.matchAll(/<ComponentPreview\s+name="([^"]+)"/g)].map(
|
||||
(m) => m[1],
|
||||
),
|
||||
).toEqual(names);
|
||||
expect(names).toHaveLength(family === "modal" ? 14 : 6);
|
||||
for (const name of names) {
|
||||
const component = demos[`../apps/docs/demos/${name}.vue`] as Component;
|
||||
expect(component, name).toBeDefined();
|
||||
const w = mount(component, { attachTo: document.body });
|
||||
await flushPromises();
|
||||
w.unmount();
|
||||
await flushPromises();
|
||||
}
|
||||
}
|
||||
for (const component of Object.values(docs)) {
|
||||
const w = mount(component as Component, { attachTo: document.body });
|
||||
await flushPromises();
|
||||
w.unmount();
|
||||
await flushPromises();
|
||||
}
|
||||
expect(warn.mock.calls).toEqual([]);
|
||||
expect(errors.mock.calls).toEqual([]);
|
||||
} finally {
|
||||
errors.mockRestore();
|
||||
warn.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("submits real form data and reports it without pretending to send a network message", async () => {
|
||||
const demo = demos["../apps/docs/demos/modal-with-form.vue"] as Component;
|
||||
const w = mount(demo, { attachTo: document.body });
|
||||
try {
|
||||
await w.get("button").trigger("click");
|
||||
await flushPromises();
|
||||
const field = document.querySelector(
|
||||
"input[name=name]",
|
||||
) as HTMLInputElement;
|
||||
expect(field).not.toBeNull();
|
||||
field.value = "Vue用户";
|
||||
field.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
const form = document.querySelector("form")!;
|
||||
expect(new FormData(form).get("name")).toBe("Vue用户");
|
||||
form.dispatchEvent(
|
||||
new Event("submit", { bubbles: true, cancelable: true }),
|
||||
);
|
||||
await flushPromises();
|
||||
expect(w.get("[role=status]").text()).toContain("Vue用户");
|
||||
expect(document.querySelector("[role=dialog]")).toBeNull();
|
||||
} finally {
|
||||
w.unmount();
|
||||
await flushPromises();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user