@@ -26,6 +26,7 @@ describe('given a <ParallaxBanner> component', () => {
2626 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
2727 } ) ;
2828 } ) ;
29+
2930 describe . each ( ALL_PARALLAX_PROPS ) ( 'when the prop %s is given' , ( props ) => {
3031 it ( 'then it renders without issue and calls create element with props' , ( ) => {
3132 const controller = ParallaxController . init ( {
@@ -48,7 +49,11 @@ describe('given a <ParallaxBanner> component', () => {
4849 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
4950 expect ( controller . createElement ) . toBeCalledWith ( {
5051 el : expect . any ( HTMLElement ) ,
51- props : { ...props , shouldDisableScalingTranslations : true } ,
52+ props : {
53+ ...props ,
54+ shouldDisableScalingTranslations : true ,
55+ targetElement : expect . any ( HTMLElement ) ,
56+ } ,
5257 } ) ;
5358 } ) ;
5459 } ) ;
@@ -73,6 +78,7 @@ describe('given a <ParallaxBanner> component', () => {
7378 el : expect . any ( HTMLElement ) ,
7479 props : {
7580 shouldDisableScalingTranslations : true ,
81+ targetElement : expect . any ( HTMLElement ) ,
7682 } ,
7783 } ) ;
7884 } ) ;
@@ -121,18 +127,76 @@ describe('given a <ParallaxBanner> component', () => {
121127 } ) ;
122128 } ) ;
123129
124- describe ( 'with layer expanded' , ( ) => {
125- it ( 'then it will render with expanded styles based on speed' , ( ) => {
126- const { getByTestId } = render (
127- < ParallaxProvider >
128- < ParallaxBanner layers = { [ { speed : 2 } ] } />
129- </ ParallaxProvider >
130- ) ;
131- expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '-20px' ) ;
132- expect ( getByTestId ( 'layer-0' ) . style . right ) . toBe ( '0px' ) ;
133- expect ( getByTestId ( 'layer-0' ) . style . left ) . toBe ( '0px' ) ;
134- expect ( getByTestId ( 'layer-0' ) . style . bottom ) . toBe ( '-20px' ) ;
135- expect ( getByTestId ( 'layer-0' ) . style . position ) . toBe ( 'absolute' ) ;
130+ describe ( 'when the layer is expanded and' , ( ) => {
131+ describe ( 'when the speed prop is set to a positive number' , ( ) => {
132+ it ( 'then it will render with expanded styles based on speed' , ( ) => {
133+ const { getByTestId } = render (
134+ < ParallaxProvider >
135+ < ParallaxBanner layers = { [ { speed : 2 } ] } />
136+ </ ParallaxProvider >
137+ ) ;
138+ expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '-20px' ) ;
139+ expect ( getByTestId ( 'layer-0' ) . style . right ) . toBe ( '0px' ) ;
140+ expect ( getByTestId ( 'layer-0' ) . style . left ) . toBe ( '0px' ) ;
141+ expect ( getByTestId ( 'layer-0' ) . style . bottom ) . toBe ( '-20px' ) ;
142+ expect ( getByTestId ( 'layer-0' ) . style . position ) . toBe ( 'absolute' ) ;
143+ } ) ;
144+ } ) ;
145+ describe ( 'when the speed prop is set to a negative number' , ( ) => {
146+ it ( 'then it will render with expanded styles based on speed' , ( ) => {
147+ const { getByTestId } = render (
148+ < ParallaxProvider >
149+ < ParallaxBanner layers = { [ { speed : - 4 } ] } />
150+ </ ParallaxProvider >
151+ ) ;
152+ expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '-40px' ) ;
153+ expect ( getByTestId ( 'layer-0' ) . style . right ) . toBe ( '0px' ) ;
154+ expect ( getByTestId ( 'layer-0' ) . style . left ) . toBe ( '0px' ) ;
155+ expect ( getByTestId ( 'layer-0' ) . style . bottom ) . toBe ( '-40px' ) ;
156+ expect ( getByTestId ( 'layer-0' ) . style . position ) . toBe ( 'absolute' ) ;
157+ } ) ;
158+ } ) ;
159+ describe ( 'when the translateY prop is set [0px, 10px]' , ( ) => {
160+ it ( 'then it will render with expanded styles based on the translate start end values' , ( ) => {
161+ const { getByTestId } = render (
162+ < ParallaxProvider >
163+ < ParallaxBanner layers = { [ { translateY : [ '0px' , '10px' ] } ] } />
164+ </ ParallaxProvider >
165+ ) ;
166+ expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '-10px' ) ;
167+ expect ( getByTestId ( 'layer-0' ) . style . right ) . toBe ( '0px' ) ;
168+ expect ( getByTestId ( 'layer-0' ) . style . left ) . toBe ( '0px' ) ;
169+ expect ( getByTestId ( 'layer-0' ) . style . bottom ) . toBe ( '0px' ) ;
170+ expect ( getByTestId ( 'layer-0' ) . style . position ) . toBe ( 'absolute' ) ;
171+ } ) ;
172+ } ) ;
173+ describe ( 'when the translateY prop is set [-40px, 30px]' , ( ) => {
174+ it ( 'then it will render with expanded styles based on the translate start end values' , ( ) => {
175+ const { getByTestId } = render (
176+ < ParallaxProvider >
177+ < ParallaxBanner layers = { [ { translateY : [ '-40px' , '30px' ] } ] } />
178+ </ ParallaxProvider >
179+ ) ;
180+ expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '-30px' ) ;
181+ expect ( getByTestId ( 'layer-0' ) . style . right ) . toBe ( '0px' ) ;
182+ expect ( getByTestId ( 'layer-0' ) . style . left ) . toBe ( '0px' ) ;
183+ expect ( getByTestId ( 'layer-0' ) . style . bottom ) . toBe ( '-40px' ) ;
184+ expect ( getByTestId ( 'layer-0' ) . style . position ) . toBe ( 'absolute' ) ;
185+ } ) ;
186+ } ) ;
187+ describe ( 'when the translateY prop is set [0px, 100px]' , ( ) => {
188+ it ( 'then it will render with expanded styles based on the translate start end values' , ( ) => {
189+ const { getByTestId } = render (
190+ < ParallaxProvider >
191+ < ParallaxBanner layers = { [ { translateY : [ '0px' , '100px' ] } ] } />
192+ </ ParallaxProvider >
193+ ) ;
194+ expect ( getByTestId ( 'layer-0' ) . style . top ) . toBe ( '-100px' ) ;
195+ expect ( getByTestId ( 'layer-0' ) . style . right ) . toBe ( '0px' ) ;
196+ expect ( getByTestId ( 'layer-0' ) . style . left ) . toBe ( '0px' ) ;
197+ expect ( getByTestId ( 'layer-0' ) . style . bottom ) . toBe ( '0px' ) ;
198+ expect ( getByTestId ( 'layer-0' ) . style . position ) . toBe ( 'absolute' ) ;
199+ } ) ;
136200 } ) ;
137201 } ) ;
138202 describe ( 'with custom props' , ( ) => {
0 commit comments