@@ -5,6 +5,7 @@ import {describe, expect, it, vi} from 'vitest'
5
5
import BaseStyles from '../BaseStyles'
6
6
import theme from '../theme'
7
7
import ThemeProvider from '../ThemeProvider'
8
+ import { FeatureFlags } from '../FeatureFlags'
8
9
import { SegmentedControl } from '../SegmentedControl'
9
10
10
11
const segmentData = [
@@ -143,13 +144,19 @@ describe('SegmentedControl', () => {
143
144
}
144
145
} )
145
146
146
- it ( 'renders icon button with tooltip as label' , ( ) => {
147
+ it ( 'renders icon button with tooltip as label when feature flag is enabled ' , ( ) => {
147
148
const { getByRole, getByText} = render (
148
- < SegmentedControl aria-label = "File view" >
149
- { segmentData . map ( ( { label, icon} ) => (
150
- < SegmentedControl . IconButton icon = { icon } aria-label = { label } key = { label } />
151
- ) ) }
152
- </ SegmentedControl > ,
149
+ < FeatureFlags
150
+ flags = { {
151
+ primer_react_segmented_control_tooltip : true ,
152
+ } }
153
+ >
154
+ < SegmentedControl aria-label = "File view" >
155
+ { segmentData . map ( ( { label, icon} ) => (
156
+ < SegmentedControl . IconButton icon = { icon } aria-label = { label } key = { label } />
157
+ ) ) }
158
+ </ SegmentedControl >
159
+ </ FeatureFlags > ,
153
160
)
154
161
155
162
for ( const datum of segmentData ) {
@@ -160,13 +167,19 @@ describe('SegmentedControl', () => {
160
167
}
161
168
} )
162
169
163
- it ( 'renders icon button with tooltip description' , ( ) => {
170
+ it ( 'renders icon button with tooltip description when feature flag is enabled ' , ( ) => {
164
171
const { getByRole, getByText} = render (
165
- < SegmentedControl aria-label = "File view" >
166
- { segmentData . map ( ( { label, icon, description} ) => (
167
- < SegmentedControl . IconButton icon = { icon } aria-label = { label } description = { description } key = { label } />
168
- ) ) }
169
- </ SegmentedControl > ,
172
+ < FeatureFlags
173
+ flags = { {
174
+ primer_react_segmented_control_tooltip : true ,
175
+ } }
176
+ >
177
+ < SegmentedControl aria-label = "File view" >
178
+ { segmentData . map ( ( { label, icon, description} ) => (
179
+ < SegmentedControl . IconButton icon = { icon } aria-label = { label } description = { description } key = { label } />
180
+ ) ) }
181
+ </ SegmentedControl >
182
+ </ FeatureFlags > ,
170
183
)
171
184
172
185
for ( const datum of segmentData ) {
@@ -178,6 +191,21 @@ describe('SegmentedControl', () => {
178
191
}
179
192
} )
180
193
194
+ it ( 'renders icon button with aria-label and no tooltip' , ( ) => {
195
+ const { getByRole} = render (
196
+ < SegmentedControl aria-label = "File view" >
197
+ { segmentData . map ( ( { label, icon} ) => (
198
+ < SegmentedControl . IconButton icon = { icon } aria-label = { label } key = { label } />
199
+ ) ) }
200
+ </ SegmentedControl > ,
201
+ )
202
+
203
+ for ( const datum of segmentData ) {
204
+ const labelledButton = getByRole ( 'button' , { name : datum . label } )
205
+ expect ( labelledButton ) . toHaveAttribute ( 'aria-label' , datum . label )
206
+ }
207
+ } )
208
+
181
209
it ( 'calls onChange with index of clicked segment button' , async ( ) => {
182
210
const user = userEvent . setup ( )
183
211
const handleChange = vi . fn ( )
0 commit comments