@@ -11,16 +11,8 @@ describe('given a <ParallaxBanner> component', () => {
11
11
< ParallaxBanner
12
12
className = "test-class"
13
13
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' } }
24
16
>
25
17
< div >
26
18
< h1 > Foo Bar</ h1 >
@@ -31,21 +23,26 @@ describe('given a <ParallaxBanner> component', () => {
31
23
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
32
24
} ) ;
33
25
} ) ;
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' , ( ) => {
36
39
it ( 'then it will render each layer child' , ( ) => {
37
40
const { getByTestId } = render (
38
41
< ParallaxProvider >
39
42
< ParallaxBanner
40
43
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 > } ,
49
46
] }
50
47
/>
51
48
</ ParallaxProvider >
@@ -55,18 +52,11 @@ describe('given a <ParallaxBanner> component', () => {
55
52
} ) ;
56
53
} ) ;
57
54
58
- describe ( 'with layer expanded false' , ( ) => {
55
+ describe ( 'when the layer expanded option is false' , ( ) => {
59
56
it ( 'then it will render without expanded styles' , ( ) => {
60
57
const { getByTestId } = render (
61
58
< ParallaxProvider >
62
- < ParallaxBanner
63
- layers = { [
64
- {
65
- speed : 2 ,
66
- expanded : false ,
67
- } ,
68
- ] }
69
- />
59
+ < ParallaxBanner layers = { [ { speed : 2 , expanded : false } ] } />
70
60
</ ParallaxProvider >
71
61
) ;
72
62
expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '0px' ) ;
@@ -80,61 +70,85 @@ describe('given a <ParallaxBanner> component', () => {
80
70
describe ( 'with layer expanded' , ( ) => {
81
71
it ( 'then it will render with expanded styles based on speed' , ( ) => {
82
72
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 (
83
87
< ParallaxProvider >
84
88
< ParallaxBanner
85
89
layers = { [
86
90
{
87
91
speed : 2 ,
92
+ style : {
93
+ backgroundColor : 'red' ,
94
+ } ,
95
+ className : 'my-custom-class' ,
88
96
} ,
89
97
] }
90
98
/>
91
99
</ ParallaxProvider >
92
100
) ;
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' ) ;
98
103
} ) ;
99
104
} ) ;
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 (
104
108
< 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
+ />
108
117
</ ParallaxProvider >
109
118
) ;
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' ) ;
111
125
} ) ;
112
126
} ) ;
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' , ( ) => {
116
129
const { container, getByTestId } = render (
117
130
< ParallaxProvider >
118
131
< ParallaxBanner
119
132
layers = { [
120
133
{
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' ,
129
141
} ,
130
142
] }
131
143
/>
132
144
</ ParallaxProvider >
133
145
) ;
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' ) ;
138
152
} ) ;
139
153
} ) ;
140
154
} ) ;
0 commit comments