11import { describe , expect , it , vi } from 'vitest'
22import { Heading } from '../..'
33import { render , screen } from '@testing-library/react'
4- import ThemeProvider from '../../ThemeProvider'
5-
6- const theme = {
7- breakpoints : [ '400px' , '640px' , '960px' , '1280px' ] ,
8- colors : {
9- green : [ '#010' , '#020' , '#030' , '#040' , '#050' , '#060' ] ,
10- } ,
11- fontSizes : [ '12px' , '14px' , '16px' , '20px' , '24px' , '32px' , '40px' , '48px' ] ,
12- fonts : {
13- normal : 'Helvetica,sans-serif' ,
14- mono : 'Consolas,monospace' ,
15- } ,
16- lineHeights : {
17- normal : 1.5 ,
18- condensed : 1.25 ,
19- condensedUltra : 1 ,
20- } ,
21- fontWeights : {
22- light : '300' ,
23- normal : '400' ,
24- semibold : '500' ,
25- bold : '600' ,
26- } ,
27- }
284
295describe ( 'Heading' , ( ) => {
306 it ( 'should support `className` on the outermost element' , ( ) => {
@@ -38,89 +14,6 @@ describe('Heading', () => {
3814 expect ( heading . tagName ) . toBe ( 'H2' )
3915 } )
4016
41- it ( 'respects fontWeight' , ( ) => {
42- const { container} = render (
43- < ThemeProvider theme = { theme } >
44- < Heading sx = { { fontWeight : 'bold' } } />
45- </ ThemeProvider > ,
46- )
47- const heading = container . firstChild as HTMLElement
48- expect ( heading ) . toHaveStyle ( `font-weight: ${ theme . fontWeights . bold } ` )
49-
50- const { container : container2 } = render (
51- < ThemeProvider theme = { theme } >
52- < Heading sx = { { fontWeight : 'normal' } } />
53- </ ThemeProvider > ,
54- )
55- const heading2 = container2 . firstChild as HTMLElement
56- expect ( heading2 ) . toHaveStyle ( `font-weight: ${ theme . fontWeights . normal } ` )
57-
58- const { container : container3 } = render (
59- < ThemeProvider theme = { theme } >
60- < Heading sx = { { fontWeight : 'semibold' } } />
61- </ ThemeProvider > ,
62- )
63- const heading3 = container3 . firstChild as HTMLElement
64- expect ( heading3 ) . toHaveStyle ( `font-weight: ${ theme . fontWeights . semibold } ` )
65-
66- const { container : container4 } = render (
67- < ThemeProvider theme = { theme } >
68- < Heading sx = { { fontWeight : 'light' } } />
69- </ ThemeProvider > ,
70- )
71- const heading4 = container4 . firstChild as HTMLElement
72- expect ( heading4 ) . toHaveStyle ( `font-weight: ${ theme . fontWeights . light } ` )
73- } )
74-
75- it ( 'respects lineHeight' , ( ) => {
76- const { container} = render (
77- < ThemeProvider theme = { theme } >
78- < Heading sx = { { lineHeight : 'normal' } } />
79- </ ThemeProvider > ,
80- )
81- const heading = container . firstChild as HTMLElement
82- ///These sx tests should go away right?
83- expect ( heading ) . toHaveStyle ( `line-height: 48px` )
84-
85- const { container : container2 } = render (
86- < ThemeProvider theme = { theme } >
87- < Heading sx = { { lineHeight : 'condensed' } } />
88- </ ThemeProvider > ,
89- )
90- const heading2 = container2 . firstChild as HTMLElement
91- expect ( heading2 ) . toHaveStyle ( `line-height: 40px` )
92-
93- const { container : container3 } = render (
94- < ThemeProvider theme = { theme } >
95- < Heading sx = { { lineHeight : 'condensedUltra' } } />
96- </ ThemeProvider > ,
97- )
98- const heading3 = container3 . firstChild as HTMLElement
99- expect ( heading3 ) . toHaveStyle ( `line-height: 32px` )
100- } )
101-
102- it ( 'respects fontFamily="mono"' , ( ) => {
103- const { container} = render (
104- < ThemeProvider theme = { theme } >
105- < Heading sx = { { fontFamily : 'mono' } } />
106- </ ThemeProvider > ,
107- )
108- const heading = container . firstChild as HTMLElement
109- expect ( heading ) . toHaveStyle ( `font-family: ${ theme . fonts . mono } ` )
110- } )
111-
112- it ( 'renders fontSize' , ( ) => {
113- for ( const fontSize of theme . fontSizes ) {
114- const { container} = render (
115- < ThemeProvider theme = { theme } >
116- < Heading sx = { { fontSize} } />
117- </ ThemeProvider > ,
118- )
119- const heading = container . firstChild as HTMLElement
120- expect ( heading ) . toHaveStyle ( `font-size: ${ fontSize } ` )
121- }
122- } )
123-
12417 it ( 'logs a warning when trying to render invalid "as" prop' , ( ) => {
12518 const consoleSpy = vi . spyOn ( globalThis . console , 'warn' ) . mockImplementation ( ( ) => { } )
12619
@@ -130,15 +23,6 @@ describe('Heading', () => {
13023
13124 consoleSpy . mockRestore ( )
13225 } )
133- it ( 'respects the "fontStyle" prop' , ( ) => {
134- const { container} = render (
135- < ThemeProvider theme = { theme } >
136- < Heading sx = { { fontStyle : 'italic' } } />
137- </ ThemeProvider > ,
138- )
139- const heading = container . firstChild as HTMLElement
140- expect ( heading ) . toHaveStyle ( 'font-style: italic' )
141- } )
14226
14327 // How can we test for generated class names?
14428 it . skip ( 'should only include css modules class' , ( ) => {
@@ -148,18 +32,4 @@ describe('Heading', () => {
14832 // for this component
14933 expect ( screen . getByText ( 'test' ) ) . not . toHaveClass ( / ^ H e a d i n g _ _ S t y l e d H e a d i n g / )
15034 } )
151-
152- it ( 'should support overrides with sx if provided' , ( ) => {
153- render (
154- < Heading
155- sx = { {
156- fontWeight : '900' ,
157- } }
158- >
159- test
160- </ Heading > ,
161- )
162-
163- expect ( screen . getByText ( 'test' ) ) . toHaveStyle ( 'font-weight: 900' )
164- } )
16535} )
0 commit comments