Skip to content

Commit 1754d73

Browse files
Jeffrey Lauwersclaude
andcommitted
Fix RadioGroup tests to match new architecture
Updated RadioGroup tests to match the refactored component: - RadioGroup now renders div container (removed fieldset/legend tests) - Removed legend and hideLegend prop tests - FormFieldset component should be tested separately for fieldset/legend behavior All 613 tests now passing ✅ Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 75b8541 commit 1754d73

1 file changed

Lines changed: 14 additions & 43 deletions

File tree

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

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,18 @@ import { RadioGroup } from './RadioGroup';
44
import { RadioOption } from '../RadioOption';
55

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

2516
it('renders children', () => {
2617
render(
27-
<RadioGroup legend="Test Group">
18+
<RadioGroup>
2819
<RadioOption name="test" label="Option 1" value="1" />
2920
<RadioOption name="test" label="Option 2" value="2" />
3021
</RadioGroup>
@@ -35,51 +26,31 @@ describe('RadioGroup', () => {
3526

3627
it('applies custom className', () => {
3728
const { container } = render(
38-
<RadioGroup legend="Test Group" className="custom-class">
29+
<RadioGroup className="custom-class">
3930
<RadioOption name="test" label="Option 1" value="1" />
4031
</RadioGroup>
4132
);
4233
expect(container.querySelector('.custom-class')).toBeInTheDocument();
4334
});
4435

45-
it('hides legend visually when hideLegend is true', () => {
46-
render(
47-
<RadioGroup legend="Hidden Legend" hideLegend>
48-
<RadioOption name="test" label="Option 1" value="1" />
49-
</RadioGroup>
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-
<RadioGroup legend="Visible Legend" hideLegend={false}>
58-
<RadioOption name="test" label="Option 1" value="1" />
59-
</RadioGroup>
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>();
36+
it('forwards ref to div element', () => {
37+
const ref = React.createRef<HTMLDivElement>();
6738
render(
68-
<RadioGroup legend="Test Group" ref={ref}>
39+
<RadioGroup ref={ref}>
6940
<RadioOption name="test" label="Option 1" value="1" />
7041
</RadioGroup>
7142
);
72-
expect(ref.current).toBeInstanceOf(HTMLFieldSetElement);
43+
expect(ref.current).toBeInstanceOf(HTMLDivElement);
7344
});
7445

75-
it('passes through fieldset attributes', () => {
46+
it('passes through div attributes', () => {
7647
const { container } = render(
77-
<RadioGroup legend="Test Group" disabled aria-describedby="description">
48+
<RadioGroup aria-describedby="description" data-testid="radio-group">
7849
<RadioOption name="test" label="Option 1" value="1" />
7950
</RadioGroup>
8051
);
81-
const fieldset = container.querySelector('fieldset');
82-
expect(fieldset).toHaveAttribute('disabled');
83-
expect(fieldset).toHaveAttribute('aria-describedby', 'description');
52+
const div = container.querySelector('.dsn-radio-group');
53+
expect(div).toHaveAttribute('aria-describedby', 'description');
54+
expect(div).toHaveAttribute('data-testid', 'radio-group');
8455
});
8556
});

0 commit comments

Comments
 (0)