fix: complete field and OTP public contracts (HD-07)
This commit is contained in:
@@ -463,3 +463,141 @@ it("native Switch overrides an aria Form and blocks invalid submission", async (
|
||||
expect(w.get("[role=switch]").attributes("aria-invalid")).toBe("true");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("TextField autoFocus and focus-within cover moves between child controls", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(
|
||||
TextField,
|
||||
{ autoFocus: true },
|
||||
{
|
||||
default: (state: Record<string, unknown>) => [
|
||||
h(Input),
|
||||
h("button", { type: "button" }, "inside"),
|
||||
h("output", String(state.isFocusWithin)),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
expect(document.activeElement).toBe(w.get("input").element);
|
||||
expect(
|
||||
w.get('[data-slot="textfield"]').attributes("data-focus-within"),
|
||||
).toBe("true");
|
||||
(w.get("button").element as HTMLButtonElement).focus();
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("true");
|
||||
(w.get("button").element as HTMLButtonElement).blur();
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("false");
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
it("field and Form errors merge in order, dismiss on edit/reset, and a new response reappears", async () => {
|
||||
const local = ref(["local"]),
|
||||
server = ref({ name: "server" });
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Form, { validationErrors: server.value }, () =>
|
||||
h(TextField, { name: "name", validationErrors: local.value }, () => [
|
||||
h(Input),
|
||||
h(
|
||||
FieldError,
|
||||
{},
|
||||
{
|
||||
default: (s: {
|
||||
validationErrors: string[];
|
||||
validationDetails?: ValidityState;
|
||||
}) =>
|
||||
`${s.validationErrors.join("|")}:${s.validationDetails?.customError}`,
|
||||
},
|
||||
),
|
||||
]),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
expect(w.get('[role="alert"]').text()).toBe("local|server:true");
|
||||
expect((w.get("input").element as HTMLInputElement).checkValidity()).toBe(
|
||||
false,
|
||||
);
|
||||
await w.get("input").setValue("edit");
|
||||
await settle();
|
||||
expect(w.find('[role="alert"]').exists()).toBe(false);
|
||||
local.value = ["new local"];
|
||||
server.value = { name: "new server" };
|
||||
await settle();
|
||||
expect(w.get('[role="alert"]').text()).toBe("new local|new server:true");
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await settle();
|
||||
expect(w.find('[role="alert"]').exists()).toBe(false);
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
it("TextField FieldError exposes native validity flags for required input", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(TextField, { isRequired: true }, () => [
|
||||
h(Input),
|
||||
h(
|
||||
FieldError,
|
||||
{},
|
||||
{
|
||||
default: (s: { validationDetails?: ValidityState }) =>
|
||||
String(s.validationDetails?.valueMissing),
|
||||
},
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
(w.get("input").element as HTMLInputElement).checkValidity();
|
||||
await settle();
|
||||
expect(w.get('[role="alert"]').text()).toBe("true");
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("TextField validity details update when native constraints change without an edit", async () => {
|
||||
const pattern = ref("[0-9]+");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(
|
||||
TextField,
|
||||
{ defaultValue: "123", pattern: pattern.value },
|
||||
{
|
||||
default: (state: { validationDetails: ValidityState }) => [
|
||||
h(Input),
|
||||
h("output", String(state.validationDetails.patternMismatch)),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("false");
|
||||
pattern.value = "[a-z]+";
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("true");
|
||||
pattern.value = "[0-9]+";
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("false");
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user