Skip to content

Commit 75b8541

Browse files
Jeffrey Lauwersclaude
andcommitted
Fix FormField and CheckboxGroup tests
Updated tests to match the new component architecture: - FormField now always renders div/label (removed isGroup prop tests) - CheckboxGroup now renders div container (removed fieldset/legend tests) - FormFieldset component should be tested separately for fieldset/legend behavior Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 876e233 commit 75b8541

2 files changed

Lines changed: 116 additions & 277 deletions

File tree

packages/components-react/src/CheckboxGroup/CheckboxGroup.test.tsx

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,20 @@ import { CheckboxGroup } from './CheckboxGroup';
44
import { CheckboxOption } from '../CheckboxOption';
55

66
describe('CheckboxGroup', () => {
7-
it('renders a fieldset element', () => {
7+
it('renders a div element', () => {
88
const { container } = render(
9-
<CheckboxGroup legend="Test Group">
9+
<CheckboxGroup>
1010
<CheckboxOption label="Option 1" value="1" />
1111
</CheckboxGroup>
1212
);
13-
expect(container.querySelector('fieldset')).toBeInTheDocument();
14-
});
15-
16-
it('renders the legend', () => {
17-
render(
18-
<CheckboxGroup legend="My Group">
19-
<CheckboxOption label="Option 1" value="1" />
20-
</CheckboxGroup>
21-
);
22-
expect(screen.getByText('My Group')).toBeInTheDocument();
13+
expect(
14+
container.querySelector('div.dsn-checkbox-group')
15+
).toBeInTheDocument();
2316
});
2417

2518
it('renders children', () => {
2619
render(
27-
<CheckboxGroup legend="Test Group">
20+
<CheckboxGroup>
2821
<CheckboxOption label="Option 1" value="1" />
2922
<CheckboxOption label="Option 2" value="2" />
3023
</CheckboxGroup>
@@ -35,55 +28,34 @@ describe('CheckboxGroup', () => {
3528

3629
it('applies custom className', () => {
3730
const { container } = render(
38-
<CheckboxGroup legend="Test Group" className="custom-class">
31+
<CheckboxGroup className="custom-class">
3932
<CheckboxOption label="Option 1" value="1" />
4033
</CheckboxGroup>
4134
);
4235
expect(container.querySelector('.custom-class')).toBeInTheDocument();
4336
});
4437

45-
it('hides legend visually when hideLegend is true', () => {
46-
render(
47-
<CheckboxGroup legend="Hidden Legend" hideLegend>
48-
<CheckboxOption label="Option 1" value="1" />
49-
</CheckboxGroup>
50-
);
51-
const legend = screen.getByText('Hidden Legend');
52-
expect(legend).toHaveClass('dsn-visually-hidden');
53-
});
54-
55-
it('shows legend when hideLegend is false', () => {
56-
render(
57-
<CheckboxGroup legend="Visible Legend" hideLegend={false}>
58-
<CheckboxOption label="Option 1" value="1" />
59-
</CheckboxGroup>
60-
);
61-
const legend = screen.getByText('Visible Legend');
62-
expect(legend).not.toHaveClass('dsn-visually-hidden');
63-
});
64-
65-
it('forwards ref to fieldset element', () => {
66-
const ref = React.createRef<HTMLFieldSetElement>();
38+
it('forwards ref to div element', () => {
39+
const ref = React.createRef<HTMLDivElement>();
6740
render(
68-
<CheckboxGroup legend="Test Group" ref={ref}>
41+
<CheckboxGroup ref={ref}>
6942
<CheckboxOption label="Option 1" value="1" />
7043
</CheckboxGroup>
7144
);
72-
expect(ref.current).toBeInstanceOf(HTMLFieldSetElement);
45+
expect(ref.current).toBeInstanceOf(HTMLDivElement);
7346
});
7447

75-
it('passes through fieldset attributes', () => {
48+
it('passes through div attributes', () => {
7649
const { container } = render(
7750
<CheckboxGroup
78-
legend="Test Group"
79-
disabled
8051
aria-describedby="description"
52+
data-testid="checkbox-group"
8153
>
8254
<CheckboxOption label="Option 1" value="1" />
8355
</CheckboxGroup>
8456
);
85-
const fieldset = container.querySelector('fieldset');
86-
expect(fieldset).toHaveAttribute('disabled');
87-
expect(fieldset).toHaveAttribute('aria-describedby', 'description');
57+
const div = container.querySelector('.dsn-checkbox-group');
58+
expect(div).toHaveAttribute('aria-describedby', 'description');
59+
expect(div).toHaveAttribute('data-testid', 'checkbox-group');
8860
});
8961
});

0 commit comments

Comments
 (0)