@@ -43,7 +43,9 @@ class TopAppBarWithScroll extends React.Component<ScrollProps, ScrollState> {
43
43
< TopAppBarSection > < TopAppBarTitle > Scroll</ TopAppBarTitle > </ TopAppBarSection >
44
44
</ TopAppBarRow >
45
45
</ TopAppBar >
46
- < div ref = { this . state . scrollRef } > Scroll Target</ div >
46
+ < div ref = { this . state . scrollRef } style = { { height : '1000px' , overflow : 'auto' } } >
47
+ < div style = { { height : '3000px' } } > Scroll Target</ div >
48
+ </ div >
47
49
</ div >
48
50
) ;
49
51
}
@@ -245,6 +247,37 @@ test(
245
247
}
246
248
) ;
247
249
250
+ test ( '#adapter.getViewportScrollY returns same value with scrollTarget.scrollTop' , ( ) => {
251
+ const div = document . createElement ( 'div' ) ;
252
+ document . body . appendChild ( div ) ;
253
+
254
+ const wrapper = mount < TopAppBarWithScroll > ( < TopAppBarWithScroll withRef = { true } /> , { attachTo : div } ) ;
255
+ const topAppBar : TopAppBar = coerceForTesting < TopAppBar > ( wrapper . find ( 'TopAppBar' ) . instance ( ) ) ;
256
+ const scrollTarget = topAppBar . state . scrollTarget ! . current ! ;
257
+ assert . equal ( scrollTarget . scrollTop , topAppBar . adapter . getViewportScrollY ( ) ) ;
258
+
259
+ // https://github.com/material-components/material-components-web-react/pull/771
260
+ // We commented out the code below because linux puppeteer version doesn't scroll.
261
+ // const scrollY = 150;
262
+ // scrollTarget.scrollTo(0, scrollY);
263
+ // assert.equal(scrollY, topAppBar.adapter.getViewportScrollY());
264
+
265
+ document . body . removeChild ( div ) ;
266
+ } ) ;
267
+
268
+ test ( '#adapter.getViewportScrollY test for changing scrollTarget' , ( ) => {
269
+ const div = document . createElement ( 'div' ) ;
270
+ document . body . appendChild ( div ) ;
271
+
272
+ const wrapper = mount < TopAppBarWithScroll > ( < TopAppBarWithScroll withRef = { false } /> , { attachTo : div } ) ;
273
+ const topAppBar : TopAppBar = coerceForTesting < TopAppBar > ( wrapper . find ( 'TopAppBar' ) . instance ( ) ) ;
274
+ assert . equal ( window . pageYOffset , topAppBar . adapter . getViewportScrollY ( ) ) ;
275
+ wrapper . setState ( { withRef : true } ) ;
276
+
277
+ const scrollTarget = topAppBar . state . scrollTarget ! . current ! ;
278
+ assert . equal ( scrollTarget . scrollTop , topAppBar . adapter . getViewportScrollY ( ) ) ;
279
+ document . body . removeChild ( div ) ;
280
+ } ) ;
248
281
249
282
test ( '#adapter.getTotalActionItems returns one with one actionItem passed' , ( ) => {
250
283
const wrapper = mount < TopAppBar > (
@@ -289,7 +322,7 @@ test('#adapter.getTopAppBarHeight should return clientHeight', () => {
289
322
const div = document . createElement ( 'div' ) ;
290
323
// needs to be attached to real DOM to get width
291
324
// https://github.com/airbnb/enzyme/issues/1525
292
- document . body . append ( div ) ;
325
+ document . body . appendChild ( div ) ;
293
326
const options = { attachTo : div } ;
294
327
const wrapper = mount < TopAppBar > (
295
328
< TopAppBar >
@@ -300,7 +333,7 @@ test('#adapter.getTopAppBarHeight should return clientHeight', () => {
300
333
const topAppBarHeight = wrapper . instance ( ) . adapter . getTopAppBarHeight ( ) ;
301
334
const realDOMHeight = wrapper . getDOMNode ( ) . clientHeight ;
302
335
assert . equal ( topAppBarHeight , realDOMHeight ) ;
303
- div . remove ( ) ;
336
+ document . body . removeChild ( div ) ;
304
337
} ) ;
305
338
306
339
test ( 'when changes from short to fixed the foundation changes' , ( ) => {
0 commit comments