@@ -5,11 +5,13 @@ describe('uiScroll user min/max indicies.', () => {
5
5
let datasource ;
6
6
beforeEach ( module ( 'ui.scroll' ) ) ;
7
7
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
+ ) ;
13
15
14
16
const viewportHeight = 120 ;
15
17
const itemHeight = 20 ;
@@ -26,6 +28,7 @@ describe('uiScroll user min/max indicies.', () => {
26
28
} ;
27
29
28
30
describe ( 'Setting\n' , ( ) => {
31
+ injectDatasource ( 'myInfiniteDatasource' ) ;
29
32
30
33
it ( 'should calculate bottom padding element\'s height after user max index is set' , ( ) =>
31
34
runTest ( scrollSettings ,
@@ -60,6 +63,7 @@ describe('uiScroll user min/max indicies.', () => {
60
63
} ) ;
61
64
62
65
describe ( 'Pre-setting\n' , ( ) => {
66
+ injectDatasource ( 'myInfiniteDatasource' ) ;
63
67
64
68
it ( 'should work with maxIndex pre-set on datasource' , ( ) => {
65
69
datasource . maxIndex = userMaxIndex ;
@@ -88,10 +92,15 @@ describe('uiScroll user min/max indicies.', () => {
88
92
} ) ;
89
93
90
94
describe ( 'Reload\n' , ( ) => {
95
+ injectDatasource ( 'myResponsiveDatasource' ) ;
96
+ beforeEach ( ( ) => {
97
+ datasource . min = userMinIndex ;
98
+ datasource . max = userMaxIndex ;
99
+ } ) ;
91
100
92
101
it ( 'should persist user maxIndex after reload' , ( ) => {
93
102
datasource . maxIndex = userMaxIndex ;
94
- runTest ( scrollSettings ,
103
+ runTest ( Object . assign ( { } , scrollSettings , { datasource : 'myResponsiveDatasource' } ) ,
95
104
( viewport , scope ) => {
96
105
scope . adapter . reload ( ) ;
97
106
const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
@@ -104,7 +113,7 @@ describe('uiScroll user min/max indicies.', () => {
104
113
105
114
it ( 'should persist user minIndex after reload' , ( ) => {
106
115
datasource . minIndex = userMinIndex ;
107
- runTest ( scrollSettings ,
116
+ runTest ( Object . assign ( { } , scrollSettings , { datasource : 'myResponsiveDatasource' } ) ,
108
117
( viewport , scope ) => {
109
118
scope . adapter . reload ( ) ;
110
119
const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
@@ -115,6 +124,32 @@ describe('uiScroll user min/max indicies.', () => {
115
124
) ;
116
125
} ) ;
117
126
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
+
118
153
} ) ;
119
154
120
155
} ) ;
0 commit comments