@@ -161,4 +161,98 @@ describe('VirtualizedSectionList', () => {
161161 ) ;
162162 expect ( component ) . toMatchSnapshot ( ) ;
163163 } ) ;
164+
165+ describe ( 'scrollToLocation' , ( ) => {
166+ const ITEM_HEIGHT = 100 ;
167+
168+ const createVirtualizedSectionList = props => {
169+ const component = ReactTestRenderer . create (
170+ < VirtualizedSectionList
171+ sections = { [
172+ { title : 's1' , data : [ { key : 'i1.1' } , { key : 'i1.2' } , { key : 'i1.3' } ] } ,
173+ { title : 's2' , data : [ { key : 'i2.1' } , { key : 'i2.2' } , { key : 'i2.3' } ] } ,
174+ ] }
175+ renderItem = { ( { item} ) => < item value = { item . key } /> }
176+ getItem = { ( data , key ) => data [ key ] }
177+ getItemCount = { data => data . length }
178+ getItemLayout = { ( data , index ) => ( {
179+ length : ITEM_HEIGHT ,
180+ offset : ITEM_HEIGHT * index ,
181+ index,
182+ } ) }
183+ { ...props }
184+ /> ,
185+ ) ;
186+ const instance = component . getInstance ( ) ;
187+ const spy = jest . fn ( ) ;
188+ instance . _listRef . scrollToIndex = spy ;
189+ return {
190+ instance,
191+ spy,
192+ } ;
193+ } ;
194+
195+ it ( 'when sticky stickySectionHeadersEnabled={true}, header height is added to the developer-provided viewOffset' , ( ) => {
196+ const { instance, spy} = createVirtualizedSectionList ( {
197+ stickySectionHeadersEnabled : true ,
198+ } ) ;
199+
200+ const viewOffset = 25 ;
201+
202+ instance . scrollToLocation ( {
203+ sectionIndex : 0 ,
204+ itemIndex : 1 ,
205+ viewOffset,
206+ } ) ;
207+ expect ( spy ) . toHaveBeenCalledWith ( {
208+ index : 1 ,
209+ itemIndex : 1 ,
210+ sectionIndex : 0 ,
211+ viewOffset : viewOffset + ITEM_HEIGHT ,
212+ } ) ;
213+ } ) ;
214+
215+ it . each ( [
216+ [
217+ // prevents #18098
218+ { sectionIndex : 0 , itemIndex : 0 } ,
219+ {
220+ index : 0 ,
221+ itemIndex : 0 ,
222+ sectionIndex : 0 ,
223+ viewOffset : 0 ,
224+ } ,
225+ ] ,
226+ [
227+ { sectionIndex : 2 , itemIndex : 1 } ,
228+ {
229+ index : 11 ,
230+ itemIndex : 1 ,
231+ sectionIndex : 2 ,
232+ viewOffset : 0 ,
233+ } ,
234+ ] ,
235+ [
236+ {
237+ sectionIndex : 0 ,
238+ itemIndex : 1 ,
239+ viewOffset : 25 ,
240+ } ,
241+ {
242+ index : 1 ,
243+ itemIndex : 1 ,
244+ sectionIndex : 0 ,
245+ viewOffset : 25 ,
246+ } ,
247+ ] ,
248+ ] ) (
249+ 'given sectionIndex, itemIndex and viewOffset, scrollToIndex is called with correct params' ,
250+ ( scrollToLocationParams , expected ) => {
251+ const { instance, spy} = createVirtualizedSectionList ( ) ;
252+
253+ instance . scrollToLocation ( scrollToLocationParams ) ;
254+ expect ( spy ) . toHaveBeenCalledWith ( expected ) ;
255+ } ,
256+ ) ;
257+ } ) ;
164258} ) ;
0 commit comments