66 */
77
88import React from 'react' ;
9- import { render , renderRtl } from 'garden-test-utils' ;
10- import { PALETTE_V8 } from '@zendeskgarden/react-theming' ;
9+ import { getRenderFn , render , renderRtl } from 'garden-test-utils' ;
10+ import { PALETTE } from '@zendeskgarden/react-theming' ;
1111import { Code } from './Code' ;
12+ import { ICodeProps } from 'packages/typography/src/types' ;
1213
1314describe ( 'Code' , ( ) => {
15+ it ( 'renders the expected element' , ( ) => {
16+ const { container } = render ( < Code /> ) ;
17+
18+ expect ( container . firstChild ! . nodeName ) . toBe ( 'CODE' ) ;
19+ } ) ;
20+
1421 it ( 'applies correct styling with RTL locale' , ( ) => {
1522 const { container } = renderRtl ( < Code /> ) ;
1623
@@ -26,7 +33,23 @@ describe('Code', () => {
2633 ) ;
2734 } ) ;
2835
36+ it ( 'renders anchor-inherited color' , ( ) => {
37+ const { getByTestId } = render (
38+ < a href = "test" >
39+ < Code data-test-id = "test" />
40+ </ a >
41+ ) ;
42+
43+ expect ( getByTestId ( 'test' ) ) . toHaveStyleRule ( 'color' , 'inherit' , { modifier : 'a &' } ) ;
44+ } ) ;
45+
2946 describe ( 'size' , ( ) => {
47+ it ( 'renders inherited size' , ( ) => {
48+ const { container } = render ( < Code /> ) ;
49+
50+ expect ( container . firstChild ) . not . toHaveStyleRule ( 'font-size' , 'inherit' ) ;
51+ } ) ;
52+
3053 it ( 'renders small styling if provided' , ( ) => {
3154 const { container } = render ( < Code size = "small" /> ) ;
3255
@@ -47,28 +70,55 @@ describe('Code', () => {
4770 } ) ;
4871
4972 describe ( 'hue' , ( ) => {
50- it ( 'renders grey hue if provided' , ( ) => {
51- const { container } = render ( < Code hue = "grey" /> ) ;
52-
53- expect ( container . firstChild ) . toHaveStyleRule ( 'background-color' , PALETTE_V8 . grey [ 200 ] ) ;
54- } ) ;
55-
56- it ( 'renders green hue if provided' , ( ) => {
57- const { container } = render ( < Code hue = "green" /> ) ;
58-
59- expect ( container . firstChild ) . toHaveStyleRule ( 'background-color' , PALETTE_V8 . green [ 200 ] ) ;
60- } ) ;
61-
62- it ( 'renders red hue if provided' , ( ) => {
63- const { container } = render ( < Code hue = "red" /> ) ;
64-
65- expect ( container . firstChild ) . toHaveStyleRule ( 'background-color' , PALETTE_V8 . red [ 200 ] ) ;
73+ it . each <
74+ [
75+ ICodeProps [ 'hue' ] ,
76+ 'dark' | 'light' ,
77+ {
78+ color : string ;
79+ bgColor : string ;
80+ }
81+ ]
82+ > ( [
83+ // light mode
84+ [ 'grey' , 'light' , { color : PALETTE . grey [ 900 ] , bgColor : PALETTE . grey [ 200 ] } ] ,
85+ [ 'green' , 'light' , { color : PALETTE . green [ 900 ] , bgColor : PALETTE . green [ 200 ] } ] ,
86+ [ 'red' , 'light' , { color : PALETTE . red [ 900 ] , bgColor : PALETTE . red [ 200 ] } ] ,
87+ [ 'yellow' , 'light' , { color : PALETTE . yellow [ 900 ] , bgColor : PALETTE . yellow [ 200 ] } ] ,
88+ // dark mode
89+ [ 'grey' , 'dark' , { color : PALETTE . grey [ 300 ] , bgColor : PALETTE . grey [ 900 ] } ] ,
90+ [ 'green' , 'dark' , { color : PALETTE . green [ 300 ] , bgColor : PALETTE . green [ 900 ] } ] ,
91+ [ 'red' , 'dark' , { color : PALETTE . red [ 300 ] , bgColor : PALETTE . red [ 900 ] } ] ,
92+ [ 'yellow' , 'dark' , { color : PALETTE . yellow [ 300 ] , bgColor : PALETTE . yellow [ 900 ] } ]
93+ ] ) ( 'renders with a "%s" hue in "%s" mode' , ( hue , mode , { color, bgColor } ) => {
94+ const { container } = getRenderFn ( mode ) ( < Code hue = { hue } /> ) ;
95+
96+ expect ( container . firstChild ) . toHaveStyleRule ( 'color' , color ) ;
97+ expect ( container . firstChild ) . toHaveStyleRule ( 'background-color' , bgColor ) ;
6698 } ) ;
6799
68- it ( 'renders yellow hue if provided' , ( ) => {
69- const { container } = render ( < Code hue = "yellow" /> ) ;
70-
71- expect ( container . firstChild ) . toHaveStyleRule ( 'background-color' , PALETTE_V8 . yellow [ 200 ] ) ;
72- } ) ;
100+ it . each <
101+ [
102+ string | undefined ,
103+ 'dark' | 'light' ,
104+ {
105+ color : string ;
106+ bgColor : string ;
107+ }
108+ ]
109+ > ( [
110+ [ 'azure' , 'light' , { color : PALETTE . grey [ 900 ] , bgColor : PALETTE . grey [ 200 ] } ] ,
111+ [ undefined , 'light' , { color : PALETTE . grey [ 900 ] , bgColor : PALETTE . grey [ 200 ] } ] ,
112+ [ 'azure' , 'dark' , { color : PALETTE . grey [ 300 ] , bgColor : PALETTE . grey [ 900 ] } ] ,
113+ [ undefined , 'dark' , { color : PALETTE . grey [ 300 ] , bgColor : PALETTE . grey [ 900 ] } ]
114+ ] ) (
115+ 'outputs the grey hue color combination for an unsupported "%s" hue in "%s" mode' ,
116+ ( hue , mode , { color, bgColor } ) => {
117+ const { container } = getRenderFn ( mode ) ( < Code hue = { hue as any } /> ) ;
118+
119+ expect ( container . firstChild ) . toHaveStyleRule ( 'color' , color ) ;
120+ expect ( container . firstChild ) . toHaveStyleRule ( 'background-color' , bgColor ) ;
121+ }
122+ ) ;
73123 } ) ;
74124} ) ;
0 commit comments