|
8 | 8 | import React from 'react';
|
9 | 9 | import TileGroup from '../TileGroup';
|
10 | 10 | import RadioTile from '../../RadioTile/RadioTile';
|
| 11 | +import Button from '../../Button'; |
11 | 12 | import userEvent from '@testing-library/user-event';
|
12 | 13 | import { render, screen } from '@testing-library/react';
|
13 | 14 | import { FeatureFlags } from '../../FeatureFlags';
|
@@ -94,6 +95,39 @@ describe('TileGroup', () => {
|
94 | 95 | expect(screen.getByDisplayValue('test-2')).toBeRequired();
|
95 | 96 | });
|
96 | 97 |
|
| 98 | + it('should handle non-RadioTile (null) children', async () => { |
| 99 | + const ToggleableRadioTiles = () => { |
| 100 | + const [showSecondTile, setShowSecondTile] = React.useState(true); |
| 101 | + return ( |
| 102 | + <> |
| 103 | + <Button onClick={() => setShowSecondTile(!showSecondTile)}> |
| 104 | + Toggle second tile |
| 105 | + </Button> |
| 106 | + |
| 107 | + <TileGroup defaultSelected="test-1" legend="TestGroup" name="test"> |
| 108 | + <RadioTile id="test-1" value="test-1"> |
| 109 | + Option 1 |
| 110 | + </RadioTile> |
| 111 | + {showSecondTile && ( |
| 112 | + <RadioTile id="test-2" value="test-2"> |
| 113 | + Option 2 |
| 114 | + </RadioTile> |
| 115 | + )} |
| 116 | + </TileGroup> |
| 117 | + </> |
| 118 | + ); |
| 119 | + }; |
| 120 | + render(<ToggleableRadioTiles />); |
| 121 | + |
| 122 | + expect(screen.getByDisplayValue('test-1')).toBeVisible(); |
| 123 | + expect(screen.getByDisplayValue('test-2')).toBeVisible(); |
| 124 | + |
| 125 | + await userEvent.click(screen.getByRole('button')); |
| 126 | + |
| 127 | + expect(screen.getByDisplayValue('test-1')).toBeVisible(); |
| 128 | + expect(screen.queryByDisplayValue('test-2')).not.toBeInTheDocument(); |
| 129 | + }); |
| 130 | + |
97 | 131 | it('should support a custom `className` on the outermost element', () => {
|
98 | 132 | const { container } = render(
|
99 | 133 | <TileGroup
|
|
0 commit comments