@@ -69,4 +69,93 @@ describe('A Routes', function () {
6969 } ) ;
7070 } ) ;
7171
72+ describe ( 'that considers ignoreScrollBehavior when calling updateScroll' , function ( ) {
73+ var component ;
74+ beforeEach ( function ( ) {
75+ component = ReactTestUtils . renderIntoDocument (
76+ Routes ( { location : 'none' } ,
77+ Route ( { handler : NullHandler , ignoreScrollBehavior : true } ,
78+ Route ( { path : '/feed' , handler : NullHandler } ) ,
79+ Route ( { path : '/discover' , handler : NullHandler } )
80+ ) ,
81+ Route ( { path : '/search' , handler : NullHandler , ignoreScrollBehavior : true } ) ,
82+ Route ( { path : '/about' , handler : NullHandler } )
83+ )
84+ ) ;
85+ } ) ;
86+
87+ function spyOnUpdateScroll ( action ) {
88+ var didCall = false ;
89+
90+ var realUpdateScroll = component . updateScroll ;
91+ component . updateScroll = function mockUpdateScroll ( ) {
92+ didCall = true ;
93+ realUpdateScroll . apply ( component , arguments ) ;
94+ } ;
95+
96+ try {
97+ action ( ) ;
98+ } finally {
99+ component . updateScroll = realUpdateScroll ;
100+ }
101+
102+ return didCall ;
103+ }
104+
105+ afterEach ( function ( ) {
106+ React . unmountComponentAtNode ( component . getDOMNode ( ) ) ;
107+ } ) ;
108+
109+ it ( 'calls updateScroll when no ancestors ignore scroll' , function ( ) {
110+ component . updateLocation ( '/feed' ) ;
111+
112+ var calledUpdateScroll = spyOnUpdateScroll ( function ( ) {
113+ component . updateLocation ( '/about' ) ;
114+ } ) ;
115+
116+ expect ( calledUpdateScroll ) . toEqual ( true ) ;
117+ } ) ;
118+
119+ it ( 'calls updateScroll when no ancestors ignore scroll even though source and target do' , function ( ) {
120+ component . updateLocation ( '/feed' ) ;
121+
122+ var calledUpdateScroll = spyOnUpdateScroll ( function ( ) {
123+ component . updateLocation ( '/search' ) ;
124+ } ) ;
125+
126+ expect ( calledUpdateScroll ) . toEqual ( true ) ;
127+ } ) ;
128+
129+ it ( 'calls updateScroll when source is same as target and does not ignore scroll' , function ( ) {
130+ component . updateLocation ( '/about' ) ;
131+
132+ var calledUpdateScroll = spyOnUpdateScroll ( function ( ) {
133+ component . updateLocation ( '/about?page=2' ) ;
134+ } ) ;
135+
136+ expect ( calledUpdateScroll ) . toEqual ( true ) ;
137+ } ) ;
138+
139+ it ( 'does not call updateScroll when common ancestor ignores scroll' , function ( ) {
140+ component . updateLocation ( '/feed' ) ;
141+
142+ var calledUpdateScroll = spyOnUpdateScroll ( function ( ) {
143+ component . updateLocation ( '/discover' ) ;
144+ } ) ;
145+
146+ expect ( calledUpdateScroll ) . toEqual ( false ) ;
147+ } ) ;
148+
149+ it ( 'does not call updateScroll when source is same as target and ignores scroll' , function ( ) {
150+ component . updateLocation ( '/search' ) ;
151+
152+ var calledUpdateScroll = spyOnUpdateScroll ( function ( ) {
153+ component . updateLocation ( '/search?q=test' ) ;
154+ } ) ;
155+
156+ expect ( calledUpdateScroll ) . toEqual ( false ) ;
157+ } ) ;
158+
159+ } ) ;
160+
72161} ) ;
0 commit comments