@@ -47,8 +47,9 @@ import {
4747
4848describe ( '@primer/react' , ( ) => {
4949 test ( 'ActionList supports `sx` prop' , ( ) => {
50- render ( < ActionList data-testid = "component" sx = { { background : 'red' } } /> )
50+ render ( < ActionList as = "div" data-testid = "component" sx = { { background : 'red' } } variant = "inset" /> )
5151 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
52+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'data-variant' , 'inset' )
5253 } )
5354
5455 test ( 'ActionMenu.Button supports `sx` prop' , ( ) => {
@@ -109,7 +110,7 @@ describe('@primer/react', () => {
109110 } )
110111
111112 test ( 'Box supports `sx` prop' , ( ) => {
112- render ( < Box data-testid = "component" sx = { { background : 'red' } } /> )
113+ render ( < Box as = "div" data-testid = "component" sx = { { background : 'red' } } /> )
113114 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
114115 } )
115116
@@ -119,14 +120,15 @@ describe('@primer/react', () => {
119120 } )
120121
121122 test ( 'Breadcrumbs.Item supports `sx` prop' , ( ) => {
122- render ( < Breadcrumbs . Item data-testid = "component" sx = { { background : 'red' } } href = "#" /> )
123+ render ( < Breadcrumbs . Item as = "li" data-testid = "component" sx = { { background : 'red' } } selected /> )
123124 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
124- expect ( window . getComputedStyle ( screen . getByRole ( 'link' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
125+ expect ( screen . getByTestId ( 'component' ) . className . includes ( 'selected' ) ) . toBe ( true )
125126 } )
126127
127128 test ( 'Button supports `sx` prop' , ( ) => {
128- render ( < Button data-testid = "component" sx = { { background : 'red' } } /> )
129+ render ( < Button as = "button" data-testid = "component" sx = { { background : 'red' } } size = "medium" /> )
129130 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
131+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'data-size' , 'medium' )
130132 } )
131133
132134 test ( 'Checkbox supports `sx` prop' , ( ) => {
@@ -184,8 +186,9 @@ describe('@primer/react', () => {
184186 } )
185187
186188 test ( 'Flash supports `sx` prop' , ( ) => {
187- render ( < Flash data-testid = "component" sx = { { background : 'red' } } /> )
189+ render ( < Flash as = "div" data-testid = "component" sx = { { background : 'red' } } variant = "success" /> )
188190 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
191+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'variant' , 'success' )
189192 } )
190193
191194 test ( 'FormControl supports `sx` prop' , ( ) => {
@@ -198,7 +201,7 @@ describe('@primer/react', () => {
198201 } )
199202
200203 test ( 'Header supports `sx` prop' , ( ) => {
201- render ( < Header data-testid = "component" sx = { { background : 'red' } } /> )
204+ render ( < Header as = "header" data-testid = "component" sx = { { background : 'red' } } /> )
202205 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
203206 } )
204207
@@ -208,23 +211,40 @@ describe('@primer/react', () => {
208211 } )
209212
210213 test ( 'IconButton supports `sx` prop' , ( ) => {
211- render ( < IconButton aria-label = "test" data-testid = "component" sx = { { background : 'red' } } icon = { ( ) => < svg /> } /> )
214+ render (
215+ < IconButton
216+ as = "button"
217+ aria-label = "test"
218+ data-testid = "component"
219+ sx = { { background : 'red' } }
220+ icon = { ( ) => < svg /> }
221+ /> ,
222+ )
212223 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
224+
225+ // Test that IconButton renders the icon component (SVG) in its children
226+ const iconButton = screen . getByTestId ( 'component' )
227+ const svgElement = iconButton . querySelector ( 'svg' )
228+ expect ( svgElement ) . toBeInTheDocument ( )
229+ expect ( iconButton . children . length ) . toBeGreaterThan ( 0 )
213230 } )
214231
215232 test ( 'Label supports `sx` prop' , ( ) => {
216- render ( < Label data-testid = "component" sx = { { background : 'red' } } /> )
233+ render ( < Label as = "span" data-testid = "component" sx = { { background : 'red' } } size = "large" /> )
217234 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
235+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'data-size' , 'large' )
218236 } )
219237
220238 test ( 'Link supports `sx` prop' , ( ) => {
221- render ( < Link data-testid = "component" sx = { { background : 'red' } } /> )
239+ render ( < Link as = "a" data-testid = "component" sx = { { background : 'red' } } inline /> )
240+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'data-inline' , 'true' )
222241 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
223242 } )
224243
225244 test ( 'LinkButton supports `sx` prop' , ( ) => {
226- render ( < LinkButton data-testid = "component" sx = { { background : 'red' } } /> )
245+ render ( < LinkButton as = "a" data-testid = "component" sx = { { background : 'red' } } icon = { < svg /> } /> )
227246 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
247+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'icon' )
228248 } )
229249
230250 test ( 'NavList supports `sx` prop' , ( ) => {
@@ -286,19 +306,23 @@ describe('@primer/react', () => {
286306 render (
287307 < ThemeProvider >
288308 < Overlay
309+ as = "div"
289310 data-testid = "component"
290311 sx = { { background : 'red' } }
291312 onClickOutside = { ( ) => { } }
292313 onEscape = { ( ) => { } }
293314 returnFocusRef = { ref }
315+ role = "dialog"
294316 />
295317 </ ThemeProvider > ,
296318 )
297319 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
320+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'role' , 'dialog' )
298321 } )
299322
300323 test ( 'PageHeader supports `sx` prop' , ( ) => {
301- const { container} = render ( < PageHeader data-testid = "component" sx = { { background : 'red' } } /> )
324+ const { container} = render ( < PageHeader as = "div" data-testid = "component" sx = { { background : 'red' } } role = "article" /> )
325+ expect ( container . firstElementChild ! ) . toHaveAttribute ( 'role' , 'article' )
302326 expect ( window . getComputedStyle ( container . firstElementChild ! ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
303327 } )
304328
@@ -323,8 +347,13 @@ describe('@primer/react', () => {
323347 } )
324348
325349 test ( 'PageLayout.Content supports `sx` prop' , ( ) => {
326- const { container} = render ( < PageLayout . Content data-testid = "component" sx = { { background : 'red' } } /> )
327- expect ( window . getComputedStyle ( container . firstElementChild ! ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
350+ const { container} = render (
351+ < PageLayout . Content as = "section" data-testid = "component" sx = { { background : 'red' } } aria-labelledby = "normal" /> ,
352+ )
353+
354+ const outerElement = container . firstElementChild ! as HTMLElement
355+ expect ( window . getComputedStyle ( outerElement ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
356+ expect ( outerElement ) . toHaveAttribute ( 'aria-labelledby' , 'normal' )
328357 } )
329358
330359 test ( 'PageLayout.Pane supports `sx` prop' , ( ) => {
@@ -386,8 +415,9 @@ describe('@primer/react', () => {
386415 } )
387416
388417 test . skip ( 'Select supports `sx` prop' , ( ) => {
389- render ( < Select data-testid = "component" sx = { { background : 'red' } } /> )
418+ render ( < Select as = "select" data-testid = "component" sx = { { background : 'red' } } required /> )
390419 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
420+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'required' )
391421 } )
392422
393423 test ( 'Spinner supports `sx` prop' , ( ) => {
@@ -411,13 +441,15 @@ describe('@primer/react', () => {
411441 } )
412442
413443 test ( 'Text supports `sx` prop' , ( ) => {
414- render ( < Text data-testid = "component" sx = { { background : 'red' } } /> )
444+ render ( < Text as = "span" data-testid = "component" sx = { { background : 'red' } } size = "small" /> )
415445 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
446+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'data-size' , 'small' )
416447 } )
417448
418449 test ( 'TextInput supports `sx` prop' , ( ) => {
419- const { container} = render ( < TextInput sx = { { background : 'red' } } /> )
450+ const { container} = render ( < TextInput as = "input" sx = { { background : 'red' } } loading /> )
420451 expect ( window . getComputedStyle ( container . firstElementChild ! ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
452+ expect ( container . firstElementChild ) . toHaveAttribute ( 'data-trailing-visual' , 'true' )
421453 } )
422454
423455 test ( 'TextInput.Action supports `sx` prop' , ( ) => {
@@ -456,8 +488,9 @@ describe('@primer/react', () => {
456488 } )
457489
458490 test ( 'Token supports `sx` prop' , ( ) => {
459- render ( < Token data-testid = "component" sx = { { background : 'red' } } text = "test" /> )
491+ render ( < Token as = "button" data-testid = "component" sx = { { background : 'red' } } text = "test" /> )
460492 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
493+ expect ( screen . getByTestId ( 'component' ) ) . toHaveTextContent ( 'test' )
461494 } )
462495
463496 test . todo ( 'Tooltip supports `sx` prop' , ( ) => {
@@ -470,25 +503,29 @@ describe('@primer/react', () => {
470503 } )
471504
472505 test ( 'Truncate supports `sx` prop' , ( ) => {
473- render ( < Truncate data-testid = "component" sx = { { background : 'red' } } title = "test" /> )
506+ render ( < Truncate as = "div" data-testid = "component" sx = { { background : 'red' } } title = "test" /> )
474507 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
508+ expect ( screen . getByTestId ( 'component' ) ) . toHaveAttribute ( 'title' , 'test' )
475509 } )
476510
477511 test ( 'UnderlineNav supports `sx` prop' , ( ) => {
478512 render (
479- < UnderlineNav aria-label = "navigation" data-testid = "component" sx = { { background : 'red' } } >
513+ < UnderlineNav as = "nav" aria-label = "navigation" data-testid = "component" sx = { { background : 'red' } } variant = "inset" >
480514 < UnderlineNav . Item > test</ UnderlineNav . Item >
481515 </ UnderlineNav > ,
482516 )
483517 expect ( window . getComputedStyle ( screen . getByLabelText ( 'navigation' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
518+ expect ( screen . getByLabelText ( 'navigation' ) ) . toHaveAttribute ( 'data-variant' , 'inset' )
484519 } )
485520
486521 test ( 'UnderlineNav.Item supports `sx` prop' , ( ) => {
487522 render (
488- < UnderlineNav . Item data-testid = "component" sx = { { background : 'red' } } >
523+ < UnderlineNav . Item as = "a" data-testid = "component" sx = { { background : 'red' } } icon = { < svg /> } >
489524 test
490525 </ UnderlineNav . Item > ,
491526 )
492527 expect ( window . getComputedStyle ( screen . getByTestId ( 'component' ) ) . backgroundColor ) . toBe ( 'rgb(255, 0, 0)' )
528+ const svgElement = screen . getByTestId ( 'component' ) . querySelector ( 'svg' )
529+ expect ( svgElement ) . toBeInTheDocument ( )
493530 } )
494531} )
0 commit comments