@@ -5,6 +5,7 @@ import {describe, expect, it, vi} from 'vitest'
55import BaseStyles from '../BaseStyles'
66import theme from '../theme'
77import ThemeProvider from '../ThemeProvider'
8+ import { FeatureFlags } from '../FeatureFlags'
89import { SegmentedControl } from '../SegmentedControl'
910
1011const segmentData = [
@@ -143,13 +144,19 @@ describe('SegmentedControl', () => {
143144 }
144145 } )
145146
146- it ( 'renders icon button with tooltip as label' , ( ) => {
147+ it ( 'renders icon button with tooltip as label when feature flag is enabled ' , ( ) => {
147148 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 > ,
153160 )
154161
155162 for ( const datum of segmentData ) {
@@ -160,13 +167,19 @@ describe('SegmentedControl', () => {
160167 }
161168 } )
162169
163- it ( 'renders icon button with tooltip description' , ( ) => {
170+ it ( 'renders icon button with tooltip description when feature flag is enabled ' , ( ) => {
164171 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 > ,
170183 )
171184
172185 for ( const datum of segmentData ) {
@@ -178,6 +191,21 @@ describe('SegmentedControl', () => {
178191 }
179192 } )
180193
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+
181209 it ( 'calls onChange with index of clicked segment button' , async ( ) => {
182210 const user = userEvent . setup ( )
183211 const handleChange = vi . fn ( )
0 commit comments