fix(demos): snapshot validated values before asynchronous submissions
This commit is contained in:
@@ -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();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user