fix(demos): restore form, overlay and toast demos to the pinned cn baseline

HD-02 scope, all against heroui ce90ea3 cn sources:

- card: add the text-primary class to the coin icons (source parity);
  card-with-form drops the added required validation and inline business
  note, restores the plain href="#" forgot-password link and the baseline
  alert("表单提交成功!") submit feedback (autocomplete kept: no visible
  impact, allowed by the task card)
- input-group-with-textarea: restore the four Tooltips and the Enter Kbd
  hint; drop the stale "Tooltip 组件尚未迁移" note from input-group.md
- alert-dialog: restore the h-px top light line in custom-styles and the
  truncated/missing description text in sizes/custom-portal/
  custom-animations (+ controlled); align the fluid-slide icon with the
  modal mapping (IconArrowBarUp for gravity-ui:arrow-up-from-line)
- toast: restore the upstream demo layout shells (variants/simple/
  custom-indicator/custom-queue) and the action button default variant:
  ToastActionButton now falls back to the Button defaults (primary/md)
  like upstream ToastActionButton, so variants' actions render primary,
  danger stays danger and default stays tertiary; toast.md defaults fixed
- submit demos: restore baseline feedback and structure — alert() for
  card/fieldset/form/checkbox/checkbox-group/switch/select/combo-box/
  autocomplete and console.log for search/number/time field form examples;
  modal-with-form returns to the close-only footer (no submit/result row);
  drop the added inline status/result rows and the max-w-full/
  max-sm:min-w-0 width guards from the restored demos
- radio-group-validation: add the missing text-muted to the result line;
  label.md invalid example gives the real control its invalid state and
  matches the baseline input shape

