test(RadioGroup): improve

This commit is contained in:
Benjamin Canac
2024-05-29 14:41:23 +02:00
parent dfc63b1bc0
commit ff77967fd7
2 changed files with 42 additions and 13 deletions

View File

@@ -13,21 +13,23 @@ describe('RadioGroup', () => {
{ value: '3', label: 'Option 3' }
]
const props = { items }
it.each([
['with items', { props: { items } }],
['with defaultValue', { props: { items, defaultValue: '1' } }],
['with disabled', { props: { items, disabled: true } }],
['with items', { props }],
['with defaultValue', { props: { ...props, defaultValue: '1' } }],
['with disabled', { props: { ...props, disabled: true } }],
['with description', { props: { items: items.map((opt, count) => ({ ...opt, description: `Description ${count}` })) } }],
['with required', { props: { items, legend: 'Legend', required: true } }],
...sizes.map((size: string) => [`with size ${size}`, { props: { items, size } }]),
...colors.map((color: string) => [`with color ${color}`, { props: { items, color } }]),
['with class', { props: { items, class: 'absolute' } }],
['with ui', { props: { ui: { items, wrapper: 'ms-4' } } }],
['with orientation', { props: { items, orientation: 'horizontal' } }],
['with required', { props: { ...props, legend: 'Legend', required: true } }],
...sizes.map((size: string) => [`with size ${size}`, { props: { ...props, size } }]),
...colors.map((color: string) => [`with color ${color}`, { props: { ...props, color } }]),
['with class', { props: { ...props, class: 'absolute' } }],
['with ui', { props: { ...props, ui: { wrapper: 'ms-4' } } }],
['with orientation', { props: { ...props, orientation: 'horizontal' } }],
// Slots
['with legend slot', { props: { items }, slots: { label: () => 'Legend slot' } }],
['with label slot', { props: { items }, slots: { label: () => 'Label slot' } }],
['with description slot', { props: { items }, slots: { label: () => 'Description slot' } }]
['with legend slot', { props, slots: { label: () => 'Legend slot' } }],
['with label slot', { props, slots: { label: () => 'Label slot' } }],
['with description slot', { props, slots: { label: () => 'Description slot' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: RadioGroupProps<any>, slots?: Partial<RadioGroupSlots<any>> }) => {
const html = await ComponentRender(nameOrHtml, options, RadioGroup)
expect(html).toMatchSnapshot()

View File

@@ -665,9 +665,36 @@ exports[`RadioGroup > renders with size xs correctly 1`] = `
`;
exports[`RadioGroup > renders with ui correctly 1`] = `
"<div role="radiogroup" required="false" aria-orientation="vertical" aria-required="false" dir="ltr" tabindex="-1" data-orientation="vertical" style="outline-color: none; outline-style: none; outline-width: initial;" id="15" class="relative">
"<div role="radiogroup" required="false" aria-orientation="vertical" aria-required="false" dir="ltr" data-orientation="vertical" style="outline-color: none; outline-style: none; outline-width: initial;" id="15" class="relative" tabindex="0">
<fieldset class="flex flex-col gap-1">
<!--v-if-->
<div class="flex items-start text-sm">
<div class="flex items-center h-5"><button class="rounded-full ring ring-inset ring-gray-300 dark:ring-gray-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:outline-primary-400 size-4" data-radix-vue-collection-item="" tabindex="-1" data-orientation="vertical" data-active="false" id="15:1" role="radio" type="button" aria-checked="false" data-state="unchecked" required="false" value="1" aria-label="1">
<!---->
<!---->
</button></div>
<div class="ms-4"><label for="15:1" class="block font-medium text-gray-700 dark:text-gray-200">Option 1</label>
<!--v-if-->
</div>
</div>
<div class="flex items-start text-sm">
<div class="flex items-center h-5"><button class="rounded-full ring ring-inset ring-gray-300 dark:ring-gray-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:outline-primary-400 size-4" data-radix-vue-collection-item="" tabindex="-1" data-orientation="vertical" data-active="false" id="15:2" role="radio" type="button" aria-checked="false" data-state="unchecked" required="false" value="2" aria-label="2">
<!---->
<!---->
</button></div>
<div class="ms-4"><label for="15:2" class="block font-medium text-gray-700 dark:text-gray-200">Option 2</label>
<!--v-if-->
</div>
</div>
<div class="flex items-start text-sm">
<div class="flex items-center h-5"><button class="rounded-full ring ring-inset ring-gray-300 dark:ring-gray-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:outline-primary-400 size-4" data-radix-vue-collection-item="" tabindex="-1" data-orientation="vertical" data-active="false" id="15:3" role="radio" type="button" aria-checked="false" data-state="unchecked" required="false" value="3" aria-label="3">
<!---->
<!---->
</button></div>
<div class="ms-4"><label for="15:3" class="block font-medium text-gray-700 dark:text-gray-200">Option 3</label>
<!--v-if-->
</div>
</div>
</fieldset>
</div>"
`;