feat: establish shared field and form foundation
This commit is contained in:
@@ -36,3 +36,38 @@ it("renders the initial components without browser globals", async () => {
|
||||
expect(html).toContain('role="status"');
|
||||
expect(html).toContain('data-slot="textarea"');
|
||||
});
|
||||
|
||||
it("renders complete field associations without browser globals", async () => {
|
||||
const { TextField, Label, Description, FieldError, Form } =
|
||||
await import("../packages/vue/src");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(Form, {}, () => [
|
||||
h(
|
||||
TextField,
|
||||
{ name: "email", defaultValue: "a@example.com", isInvalid: true },
|
||||
() => [
|
||||
h(Label, {}, () => "Email"),
|
||||
h(Input),
|
||||
h(Description, {}, () => "Hint"),
|
||||
h(FieldError, {}, () => "Error"),
|
||||
],
|
||||
),
|
||||
h(TextField, { name: "notes" }, () => [
|
||||
h(Label, {}, () => "Notes"),
|
||||
h(TextArea),
|
||||
h(Description, {}, () => "Other hint"),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
const ids = [...html.matchAll(/\sid="([^"]+)"/g)].map((match) => match[1]);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
const refs = [
|
||||
...html.matchAll(/(?:for|aria-describedby)="([^"]+)"/g),
|
||||
].flatMap((match) => match[1].split(" "));
|
||||
expect(refs.length).toBeGreaterThan(3);
|
||||
for (const id of refs) expect(ids).toContain(id);
|
||||
expect(html).toContain('value="a@example.com"');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user