feat: add Checkbox and Radio field families
This commit is contained in:
@@ -144,3 +144,53 @@ it("renders disabled fieldsets and search fields without browser globals", async
|
||||
expect(html).toContain('data-slot="search-field-clear-button"');
|
||||
expect(html).toContain('data-disabled="true"');
|
||||
});
|
||||
|
||||
it("renders choice groups and nested content associations without browser globals", async () => {
|
||||
const {
|
||||
CheckboxGroup,
|
||||
Checkbox,
|
||||
CheckboxContent,
|
||||
RadioGroup,
|
||||
Radio,
|
||||
RadioContent,
|
||||
Label,
|
||||
Description,
|
||||
} = await import("../packages/vue/src");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h("form", {}, [
|
||||
h(
|
||||
CheckboxGroup,
|
||||
{ name: "features", defaultValue: ["a"], isRequired: true },
|
||||
() => [
|
||||
h(Label, {}, () => "Features"),
|
||||
h(Checkbox, { value: "a" }, () =>
|
||||
h(CheckboxContent, {}, () => [
|
||||
"A",
|
||||
h(Description, {}, () => "Nested hint"),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
h(RadioGroup, { name: "plan", defaultValue: "pro" }, () => [
|
||||
h(Label, {}, () => "Plan"),
|
||||
h(Radio, { value: "basic" }, () =>
|
||||
h(RadioContent, {}, () => "Basic"),
|
||||
),
|
||||
h(Radio, { value: "pro" }, () => h(RadioContent, {}, () => "Pro")),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('name="features"');
|
||||
expect(html).toContain('name="plan"');
|
||||
expect(html).toContain('value="pro" checked');
|
||||
const ids = [...html.matchAll(/\sid="([^"]+)"/g)].map((m) => m[1]);
|
||||
const refs = [
|
||||
...html.matchAll(/aria-(?:labelledby|describedby)="([^"]+)"/g),
|
||||
].flatMap((m) => m[1].split(" "));
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
expect(refs.length).toBeGreaterThan(2);
|
||||
for (const id of refs) expect(ids).toContain(id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user