@@ -2,7 +2,7 @@ import React from 'react';
22import { mount } from 'enzyme' ;
33import sinon from 'sinon' ;
44import { noop } from 'utility/memory' ;
5- import Scrollable from './Scrollable ' ;
5+ import Scrollable from './' ;
66import { normalizeScrollPosition } from './Scrollable.utils' ;
77import { SCROLLING_CLASS_REMOVAL_DELAY } from './Scrollable.constants' ;
88
@@ -18,6 +18,19 @@ describe('<Scrollable/>', () => {
1818 expect ( wrapper . find ( 'VerticalScrollbar' ) ) . toHaveLength ( 1 ) ;
1919 expect ( wrapper . find ( 'HorizontalScrollbar' ) ) . toHaveLength ( 1 ) ;
2020 } ) ;
21+
22+ it ( 'should render a Scrollbar with custom vertical & horizontal scrollbars' , ( ) => {
23+ const wrapper = mount (
24+ < Scrollable >
25+ < Scrollable . VerticalScrollbar > < div className = 'vsb-child' > </ div > </ Scrollable . VerticalScrollbar >
26+ < Scrollable . HorizontalScrollbar > < div className = 'hsb-child' > </ div > </ Scrollable . HorizontalScrollbar >
27+ </ Scrollable >
28+ ) ;
29+ expect ( wrapper . find ( '.scrollbar' ) ) . toHaveLength ( 1 ) ;
30+ expect ( wrapper . find ( 'ResizeObserver' ) ) . toHaveLength ( 1 ) ;
31+ expect ( wrapper . find ( '.vsb-child' ) ) . toHaveLength ( 1 ) ;
32+ expect ( wrapper . find ( '.hsb-child' ) ) . toHaveLength ( 1 ) ;
33+ } ) ;
2134 } ) ;
2235
2336 describe ( 'Life Cycle' , ( ) => {
@@ -34,14 +47,26 @@ describe('<Scrollable/>', () => {
3447 expect ( s . getSnapshotBeforeUpdate ( ) ) . toEqual ( s . container . current ) ;
3548 } ) ;
3649
37- it ( 'componentDidUpdate()' , ( ) => {
38- const s = new Scrollable ( { scrollOnDOMChange : false } ) ;
39- s . container = { current : { scrollTop : 0 } } ;
40- s . updateScrollbars = sinon . spy ( ) ;
41- s . componentDidUpdate ( null , null , { scrollTop : 50 , scrollLeft : 50 } ) ;
42- expect ( s . container . current . scrollTop ) . toEqual ( 50 ) ;
43- expect ( s . container . current . scrollLeft ) . toEqual ( 50 ) ;
44- expect ( s . updateScrollbars . callCount ) . toEqual ( 1 ) ;
50+ describe ( 'componentDidUpdate' , ( ) => {
51+ it ( 'scrollOnDOMChange prop "true"' , ( ) => {
52+ const s = new Scrollable ( { scrollOnDOMChange : true } ) ;
53+ s . container = { current : { scrollTop : 0 , scrollLeft : 0 } } ;
54+ s . updateScrollbars = sinon . spy ( ) ;
55+ s . componentDidUpdate ( null , null , { scrollTop : 50 , scrollLeft : 50 } ) ;
56+ expect ( s . container . current . scrollTop ) . toEqual ( 0 ) ;
57+ expect ( s . container . current . scrollLeft ) . toEqual ( 0 ) ;
58+ expect ( s . updateScrollbars . callCount ) . toEqual ( 1 ) ;
59+ } ) ;
60+
61+ it ( 'scrollOnDOMChange prop "false"' , ( ) => {
62+ const s = new Scrollable ( { scrollOnDOMChange : false } ) ;
63+ s . container = { current : { scrollTop : 0 } } ;
64+ s . updateScrollbars = sinon . spy ( ) ;
65+ s . componentDidUpdate ( null , null , { scrollTop : 50 , scrollLeft : 50 } ) ;
66+ expect ( s . container . current . scrollTop ) . toEqual ( 50 ) ;
67+ expect ( s . container . current . scrollLeft ) . toEqual ( 50 ) ;
68+ expect ( s . updateScrollbars . callCount ) . toEqual ( 1 ) ;
69+ } ) ;
4570 } ) ;
4671 } ) ;
4772
@@ -162,7 +187,6 @@ describe('<Scrollable/>', () => {
162187 expect ( global . window . requestAnimationFrame . callCount ) . toEqual ( 1 ) ;
163188 global . window . requestAnimationFrame . args [ 0 ] [ 0 ] ( ) ;
164189 expect ( toggle . callCount ) . toEqual ( 2 ) ;
165-
166190 expect ( containerSetProperty . callCount ) . toEqual ( 2 ) ;
167191 expect ( hTrackSetProperty . callCount ) . toEqual ( 1 ) ;
168192 expect ( vTrackSetProperty . callCount ) . toEqual ( 1 ) ;
0 commit comments