fix(demos): snapshot validated values before asynchronous submissions

This commit is contained in:
maoyingjie
2026-10-28 15:05:09 +08:00
parent 49dd67afac
commit b0f32796cb
6 changed files with 102 additions and 3 deletions
+32
View File
@@ -113,3 +113,35 @@ describe("TimeField documentation", () => {
}
});
});
it.each(["15:30:00", "08:00:00"])(
"keeps the submitted time-field snapshot when pending input changes to %s",
async (changed) => {
const { default: Demo } =
await import("../apps/docs/demos/time-field-form-example.vue");
const w = mount(Demo, { attachTo: document.body });
const log = vi.spyOn(console, "log").mockImplementation(() => {});
vi.useFakeTimers();
try {
const input = w.get("[data-slot=time-field-value]");
await input.setValue("14:30:00");
await input.trigger("blur");
await w.get("form").trigger("submit");
expect(w.get('button[type="submit"]').text()).toContain("…");
await input.setValue(changed);
await input.trigger("blur");
await w.get("form").trigger("submit");
await vi.advanceTimersByTimeAsync(1500);
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:00",
);
expect((input.element as HTMLInputElement).value).toBe("");
} finally {
w.unmount();
log.mockRestore();
vi.useRealTimers();
}
},
);