@@ -16,135 +16,23 @@ test('Renders with children', () => {
1616 expect ( screen . getByText ( 'Test content' ) ) . toBeVisible ( ) ;
1717} ) ;
1818
19- test ( 'Renders with custom class name when className prop is provided' , ( ) => {
20- render ( < CompassHero className = "custom-class" > Test</ CompassHero > ) ;
21- expect ( screen . getByText ( 'Test' ) . parentElement ) . toHaveClass ( 'custom-class' ) ;
22- } ) ;
23-
24- test ( `Renders with default ${ styles . compassPanel } and ${ styles . compassHero } classes on the hero and ${ styles . compassHeroBody } class on the hero body` , ( ) => {
19+ test ( `Renders with ${ styles . compass } __hero class by defaulty` , ( ) => {
2520 render ( < CompassHero > Test</ CompassHero > ) ;
26- const heroBodyElement = screen . getByText ( 'Test' ) ;
27- expect ( heroBodyElement ) . toHaveClass ( styles . compassHeroBody ) ;
28-
29- const heroElement = heroBodyElement . parentElement ;
30- expect ( heroElement ) . toHaveClass ( styles . compassPanel ) ;
31- expect ( heroElement ) . toHaveClass ( styles . compassHero ) ;
32- } ) ;
33-
34- test ( 'Renders with light background image style when backgroundSrcLight is provided' , ( ) => {
35- const backgroundSrc = 'light-bg.jpg' ;
36- render ( < CompassHero backgroundSrcLight = { backgroundSrc } > Test</ CompassHero > ) ;
37- expect ( screen . getByText ( 'Test' ) . parentElement ) . toHaveStyle (
38- `--pf-v6-c-compass__hero--BackgroundImage--light: url(${ backgroundSrc } )`
39- ) ;
40- } ) ;
41-
42- test ( 'Renders with dark background image style when backgroundSrcDark is provided' , ( ) => {
43- const backgroundSrc = 'dark-bg.jpg' ;
44- render ( < CompassHero backgroundSrcDark = { backgroundSrc } > Test</ CompassHero > ) ;
45- expect ( screen . getByText ( 'Test' ) . parentElement ) . toHaveStyle (
46- `--pf-v6-c-compass__hero--BackgroundImage--dark: url(${ backgroundSrc } )`
47- ) ;
48- } ) ;
49-
50- test ( 'Renders with both light and dark background image styles when both are provided' , ( ) => {
51- const lightSrc = 'light-bg.jpg' ;
52- const darkSrc = 'dark-bg.jpg' ;
53- render (
54- < CompassHero backgroundSrcLight = { lightSrc } backgroundSrcDark = { darkSrc } >
55- Test
56- </ CompassHero >
57- ) ;
58- const heroElement = screen . getByText ( 'Test' ) . parentElement ;
59- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--BackgroundImage--light: url(${ lightSrc } )` ) ;
60- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--BackgroundImage--dark: url(${ darkSrc } )` ) ;
61- } ) ;
62-
63- test ( 'Renders with light gradient styles when gradientLight is provided' , ( ) => {
64- const gradient = {
65- stop1 : '#ff0000' ,
66- stop2 : '#00ff00' ,
67- stop3 : '#0000ff'
68- } ;
69- render ( < CompassHero gradientLight = { gradient } > Test</ CompassHero > ) ;
70- const heroElement = screen . getByText ( 'Test' ) . parentElement ;
71- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-1--light: ${ gradient . stop1 } ` ) ;
72- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-2--light: ${ gradient . stop2 } ` ) ;
73- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-3--light: ${ gradient . stop3 } ` ) ;
74- } ) ;
7521
76- test ( 'Renders with dark gradient styles when gradientDark is provided' , ( ) => {
77- const gradient = {
78- stop1 : '#ff0000' ,
79- stop2 : '#00ff00' ,
80- stop3 : '#0000ff'
81- } ;
82- render ( < CompassHero gradientDark = { gradient } > Test</ CompassHero > ) ;
83- const heroElement = screen . getByText ( 'Test' ) . parentElement ;
84- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-1--dark: ${ gradient . stop1 } ` ) ;
85- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-2--dark: ${ gradient . stop2 } ` ) ;
86- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-3--dark: ${ gradient . stop3 } ` ) ;
87- } ) ;
88-
89- test ( 'Renders with both light and dark gradient styles when both are provided' , ( ) => {
90- const lightGradient = {
91- stop1 : '#ff0000' ,
92- stop2 : '#00ff00' ,
93- stop3 : '#0000ff'
94- } ;
95- const darkGradient = {
96- stop1 : '#000000' ,
97- stop2 : '#ffffff' ,
98- stop3 : '#808080'
99- } ;
100- render (
101- < CompassHero gradientLight = { lightGradient } gradientDark = { darkGradient } >
102- Test
103- </ CompassHero >
104- ) ;
105- const heroElement = screen . getByText ( 'Test' ) . parentElement ;
106- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-1--light: ${ lightGradient . stop1 } ` ) ;
107- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-1--dark: ${ darkGradient . stop1 } ` ) ;
22+ expect ( screen . getByText ( 'Test' ) ) . toHaveClass ( `${ styles . compass } __hero` , { exact : true } ) ;
10823} ) ;
10924
110- test ( 'Renders with both background images and gradient styles when both are provided' , ( ) => {
111- const lightSrc = 'light-bg.jpg' ;
112- const darkSrc = 'dark-bg.jpg' ;
113- const lightGradient = { stop1 : '#ff0000' } ;
114- const darkGradient = { stop1 : '#000000' } ;
115-
116- render (
117- < CompassHero
118- backgroundSrcLight = { lightSrc }
119- backgroundSrcDark = { darkSrc }
120- gradientLight = { lightGradient }
121- gradientDark = { darkGradient }
122- >
123- Test
124- </ CompassHero >
125- ) ;
126- const heroElement = screen . getByText ( 'Test' ) . parentElement ;
127- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--BackgroundImage--light: url(${ lightSrc } )` ) ;
128- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--BackgroundImage--dark: url(${ darkSrc } )` ) ;
129- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-1--light: ${ lightGradient . stop1 } ` ) ;
130- expect ( heroElement ) . toHaveStyle ( `--pf-v6-c-compass__hero--gradient--stop-1--dark: ${ darkGradient . stop1 } ` ) ;
25+ test ( 'Renders with custom class name when className prop is provided' , ( ) => {
26+ render ( < CompassHero className = "custom-class" > Test</ CompassHero > ) ;
27+ expect ( screen . getByText ( 'Test' ) ) . toHaveClass ( 'custom-class' ) ;
13128} ) ;
13229
13330test ( 'Renders with additional props spread to the component' , ( ) => {
13431 render ( < CompassHero aria-label = "Test label" > Test</ CompassHero > ) ;
135- expect ( screen . getByText ( 'Test' ) . parentElement ) . toHaveAccessibleName ( 'Test label' ) ;
32+ expect ( screen . getByText ( 'Test' ) ) . toHaveAccessibleName ( 'Test label' ) ;
13633} ) ;
13734
13835test ( 'Matches the snapshot' , ( ) => {
139- const { asFragment } = render (
140- < CompassHero
141- backgroundSrcLight = "light.jpg"
142- backgroundSrcDark = "dark.jpg"
143- gradientLight = { { stop1 : '#ff0000' , stop2 : '#00ff00' , stop3 : '#0000ff' } }
144- gradientDark = { { stop1 : '#000000' , stop2 : '#ffffff' , stop3 : '#808080' } }
145- >
146- < div > Hero content</ div >
147- </ CompassHero >
148- ) ;
36+ const { asFragment } = render ( < CompassHero > Hero content</ CompassHero > ) ;
14937 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
15038} ) ;
0 commit comments