@@ -35,6 +35,38 @@ describe('Ionic ScrollDelegate Service', function() {
35
35
testWithAnimate ( false ) ;
36
36
function testWithAnimate ( animate ) {
37
37
describe ( 'with animate=' + animate , function ( ) {
38
+
39
+ it ( 'should tapScrollToTop' , function ( ) {
40
+ var scope = rootScope . $new ( ) ;
41
+ var el = angular . element ( '<div>' +
42
+ '<div class="not-button"></div>' +
43
+ '<div class="button"></div>' +
44
+ '</div>' ) ;
45
+ //ionic.trigger() REALLY doesnt want to work with tap,
46
+ //so we just mock on to catch the callback and use that...
47
+ var callback ;
48
+ spyOn ( ionic , 'on' ) . andCallFake ( function ( eventName , cb ) {
49
+ callback = cb ;
50
+ } ) ;
51
+ del . tapScrollToTop ( el , animate ) ;
52
+
53
+ spyOn ( del , 'scrollTop' ) ;
54
+ //Don't test the rectContains part, too much to mock
55
+ spyOn ( ionic . DomUtil , 'rectContains' ) . andCallFake ( function ( ) {
56
+ return true ;
57
+ } ) ;
58
+ callback ( {
59
+ target : el [ 0 ] . querySelector ( '.not-button' ) ,
60
+ gesture :{ touches :[ { } ] }
61
+ } ) ;
62
+ expect ( del . scrollTop ) . toHaveBeenCalledWith ( animate ) ;
63
+
64
+ del . scrollTop . reset ( ) ;
65
+ callback ( {
66
+ target : el [ 0 ] . querySelector ( '.button' )
67
+ } ) ;
68
+ expect ( del . scrollTop ) . not . toHaveBeenCalled ( ) ;
69
+ } ) ;
38
70
it ( 'should resize & scroll top' , function ( ) {
39
71
var scope = rootScope . $new ( ) ;
40
72
var el = compile ( '<content start-y="100"></content>' ) ( scope ) ;
0 commit comments