Tests re-pinned to the baseline contracts (alert/console/close behavior,
four tooltips + Kbd, positional modal footer); full suite 110 files /
1617 tests, typecheck, build:docs and the m35-m36 tarball contract pass.
This commit is contained in:
maoyingjie
2026-10-28 14:10:10 +08:00
parent e9760810b8
commit 53e76f676d
53 changed files with 531 additions and 572 deletions
+19 -3
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";
import { mount } from "@vue/test-utils";
import { h, nextTick, ref } from "vue";
import { readFileSync } from "node:fs";
@@ -89,6 +89,7 @@ describe("aligned examples", () => {
w.unmount();
});
it("submits actual selected values and restores Switch defaults on form reset", async () => {
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const w = mount(SwitchForm, { attachTo: document.body });
const form = w.get("form").element as HTMLFormElement;
const switches = w.findAll("[role=switch]");
@@ -98,13 +99,19 @@ describe("aligned examples", () => {
expect(new FormData(form).get("notifications")).toBe("on");
expect(new FormData(form).has("newsletter")).toBe(false);
await w.get("form").trigger("submit");
expect(w.get("output").text()).toContain("notifications: on");
// Baseline feedback: one alert carrying the real submitted entries.
expect(alert).toHaveBeenCalledTimes(1);
expect(alert.mock.calls[0][0]).toContain("表单提交内容:");
expect(alert.mock.calls[0][0]).toContain("notifications: on");
expect(alert.mock.calls[0][0]).not.toContain("newsletter");
expect(w.find("output").exists()).toBe(false);
form.reset();
await nextTick();
await nextTick();
expect(switches[0].attributes("aria-checked")).toBe("false");
expect(switches[1].attributes("aria-checked")).toBe("true");
w.unmount();
alert.mockRestore();
});
it("passes root ARIA attributes into composed SwitchContent and preserves container styles", async () => {
const name = ref("静音");
@@ -169,12 +176,21 @@ describe("aligned examples", () => {
w.unmount();
});
it("renders a working Card form using labelled native fields", async () => {
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const w = mount(CardForm);
expect(w.findAll("label")).toHaveLength(2);
// Baseline has no added required validation: the empty form submits too.
await w.get("form").trigger("submit");
expect(alert).toHaveBeenCalledWith("表单提交成功!");
expect(w.find("[role=status]").exists()).toBe(false);
await w.get("input[type=email]").setValue("test@example.com");
await w.get("input[type=password]").setValue("test-pass");
await w.get("form").trigger("submit");
expect(w.get("[role=status]").text()).toContain("表单提交成功");
expect(alert).toHaveBeenCalledTimes(2);
expect(
new FormData(w.get("form").element as HTMLFormElement).get("email"),
).toBe("test@example.com");
w.unmount();
alert.mockRestore();
});
});
+31 -8
View File
@@ -82,7 +82,13 @@ describe("Autocomplete docs and demos", () => {
expect(source, name).toContain("SearchFieldClearButton");
// The ported .hv-empty-state padding must not be overridden per demo.
expect(source, name).not.toMatch(/<EmptyState\s+class=/);
expect(source, name).not.toContain("alert(");
// Baseline feedback: only the required demo submits through the plain
// success alert, exactly like the pinned cn source.
if (name === "required") {
expect(source, name).toContain('alert("表单提交成功!")');
} else {
expect(source, name).not.toContain("alert(");
}
}
});
@@ -170,11 +176,12 @@ describe("Autocomplete docs and demos", () => {
}
});
it("submits the required and name demos", async () => {
it("blocks empty required submits and keeps the baseline success alert", async () => {
const formDemo =
(await import("../apps/docs/demos/autocomplete-required.vue")) as {
default: Component;
};
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const wrapper = mount(formDemo.default, { attachTo: document.body });
mounted.push(wrapper);
await nextTick();
@@ -191,20 +198,36 @@ describe("Autocomplete docs and demos", () => {
false,
);
// `Form` renders novalidate and guards submit itself: an empty required
// field must keep the demo's status line empty.
// field must keep the demo's baseline alert silent.
const form = pickerForm;
const submit = (
wrapper.element as HTMLElement
).querySelector<HTMLButtonElement>('button[type="submit"]')!;
submit.click();
await nextTick();
await settle();
expect(form.getAttribute("novalidate")).not.toBeNull();
expect(
(wrapper.element as HTMLElement)
.querySelector('[role="status"]')
?.textContent?.trim() ?? "",
).toBe("");
expect(alert).not.toHaveBeenCalled();
// Choose a value in both required pickers: the valid submit then fires
// the plain baseline success alert (cn/autocomplete/required.tsx).
for (const trigger of root.querySelectorAll<HTMLElement>(
'[data-slot="autocomplete-trigger"]',
)) {
trigger.dispatchEvent(new MouseEvent("click", { bubbles: true }));
await nextTick();
await settle();
const option = document.querySelector<HTMLElement>('[role="option"]')!;
option.click();
await nextTick();
await settle();
}
submit.click();
await nextTick();
await settle();
expect(alert).toHaveBeenCalledTimes(1);
expect(alert).toHaveBeenCalledWith("表单提交成功!");
wrapper.unmount();
mounted.pop();
alert.mockRestore();
});
});
+6 -3
View File
@@ -458,19 +458,22 @@ it("keeps the baseline preview inventories and exact fieldset submission feedbac
).toContain("<template>");
const { default: Demo } =
await import("../apps/docs/demos/fieldset-basic.vue");
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const w = mount(Demo, { attachTo: document.body });
await w.get("input[name=name]").setValue("Jane");
await w.get("input[name=email]").setValue("jane@example.com");
await w.get("textarea").setValue("A detailed biography.");
(w.get("form").element as HTMLFormElement).requestSubmit();
await settle();
const status = w.get('[role="status"]');
expect(status.text()).toContain('"name":"Jane"');
expect(status.text()).toContain('"email":"jane@example.com"');
// Baseline feedback: the plain success alert, no inline result row.
expect(alert).toHaveBeenCalledTimes(1);
expect(alert).toHaveBeenCalledWith("表单提交成功!");
expect(w.find('[role="status"]').exists()).toBe(false);
await w.get('button[type="reset"]').trigger("click");
await settle();
expect((w.get("input[name=name]").element as HTMLInputElement).value).toBe(
"",
);
alert.mockRestore();
w.unmount();
});
+9 -10
View File
@@ -242,8 +242,9 @@ describe("Form public validation", () => {
describe("Form fixed-source demos", () => {
it.each([FormBasic, FormRenderFunction])(
"validates both fields, submits exact data, and resets values/errors/results",
"validates both fields, submits exact data via the baseline alert, and resets values/errors",
async (Demo) => {
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const w = mount(Demo, { attachTo: document.body });
wrappers.push(w);
const form = w.get("form").element as HTMLFormElement;
@@ -268,19 +269,17 @@ describe("Form fixed-source demos", () => {
submit(form);
await settle();
expect(w.get("[data-slot=field-error]").text()).toBe(error);
expect(w.find('[role="status"]').exists()).toBe(false);
expect(alert).not.toHaveBeenCalled();
}
await password.setValue("Password1");
await settle();
submit(form);
await settle();
expect(w.get('[role="status"]').text()).toContain("表单提交数据:");
expect(w.get('[role="status"]').text()).toContain(
'"email": "john@example.com"',
);
expect(w.get('[role="status"]').text()).toContain(
'"password": "Password1"',
);
expect(alert).toHaveBeenCalledTimes(1);
const message = alert.mock.calls[0][0] as string;
expect(message).toContain("表单提交数据:");
expect(message).toContain('"email": "john@example.com"');
expect(message).toContain('"password": "Password1"');
expect([...new FormData(form)]).toEqual([
["email", "john@example.com"],
["password", "Password1"],
@@ -290,8 +289,8 @@ describe("Form fixed-source demos", () => {
expect((email.element as HTMLInputElement).value).toBe("");
expect((password.element as HTMLInputElement).value).toBe("");
expect(w.find("[data-slot=field-error]").exists()).toBe(false);
expect(w.find('[role="status"]').exists()).toBe(false);
if (Demo === FormRenderFunction) expect(form.dataset.custom).toBe("foo");
alert.mockRestore();
},
);
+5 -1
View File
@@ -445,7 +445,11 @@ describe("M12 demo inventory", () => {
"utf8",
);
expect(textarea).toContain("InputGroupTextArea");
expect(textarea).not.toContain("Tooltip");
// Baseline tooltip contract: the four tooltips are restored (with the
// Enter Kbd hint on the send action) instead of native title attributes.
expect(textarea.match(/<Tooltip\b/g) ?? []).toHaveLength(4);
expect(textarea).toContain('key-value="enter"');
expect(textarea).not.toContain('title="');
});
});
+10 -5
View File
@@ -64,7 +64,7 @@ it("matches the exact baseline 14/6/6 preview inventory and compiles/mounts thei
}
});
it("submits real form data and reports it without pretending to send a network message", async () => {
it("keeps the baseline close-only footer and real named form fields", async () => {
const demo = demos["../apps/docs/demos/modal-with-form.vue"] as Component;
const w = mount(demo, { attachTo: document.body });
try {
@@ -78,12 +78,17 @@ it("submits real form data and reports it without pretending to send a network m
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 }),
);
// Baseline contract: the footer buttons only close the dialog — the
// example performs no submit and renders no result row.
const send = [
...document.querySelectorAll<HTMLButtonElement>("button"),
].find((button) => button.textContent?.trim() === "发送消息")!;
expect(send).toBeDefined();
send.click();
await flushPromises();
expect(w.get("[role=status]").text()).toContain("Vue用户");
expect(document.querySelector("[role=dialog]")).toBeNull();
expect(w.find("[role=status]").exists()).toBe(false);
expect(w.text()).not.toContain("已记录表单");
} finally {
w.unmount();
await flushPromises();
+11 -2
View File
@@ -72,10 +72,11 @@ describe("TimeField documentation", () => {
w.unmount();
}
});
it("validates business hours and submits the actual value with loading/reset feedback", async () => {
it("validates business hours and submits the actual value with baseline console feedback", async () => {
const w = mount(
demos["../apps/docs/demos/time-field-form-example.vue"] as never,
);
const log = vi.spyOn(console, "log").mockImplementation(() => {});
try {
const input = w.get('[data-slot="time-field-value"]');
await input.setValue("08:30");
@@ -94,12 +95,20 @@ describe("TimeField documentation", () => {
await w.get("form").trigger("submit");
expect(w.get("button").text()).toBe("提交中…");
await vi.advanceTimersByTimeAsync(1500);
expect(w.get("output").text()).toBe("已提交:14:30:45");
// Baseline feedback: the submitted time is logged to the console and
// the field clears; there is no inline output row.
expect(log).toHaveBeenCalledTimes(1);
expect(log.mock.calls[0][0]).toBe("Time submitted:");
expect(String((log.mock.calls[0][1] as { time: unknown }).time)).toBe(
"14:30:45",
);
expect(w.find("output").exists()).toBe(false);
expect((input.element as HTMLInputElement).value).toBe("");
expect(w.get('[data-type="hour"]').attributes("data-placeholder")).toBe(
"true",
);
} finally {
log.mockRestore();
w.unmount();
}
});