@@ -21,44 +21,67 @@ QUnit.module( libName, {
2121 }
2222} ) ;
2323
24- function scrollUp ( assert , pos ) {
25- $ ( window ) . scrollTop ( screen . height ) ;
26- assert . deepEqual ( $ ( window ) . scrollTop ( ) > 0 , true ,
27- "After setting scrollTop, it is " + $ ( window ) . scrollTop ( ) ) ;
28- $ . mobile . silentScroll ( pos ) ;
29- }
30-
31- QUnit . asyncTest ( "silent scroll scrolls the page to the top by default" , function ( assert ) {
32- scrollUp ( assert ) ;
33-
34- setTimeout ( function ( ) {
35- assert . deepEqual ( $ ( window ) . scrollTop ( ) , $ . mobile . defaultHomeScroll ,
36- "After parameterless silentScroll(), scrollTop is $.mobile.defaultHomescroll: " +
37- $ . mobile . defaultHomeScroll ) ;
38- QUnit . start ( ) ;
39- } , scrollTimeout ) ;
24+ QUnit . module ( "Silent scroll tests" , {
25+ afterEach : function ( ) {
26+ $ . mobile . window . scrollTop ( 0 ) ;
27+ }
4028} ) ;
4129
42- QUnit . asyncTest ( "silent scroll scrolls the page to the passed y position " , function ( assert ) {
43- var pos = 10 ;
44- scrollUp ( assert , pos ) ;
30+ QUnit . test ( "scrolling marks scrollstart as disabled for 150 ms " , function ( assert ) {
31+ $ . event . special . scrollstart . enabled = true ;
32+ var done = assert . async ( ) ;
4533
46- setTimeout ( function ( ) {
47- assert . deepEqual ( $ ( window ) . scrollTop ( ) , pos ) ;
48- QUnit . start ( ) ;
49- } , scrollTimeout ) ;
50- } ) ;
34+ $ . mobile . silentScroll ( 100 ) ;
5135
52- QUnit . asyncTest ( "scrolling marks scrollstart as disabled for 150 ms" , function ( assert ) {
53- $ . event . special . scrollstart . enabled = true ;
54- scrollUp ( assert ) ;
5536 assert . ok ( ! $ . event . special . scrollstart . enabled ) ;
5637
57- setTimeout ( function ( ) {
38+ window . setTimeout ( function ( ) {
5839 assert . ok ( $ . event . special . scrollstart . enabled ) ;
59- QUnit . start ( ) ;
40+ done ( ) ;
6041 } , scrollStartEnabledTimeout ) ;
6142} ) ;
6243
44+
45+
46+ QUnit . test ( "Silent scroll works when scrollTop is zero" , function ( assert ) {
47+ assert . expect ( 4 ) ;
48+ var done = assert . async ( ) ;
49+ var done2 = assert . async ( ) ;
50+
51+ $ . mobile . window . scrollTop ( 0 ) ;
52+ assert . equal ( $ . mobile . window . scrollTop ( ) , 0 , "At start, scroll is reset to 0" ) ;
53+
54+ $ . mobile . document . on ( "silentscroll" , function ( e , data ) {
55+ assert . equal ( data . x , 0 , "X coordinate of event should be 0" ) ;
56+ assert . equal ( data . y , 100 , "Y coordinate of event should be 100" ) ;
57+ done ( ) ;
58+ } ) ;
59+
60+ $ . mobile . silentScroll ( 100 ) ;
61+
62+ window . setTimeout ( function ( ) {
63+ assert . equal ( $ . mobile . window . scrollTop ( ) , 100 , "It should work after scrollTimeout" ) ;
64+ done2 ( ) ;
65+ } , scrollTimeout ) ;
66+
67+ } ) ;
68+
69+ QUnit . test ( "Silent scroll doesn't occur when scrollTop is not zero" ,
70+ function ( assert ) {
71+ assert . expect ( 2 ) ;
72+ var done = assert . async ( ) ;
73+
74+ $ . mobile . window . scrollTop ( 150 ) ;
75+ assert . equal ( $ . mobile . window . scrollTop ( ) , 150 , "At start, scroll is reset to 150" ) ;
76+ $ . mobile . silentScroll ( 0 ) ;
77+
78+ window . setTimeout ( function ( ) {
79+ assert . equal ( $ . mobile . window . scrollTop ( ) , 150 ,
80+ "It should not scroll if user has already scrolled" ) ;
81+ done ( ) ;
82+ } , 2000 ) ;
83+ } ) ;
84+
85+
6386//TODO test that silentScroll is called on window load
6487} ) ;
0 commit comments