@@ -5,11 +5,13 @@ describe('uiScroll user min/max indicies.', () => {
55 let datasource ;
66 beforeEach ( module ( 'ui.scroll' ) ) ;
77 beforeEach ( module ( 'ui.scroll.test.datasources' ) ) ;
8- beforeEach (
9- inject ( function ( myInfiniteDatasource ) {
10- datasource = myInfiniteDatasource ;
11- } )
12- ) ;
8+
9+ const injectDatasource = ( datasourceToken ) =>
10+ beforeEach (
11+ inject ( [ datasourceToken , function ( _datasource ) {
12+ datasource = _datasource ;
13+ } ] )
14+ ) ;
1315
1416 const viewportHeight = 120 ;
1517 const itemHeight = 20 ;
@@ -26,6 +28,7 @@ describe('uiScroll user min/max indicies.', () => {
2628 } ;
2729
2830 describe ( 'Setting\n' , ( ) => {
31+ injectDatasource ( 'myInfiniteDatasource' ) ;
2932
3033 it ( 'should calculate bottom padding element\'s height after user max index is set' , ( ) =>
3134 runTest ( scrollSettings ,
@@ -60,6 +63,7 @@ describe('uiScroll user min/max indicies.', () => {
6063 } ) ;
6164
6265 describe ( 'Pre-setting\n' , ( ) => {
66+ injectDatasource ( 'myInfiniteDatasource' ) ;
6367
6468 it ( 'should work with maxIndex pre-set on datasource' , ( ) => {
6569 datasource . maxIndex = userMaxIndex ;
@@ -88,10 +92,15 @@ describe('uiScroll user min/max indicies.', () => {
8892 } ) ;
8993
9094 describe ( 'Reload\n' , ( ) => {
95+ injectDatasource ( 'myResponsiveDatasource' ) ;
96+ beforeEach ( ( ) => {
97+ datasource . min = userMinIndex ;
98+ datasource . max = userMaxIndex ;
99+ } ) ;
91100
92101 it ( 'should persist user maxIndex after reload' , ( ) => {
93102 datasource . maxIndex = userMaxIndex ;
94- runTest ( scrollSettings ,
103+ runTest ( Object . assign ( { } , scrollSettings , { datasource : 'myResponsiveDatasource' } ) ,
95104 ( viewport , scope ) => {
96105 scope . adapter . reload ( ) ;
97106 const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
@@ -104,7 +113,7 @@ describe('uiScroll user min/max indicies.', () => {
104113
105114 it ( 'should persist user minIndex after reload' , ( ) => {
106115 datasource . minIndex = userMinIndex ;
107- runTest ( scrollSettings ,
116+ runTest ( Object . assign ( { } , scrollSettings , { datasource : 'myResponsiveDatasource' } ) ,
108117 ( viewport , scope ) => {
109118 scope . adapter . reload ( ) ;
110119 const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
@@ -115,6 +124,32 @@ describe('uiScroll user min/max indicies.', () => {
115124 ) ;
116125 } ) ;
117126
127+ it ( 'should apply new user minIndex and maxIndex after reload' , ( ) => {
128+ const startIndex = 10 ;
129+ const add = 50 ;
130+ const minIndexNew = userMinIndex - add ;
131+ const maxIndexNew = userMaxIndex + add ;
132+ datasource . minIndex = userMinIndex ;
133+ datasource . maxIndex = userMaxIndex ;
134+ runTest ( Object . assign ( { } , scrollSettings , { datasource : 'myResponsiveDatasource' , startIndex } ) ,
135+ ( viewport , scope ) => {
136+ const _scrollTop = viewport . scrollTop ( ) ;
137+
138+ scope . adapter . reload ( startIndex ) ;
139+ datasource . min = minIndexNew ;
140+ datasource . max = maxIndexNew ;
141+ datasource . minIndex = minIndexNew ;
142+ datasource . maxIndex = maxIndexNew ;
143+
144+ const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
145+ const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
146+ expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * ( ( - 1 ) * minIndexNew + startIndex - bufferSize ) ) ;
147+ expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * ( maxIndexNew - startIndex + 1 - ( viewportHeight / itemHeight ) - bufferSize ) ) ;
148+ expect ( viewport . scrollTop ( ) ) . toBe ( _scrollTop + itemHeight * add ) ;
149+ }
150+ ) ;
151+ } ) ;
152+
118153 } ) ;
119154
120155} ) ;
0 commit comments