@@ -2,24 +2,38 @@ describe('ionicInfiniteScroll directive', function() {
2
2
beforeEach ( module ( 'ionic' ) ) ;
3
3
4
4
var scrollTopValue ;
5
- var scrollMaxValue ;
5
+ var scrollTopMaxValue ;
6
+ var scrollLeftValue ;
7
+ var scrollLeftMaxValue ;
6
8
var ctrl ;
7
- function setup ( attrs , scopeProps ) {
9
+ function setup ( attrs , scopeProps , options ) {
8
10
var element ;
9
11
scrollTopValue = 50 ;
10
- scrollMaxValue = 101 ;
12
+ scrollLeftValue = 60 ;
13
+ scrollLeftMaxValue = 101 ;
14
+ scrollTopMaxValue = 121 ;
11
15
inject ( function ( $rootScope , $compile ) {
12
16
var scope = $rootScope . $new ( ) ;
13
17
angular . extend ( scope , scopeProps || { } ) ;
14
18
element = angular . element ( '<ion-infinite-scroll ' + ( attrs || '' ) + '></ion-infinite-scroll>' ) ;
15
19
ionic . animationFrameThrottle = function ( cb ) { return function ( ) { cb ( ) ; } ; } ;
16
20
element . data ( '$$ionicScrollController' , {
17
21
scrollView : {
22
+ options : angular . extend ( {
23
+ scrollingX : true ,
24
+ scrollingY : true
25
+ } , options || { } ) ,
18
26
getValues : jasmine . createSpy ( 'getValues' ) . andCallFake ( function ( ) {
19
- return { top : scrollTopValue } ;
27
+ return {
28
+ left : scrollLeftValue ,
29
+ top : scrollTopValue
30
+ } ;
20
31
} ) ,
21
32
getScrollMax : jasmine . createSpy ( 'getScrollMax' ) . andCallFake ( function ( ) {
22
- return { top : scrollMaxValue } ;
33
+ return {
34
+ left : scrollLeftMaxValue ,
35
+ top : scrollTopMaxValue
36
+ } ;
23
37
} ) ,
24
38
resize : jasmine . createSpy ( 'resize' )
25
39
} ,
@@ -70,27 +84,62 @@ describe('ionicInfiniteScroll directive', function() {
70
84
} ) ;
71
85
72
86
describe ( 'getMaxScroll' , function ( ) {
73
- it ( 'getMaxScroll should default to 1%' , function ( ) {
74
- var el = setup ( ) ;
75
- expect ( ctrl . getMaxScroll ( ) ) . toBe ( 101 * 0.99 ) ;
76
- } ) ;
77
-
78
- it ( 'getMaxScroll should use attr.distance as number' , function ( ) {
79
- var el = setup ( 'distance=3' ) ;
80
- expect ( ctrl . getMaxScroll ( ) ) . toBe ( 98 ) ;
81
- } ) ;
87
+ [ { scrollingX : true , scrollingY : true , } ,
88
+ { scrollingX : false , scrollingY : true } ,
89
+ { scrollingX : true , scrollingY : false }
90
+ ] . forEach ( function ( opts ) {
91
+
92
+ describe ( 'with scrollingX=' + opts . scrollingX + ', scrollingY=' + opts . scrollingY , function ( ) {
93
+ it ( 'should default to 1%' , function ( ) {
94
+ var el = setup ( '' , { } , opts ) ;
95
+ expect ( ctrl . getMaxScroll ( ) ) . toEqual ( {
96
+ left : opts . scrollingX ? scrollLeftMaxValue * 0.99 : - 1 ,
97
+ top : opts . scrollingY ? scrollTopMaxValue * 0.99 : - 1
98
+ } ) ;
99
+ } ) ;
100
+
101
+ it ( 'should use attr.distance as number' , function ( ) {
102
+ var el = setup ( 'distance=3' , { } , opts ) ;
103
+ expect ( ctrl . getMaxScroll ( ) ) . toEqual ( {
104
+ left : opts . scrollingX ? scrollLeftMaxValue - 3 : - 1 ,
105
+ top : opts . scrollingY ? scrollTopMaxValue - 3 : - 1
106
+ } ) ;
107
+ } ) ;
108
+
109
+ it ( 'should use attr.distance as percent' , function ( ) {
110
+ var el = setup ( 'distance=5%' , { } , opts ) ;
111
+ expect ( ctrl . getMaxScroll ( ) ) . toEqual ( {
112
+ left : opts . scrollingX ? scrollLeftMaxValue * 0.95 : - 1 ,
113
+ top : opts . scrollingY ? scrollTopMaxValue * 0.95 : - 1
114
+ } ) ;
115
+ } ) ;
116
+ } ) ;
82
117
83
- it ( 'getMaxScroll should use attr.distance as percent' , function ( ) {
84
- var el = setup ( 'distance=5%' ) ;
85
- expect ( ctrl . getMaxScroll ( ) ) . toBe ( 101 * 0.95 ) ;
86
118
} ) ;
87
119
} ) ;
88
120
89
121
describe ( 'scroll event' , function ( ) {
90
122
91
- it ( 'should add active and call attr.onInfinite if past top' , function ( ) {
123
+ it ( 'should do nothing if < left and top' , function ( ) {
124
+ var el = setup ( 'on-infinite="foo=1"' ) ;
125
+ el . controller ( '$ionicScroll' ) . $element . triggerHandler ( 'scroll' ) ;
126
+
127
+ expect ( el . hasClass ( 'active' ) ) . toBe ( false ) ;
128
+ expect ( ctrl . isLoading ) . toBe ( false ) ;
129
+ expect ( el . scope ( ) . foo ) . not . toBe ( 1 ) ;
130
+ } ) ;
131
+ it ( 'should add active and call attr.onInfinite if >= top' , function ( ) {
132
+ var el = setup ( 'on-infinite="foo=1"' ) ;
133
+ scrollTopValue = scrollTopMaxValue ;
134
+ el . controller ( '$ionicScroll' ) . $element . triggerHandler ( 'scroll' ) ;
135
+
136
+ expect ( el . hasClass ( 'active' ) ) . toBe ( true ) ;
137
+ expect ( ctrl . isLoading ) . toBe ( true ) ;
138
+ expect ( el . scope ( ) . foo ) . toBe ( 1 ) ;
139
+ } ) ;
140
+ it ( 'should add active and call attr.onInfinite if >= left' , function ( ) {
92
141
var el = setup ( 'on-infinite="foo=1"' ) ;
93
- scrollTopValue = scrollMaxValue ;
142
+ scrollLeftValue = scrollLeftMaxValue ;
94
143
el . controller ( '$ionicScroll' ) . $element . triggerHandler ( 'scroll' ) ;
95
144
96
145
expect ( el . hasClass ( 'active' ) ) . toBe ( true ) ;
@@ -100,7 +149,7 @@ describe('ionicInfiniteScroll directive', function() {
100
149
it ( 'should not run the event twice if isLoading is true' , function ( ) {
101
150
var onScrollSpy = jasmine . createSpy ( 'onInfiniteScroll' ) ;
102
151
var el = setup ( '' , { $onInfiniteScroll : onScrollSpy } ) ;
103
- scrollTopValue = scrollMaxValue ;
152
+ scrollTopValue = scrollTopMaxValue ;
104
153
el . controller ( '$ionicScroll' ) . $element . triggerHandler ( 'scroll' ) ;
105
154
106
155
expect ( el . hasClass ( 'active' ) ) . toBe ( true ) ;
0 commit comments