11/*global describe, beforeEach, module, inject, it, expect, runTest */
2- describe ( 'uiScroll main /max indicies' , function ( ) {
2+ describe ( 'uiScroll user min /max indicies. ' , ( ) => {
33 'use strict' ;
44
55 beforeEach ( module ( 'ui.scroll' ) ) ;
66 beforeEach ( module ( 'ui.scroll.test.datasources' ) ) ;
77
8- describe ( 'user min and max indexes' , function ( ) {
9- var viewportHeight = 120 ;
10- var itemHeight = 20 ;
11- var bufferSize = 3 ;
12- var userMinIndex = - 99 ; // for 100 items
13- var userMaxIndex = 100 ;
14-
15- var scrollSettings = {
16- datasource : 'myInfiniteDatasource' ,
17- viewportHeight : viewportHeight ,
18- itemHeight : itemHeight ,
19- bufferSize : bufferSize
20- } ;
21-
22- it ( 'should calculate bottom padding element\'s height after user max index is set' , function ( ) {
23- var setMaxIndex ;
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 = {
15+ datasource : 'myInfiniteDatasource' ,
16+ viewportHeight : viewportHeight ,
17+ itemHeight : itemHeight ,
18+ bufferSize : bufferSize ,
19+ adapter : 'adapter'
20+ } ;
21+
22+ describe ( 'Setting\n' , ( ) => {
23+
24+ it ( 'should calculate bottom padding element\'s height after user max index is set' , ( ) => {
25+ let setMaxIndex ;
2426 inject ( function ( myInfiniteDatasource ) {
25- setMaxIndex = function ( ) {
26- myInfiniteDatasource . maxIndex = userMaxIndex ;
27- } ;
27+ setMaxIndex = ( ) => myInfiniteDatasource . maxIndex = userMaxIndex ;
2828 } ) ;
2929 runTest ( scrollSettings ,
30- function ( viewport ) {
31- var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
30+ ( viewport ) => {
31+ const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
3232 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
3333
3434 setMaxIndex ( ) ;
3535
36- var virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
36+ const virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
3737 expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
3838 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
3939 }
4040 ) ;
4141 } ) ;
4242
43- it ( 'should calculate top padding element\'s height after user min index is set' , function ( ) {
44- var setMinIndex ;
43+ it ( 'should calculate top padding element\'s height after user min index is set' , ( ) => {
44+ let setMinIndex ;
4545 inject ( function ( myInfiniteDatasource ) {
46- setMinIndex = function ( ) {
47- myInfiniteDatasource . minIndex = userMinIndex ;
48- } ;
46+ setMinIndex = ( ) => myInfiniteDatasource . minIndex = userMinIndex ;
4947 } ) ;
5048 runTest ( scrollSettings ,
51- function ( viewport ) {
52- var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
49+ ( viewport ) => {
50+ const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
5351 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
5452
5553 setMinIndex ( ) ;
5654
57- var virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
55+ const virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
5856 expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
5957 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * ( ( - 1 ) * userMinIndex + 1 ) ) ;
6058 }
6159 ) ;
6260 } ) ;
6361
64- it ( 'should work with maxIndex pre-set on datasource' , function ( ) {
62+ } ) ;
63+
64+ describe ( 'Pre-setting\n' , ( ) => {
65+
66+ it ( 'should work with maxIndex pre-set on datasource' , ( ) => {
6567 inject ( function ( myInfiniteDatasource ) {
6668 myInfiniteDatasource . maxIndex = userMaxIndex ;
6769 } ) ;
6870 runTest ( scrollSettings ,
69- function ( viewport ) {
70- var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
71- var virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
71+ ( viewport ) => {
72+ const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
73+ const virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
7274 expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
7375 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
7476 }
7577 ) ;
7678 } ) ;
7779
78- it ( 'should work with minIndex pre-set on datasource' , function ( ) {
80+ it ( 'should work with minIndex pre-set on datasource' , ( ) => {
7981 inject ( function ( myInfiniteDatasource ) {
8082 myInfiniteDatasource . minIndex = userMinIndex ;
8183 } ) ;
8284 runTest ( scrollSettings ,
83- function ( viewport ) {
84- var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
85- var virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
85+ ( viewport ) => {
86+ const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
87+ const virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
8688 expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
8789 expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * ( ( - 1 ) * userMinIndex + 1 ) ) ;
8890 }
@@ -91,4 +93,38 @@ describe('uiScroll main/max indicies', function() {
9193
9294 } ) ;
9395
96+ describe ( 'Reload\n' , ( ) => {
97+
98+ it ( 'should persist user maxIndex after reload' , ( ) => {
99+ inject ( function ( myInfiniteDatasource ) {
100+ myInfiniteDatasource . maxIndex = userMaxIndex ;
101+ } ) ;
102+ runTest ( scrollSettings ,
103+ ( viewport , scope ) => {
104+ scope . adapter . reload ( ) ;
105+ const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
106+ const virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
107+ expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
108+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
109+ }
110+ ) ;
111+ } ) ;
112+
113+ // it('should persist user minIndex after reload', () => {
114+ // inject(function(myInfiniteDatasource) {
115+ // myInfiniteDatasource.minIndex = userMinIndex;
116+ // });
117+ // runTest(scrollSettings,
118+ // (viewport, scope) => {
119+ // scope.adapter.reload();
120+ // const topPaddingElement = angular.element(viewport.children()[0]);
121+ // const virtualItemsAmount = (-1) * userMinIndex - bufferSize + 1;
122+ // expect(topPaddingElement.height()).toBe(itemHeight * virtualItemsAmount);
123+ // expect(viewport.scrollTop()).toBe(itemHeight * ((-1) * userMinIndex + 1));
124+ // }
125+ // );
126+ // });
127+
128+ } ) ;
129+
94130} ) ;
0 commit comments