@@ -11,16 +11,8 @@ describe('given a <ParallaxBanner> component', () => {
1111 < ParallaxBanner
1212 className = "test-class"
1313 disabled = { false }
14- layers = { [
15- {
16- image : 'https://foo.com/bar.jpg' ,
17- speed : 2 ,
18- } ,
19- ] }
20- style = { {
21- backgroundColor : 'blue' ,
22- border : '1px solid red' ,
23- } }
14+ layers = { [ { image : 'https://foo.com/bar.jpg' , speed : 2 } ] }
15+ style = { { backgroundColor : 'blue' , border : '1px solid red' } }
2416 >
2517 < div >
2618 < h1 > Foo Bar</ h1 >
@@ -31,21 +23,26 @@ describe('given a <ParallaxBanner> component', () => {
3123 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
3224 } ) ;
3325 } ) ;
34-
35- describe ( 'with custom defined layer children' , ( ) => {
26+ describe ( 'when children are defined' , ( ) => {
27+ it ( 'then it will render the children' , ( ) => {
28+ const { getByTestId } = render (
29+ < ParallaxProvider >
30+ < ParallaxBanner >
31+ < div data-testid = "children" />
32+ </ ParallaxBanner >
33+ </ ParallaxProvider >
34+ ) ;
35+ expect ( getByTestId ( 'children' ) ) . toBeInTheDocument ( ) ;
36+ } ) ;
37+ } ) ;
38+ describe ( 'when custom defined layer children are defined' , ( ) => {
3639 it ( 'then it will render each layer child' , ( ) => {
3740 const { getByTestId } = render (
3841 < ParallaxProvider >
3942 < ParallaxBanner
4043 layers = { [
41- {
42- children : < div data-testid = "foo" > foo</ div > ,
43- speed : 2 ,
44- } ,
45- {
46- children : < div data-testid = "bar" > bar</ div > ,
47- speed : 4 ,
48- } ,
44+ { children : < div data-testid = "foo" > foo</ div > } ,
45+ { children : < div data-testid = "bar" > bar</ div > } ,
4946 ] }
5047 />
5148 </ ParallaxProvider >
@@ -55,18 +52,11 @@ describe('given a <ParallaxBanner> component', () => {
5552 } ) ;
5653 } ) ;
5754
58- describe ( 'with layer expanded false' , ( ) => {
55+ describe ( 'when the layer expanded option is false' , ( ) => {
5956 it ( 'then it will render without expanded styles' , ( ) => {
6057 const { getByTestId } = render (
6158 < ParallaxProvider >
62- < ParallaxBanner
63- layers = { [
64- {
65- speed : 2 ,
66- expanded : false ,
67- } ,
68- ] }
69- />
59+ < ParallaxBanner layers = { [ { speed : 2 , expanded : false } ] } />
7060 </ ParallaxProvider >
7161 ) ;
7262 expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '0px' ) ;
@@ -80,61 +70,85 @@ describe('given a <ParallaxBanner> component', () => {
8070 describe ( 'with layer expanded' , ( ) => {
8171 it ( 'then it will render with expanded styles based on speed' , ( ) => {
8272 const { getByTestId } = render (
73+ < ParallaxProvider >
74+ < ParallaxBanner layers = { [ { speed : 2 } ] } />
75+ </ ParallaxProvider >
76+ ) ;
77+ expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '-20px' ) ;
78+ expect ( getByTestId ( 'layer-0' ) . style . right ) . toBe ( '0px' ) ;
79+ expect ( getByTestId ( 'layer-0' ) . style . left ) . toBe ( '0px' ) ;
80+ expect ( getByTestId ( 'layer-0' ) . style . bottom ) . toBe ( '-20px' ) ;
81+ expect ( getByTestId ( 'layer-0' ) . style . position ) . toBe ( 'absolute' ) ;
82+ } ) ;
83+ } ) ;
84+ describe ( 'with custom props' , ( ) => {
85+ it ( 'then it will render children' , ( ) => {
86+ const { container, getByTestId } = render (
8387 < ParallaxProvider >
8488 < ParallaxBanner
8589 layers = { [
8690 {
8791 speed : 2 ,
92+ style : {
93+ backgroundColor : 'red' ,
94+ } ,
95+ className : 'my-custom-class' ,
8896 } ,
8997 ] }
9098 />
9199 </ ParallaxProvider >
92100 ) ;
93- expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '-20px' ) ;
94- expect ( getByTestId ( 'layer-0' ) . style . right ) . toBe ( '0px' ) ;
95- expect ( getByTestId ( 'layer-0' ) . style . left ) . toBe ( '0px' ) ;
96- expect ( getByTestId ( 'layer-0' ) . style . bottom ) . toBe ( '-20px' ) ;
97- expect ( getByTestId ( 'layer-0' ) . style . position ) . toBe ( 'absolute' ) ;
101+ expect ( container . querySelector ( '.my-custom-class' ) ) . toBeInTheDocument ( ) ;
102+ expect ( getByTestId ( 'layer-0' ) . style . background ) . toBe ( 'red' ) ;
98103 } ) ;
99104 } ) ;
100-
101- describe ( 'with children' , ( ) => {
102- it ( 'then it will render children' , ( ) => {
103- const { getByTestId } = render (
105+ describe ( 'when custom html props are given' , ( ) => {
106+ it ( 'then it adds them to the returned div' , ( ) => {
107+ const { container, getByTestId } = render (
104108 < ParallaxProvider >
105- < ParallaxBanner layers = { [ ] } >
106- < div data-testid = "child" />
107- </ ParallaxBanner >
109+ < ParallaxBanner
110+ style = { { background : 'red' } }
111+ className = "my-class"
112+ id = "test-id"
113+ data-testid = "data-test-id"
114+ data-foo = "bar"
115+ aria-label = "Cool"
116+ />
108117 </ ParallaxProvider >
109118 ) ;
110- expect ( getByTestId ( 'child' ) ) . toBeInTheDocument ( ) ;
119+ expect ( getByTestId ( 'data-test-id' ) ) . toBeInTheDocument ( ) ;
120+ expect ( container . querySelector ( '.my-class' ) ) . toBeInTheDocument ( ) ;
121+ expect ( container . querySelector ( '#test-id' ) ) . toBeInTheDocument ( ) ;
122+ expect ( getByTestId ( 'data-test-id' ) ) . toHaveAttribute ( 'aria-label' , 'Cool' ) ;
123+ expect ( getByTestId ( 'data-test-id' ) ) . toHaveAttribute ( 'data-foo' , 'bar' ) ;
124+ expect ( getByTestId ( 'data-test-id' ) . style . background ) . toBe ( 'red' ) ;
111125 } ) ;
112126 } ) ;
113-
114- describe ( 'with custom props' , ( ) => {
115- it ( 'then it will render children' , ( ) => {
127+ describe ( 'with custom props are defined in the layer' , ( ) => {
128+ it ( 'then it adds them to the layer div' , ( ) => {
116129 const { container, getByTestId } = render (
117130 < ParallaxProvider >
118131 < ParallaxBanner
119132 layers = { [
120133 {
121- speed : 2 ,
122- props : {
123- style : {
124- backgroundColor : 'red' ,
125- } ,
126- className : 'my-custom-class' ,
127- id : 'my-id' ,
128- } ,
134+ style : { background : 'red' } ,
135+ className : 'my-class' ,
136+ id : 'test-id' ,
137+ // @ts -expect-error
138+ 'data-testid' : 'data-test-id' ,
139+ 'data-foo' : 'bar' ,
140+ 'aria-label' : 'Cool' ,
129141 } ,
130142 ] }
131143 />
132144 </ ParallaxProvider >
133145 ) ;
134- expect ( container . querySelector ( '.my-custom-class' ) ) . toBeInTheDocument ( ) ;
135- expect ( container . querySelector ( '#my-id' ) ) . toBeInTheDocument ( ) ;
136-
137- expect ( getByTestId ( 'layer-0' ) . style . background ) . toBe ( 'red' ) ;
146+ expect ( getByTestId ( 'data-test-id' ) ) . toBeInTheDocument ( ) ;
147+ expect ( container . querySelector ( '.my-class' ) ) . toBeInTheDocument ( ) ;
148+ expect ( container . querySelector ( '#test-id' ) ) . toBeInTheDocument ( ) ;
149+ expect ( getByTestId ( 'data-test-id' ) ) . toHaveAttribute ( 'aria-label' , 'Cool' ) ;
150+ expect ( getByTestId ( 'data-test-id' ) ) . toHaveAttribute ( 'data-foo' , 'bar' ) ;
151+ expect ( getByTestId ( 'data-test-id' ) . style . background ) . toBe ( 'red' ) ;
138152 } ) ;
139153 } ) ;
140154} ) ;
0 commit comments