11/*
22 * mobile navigation unit tests
33 */
4- // TODO move tests to navigation_transitions.js
5- var perspective = "ui-mobile-viewport-perspective" ,
6- transitioning = "ui-mobile-viewport-transitioning" ,
7- animationCompleteFn = $ . fn . animationComplete ,
8-
9- removeBodyClasses = function ( ) {
10- $ ( "body" ) . removeClass ( [ perspective , transitioning ] . join ( " " ) ) ;
11- } ,
12-
13- removePageTransClasses = function ( ) {
14- $ ( "[data-role='page']" ) . removeClass ( "in out fade slide flip reverse pop" ) ;
4+ ( function ( $ ) {
5+ var changePageFn = $ . mobile . changePage ;
6+ module ( 'jquery.mobile.navigation.js' , {
7+ teardown : function ( ) {
8+ $ . mobile . changePage = changePageFn ;
9+ }
10+ } ) ;
11+
12+ test ( "forms with data attribute ajax set to false will not call changePage" , function ( ) {
13+ var called = false ;
14+ $ . mobile . changePage = function ( ) {
15+ called = true ;
1516 } ;
1617
17- module ( 'jquery.mobile.navigation.js' , {
18- setup : function ( ) {
19- //stub to prevent class removal
20- $ . fn . animationComplete = function ( ) { } ;
21- } ,
22-
23- teardown : function ( ) {
24- // unmock animation complete
25- $ . fn . animationComplete = animationCompleteFn ;
26-
27- // required cleanup from animation complete mocking
28- removeBodyClasses ( ) ;
29- }
30- } ) ;
31-
32- test ( "changePage applys perspective class to mobile viewport for flip" , function ( ) {
33- $ ( "#foo > a" ) . click ( ) ;
34-
35- ok ( $ ( "body" ) . hasClass ( perspective ) , "has perspective class" ) ;
36- } ) ;
37-
38- test ( "changePage does not apply perspective class to mobile viewport for transitions other than flip" , function ( ) {
39- $ ( "#bar > a" ) . click ( ) ;
40-
41- ok ( ! $ ( "body" ) . hasClass ( perspective ) , "doesn't have perspective class" ) ;
42- } ) ;
43-
44- test ( "changePage applys transition class to mobile viewport for default transition" , function ( ) {
45- $ ( "#baz > a" ) . click ( ) ;
46-
47- ok ( $ ( "body" ) . hasClass ( transitioning ) , "has transitioning class" ) ;
48- } ) ;
49-
50- test ( "explicit transition preferred for page navigation reversal (ie back)" , function ( ) {
51- $ . fn . animationComplete = function ( ) { } ;
52-
53- stop ( ) ;
54- setTimeout ( function ( ) {
55- $ ( "#fade-trans > a" ) . click ( ) ;
56- } , 300 ) ;
57-
58- setTimeout ( function ( ) {
59- $ ( "#flip-trans > a" ) . click ( ) ;
60- } , 600 ) ;
61-
62- setTimeout ( function ( ) {
63- //guarantee that we check only the newest changes
64- removePageTransClasses ( ) ;
65-
66- $ ( "#fade-trans > a" ) . click ( ) ;
67-
68- ok ( $ ( "#flip-trans" ) . hasClass ( "fade" ) , "has fade class" ) ;
69-
70- start ( ) ;
71- } , 900 ) ;
72- } ) ;
73-
74- test ( "previous transition used when not set and going back through url stack" , function ( ) {
75-
76- stop ( ) ;
77- setTimeout ( function ( ) {
78- $ ( "#no-trans > a" ) . click ( ) ;
79- } , 300 ) ;
80-
81- setTimeout ( function ( ) {
82- $ ( "#pop-trans > a" ) . click ( ) ;
83- } , 600 ) ;
84-
85-
86- setTimeout ( function ( ) {
87- //guarantee that we check only the newest changes
88- removePageTransClasses ( ) ;
89-
90- $ ( "#no-trans > a" ) . click ( ) ;
91-
92- ok ( $ ( "#pop-trans" ) . hasClass ( "pop" ) , "has pop class" ) ;
93-
94- start ( ) ;
95- } , 900 ) ;
96- } ) ;
97-
98- test ( "default transition is slide" , function ( ) {
99- stop ( ) ;
100- setTimeout ( function ( ) {
101- //guarantee that we check only the newest changes
102- removePageTransClasses ( ) ;
103-
104- $ ( "#default-trans > a" ) . click ( ) ;
18+ stop ( ) ;
19+ $ ( '#non-ajax-form' ) . live ( 'submit' , function ( event ) {
20+ ok ( true , 'submit callbacks are fired' ) ;
21+ start ( ) ;
22+ event . preventDefault ( ) ;
23+ } ) . submit ( ) ;
24+
25+ ok ( ! called , "change page should not be called" ) ;
26+ } ) ;
27+
28+ test ( "forms with data attribute ajax not set or set to anything but false will call changepage" , function ( ) {
29+ var called = 0 ;
30+ $ . mobile . changePage = function ( ) {
31+ called += 1 ;
32+ if ( called > 1 ) { start ( ) ; }
33+ } ;
10534
106- ok ( $ ( "#no-trans" ) . hasClass ( "slide" ) , "has slide class" ) ;
35+ stop ( ) ;
36+ $ ( '#ajax-form, #rand-ajax-form' ) . submit ( ) ;
10737
108- start ( ) ;
109- } , 900 ) ;
110- } ) ;
38+ same ( called , 2 , "change page should be called twice" ) ;
39+ } ) ;
40+ } ) ( jQuery ) ;
0 commit comments