22describe ( 'uiScroll user min/max indicies.' , ( ) => {
33 'use strict' ;
44
5+ let datasource ;
56 beforeEach ( module ( 'ui.scroll' ) ) ;
67 beforeEach ( module ( 'ui.scroll.test.datasources' ) ) ;
7-
8- var viewportHeight = 120 ;
9- var itemHeight = 20 ;
10- var bufferSize = 3 ;
11- var userMinIndex = - 99 ; // for 100 items
12- var userMaxIndex = 100 ;
13-
14- var scrollSettings = {
8+ beforeEach (
9+ inject ( function ( myInfiniteDatasource ) {
10+ datasource = myInfiniteDatasource ;
11+ } )
12+ ) ;
13+
14+ const viewportHeight = 120 ;
15+ const itemHeight = 20 ;
16+ const bufferSize = 3 ;
17+ const userMinIndex = - 99 ; // for 100 items
18+ const userMaxIndex = 100 ;
19+
20+ const scrollSettings = {
1521 datasource : 'myInfiniteDatasource' ,
1622 viewportHeight : viewportHeight ,
1723 itemHeight : itemHeight ,
@@ -21,52 +27,42 @@ describe('uiScroll user min/max indicies.', () => {
2127
2228 describe ( 'Setting\n' , ( ) => {
2329
24- it ( 'should calculate bottom padding element\'s height after user max index is set' , ( ) => {
25- let setMaxIndex ;
26- inject ( function ( myInfiniteDatasource ) {
27- setMaxIndex = ( ) => myInfiniteDatasource . maxIndex = userMaxIndex ;
28- } ) ;
30+ it ( 'should calculate bottom padding element\'s height after user max index is set' , ( ) =>
2931 runTest ( scrollSettings ,
3032 ( viewport ) => {
3133 const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
3234 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
3335
34- setMaxIndex ( ) ;
36+ datasource . maxIndex = userMaxIndex ;
3537
3638 const virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
3739 expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
3840 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
3941 }
40- ) ;
41- } ) ;
42+ )
43+ ) ;
4244
43- it ( 'should calculate top padding element\'s height after user min index is set' , ( ) => {
44- let setMinIndex ;
45- inject ( function ( myInfiniteDatasource ) {
46- setMinIndex = ( ) => myInfiniteDatasource . minIndex = userMinIndex ;
47- } ) ;
45+ it ( 'should calculate top padding element\'s height after user min index is set' , ( ) =>
4846 runTest ( scrollSettings ,
4947 ( viewport ) => {
5048 const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
5149 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
5250
53- setMinIndex ( ) ;
51+ datasource . minIndex = userMinIndex ;
5452
5553 const virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
5654 expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
5755 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * ( ( - 1 ) * userMinIndex + 1 ) ) ;
5856 }
59- ) ;
60- } ) ;
57+ )
58+ ) ;
6159
6260 } ) ;
6361
6462 describe ( 'Pre-setting\n' , ( ) => {
6563
6664 it ( 'should work with maxIndex pre-set on datasource' , ( ) => {
67- inject ( function ( myInfiniteDatasource ) {
68- myInfiniteDatasource . maxIndex = userMaxIndex ;
69- } ) ;
65+ datasource . maxIndex = userMaxIndex ;
7066 runTest ( scrollSettings ,
7167 ( viewport ) => {
7268 const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
@@ -78,9 +74,7 @@ describe('uiScroll user min/max indicies.', () => {
7874 } ) ;
7975
8076 it ( 'should work with minIndex pre-set on datasource' , ( ) => {
81- inject ( function ( myInfiniteDatasource ) {
82- myInfiniteDatasource . minIndex = userMinIndex ;
83- } ) ;
77+ datasource . minIndex = userMinIndex ;
8478 runTest ( scrollSettings ,
8579 ( viewport ) => {
8680 const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
@@ -96,9 +90,7 @@ describe('uiScroll user min/max indicies.', () => {
9690 describe ( 'Reload\n' , ( ) => {
9791
9892 it ( 'should persist user maxIndex after reload' , ( ) => {
99- inject ( function ( myInfiniteDatasource ) {
100- myInfiniteDatasource . maxIndex = userMaxIndex ;
101- } ) ;
93+ datasource . maxIndex = userMaxIndex ;
10294 runTest ( scrollSettings ,
10395 ( viewport , scope ) => {
10496 scope . adapter . reload ( ) ;
@@ -111,9 +103,7 @@ describe('uiScroll user min/max indicies.', () => {
111103 } ) ;
112104
113105 it ( 'should persist user minIndex after reload' , ( ) => {
114- inject ( function ( myInfiniteDatasource ) {
115- myInfiniteDatasource . minIndex = userMinIndex ;
116- } ) ;
106+ datasource . minIndex = userMinIndex ;
117107 runTest ( scrollSettings ,
118108 ( viewport , scope ) => {
119109 scope . adapter . reload ( ) ;
0 commit comments