2 * mobile page unit tests
5 var libName = 'jquery.mobile.page',
6 themedefault = $.mobile.page.prototype.options.theme,
7 keepNative = $.mobile.page.prototype.options.keepNative;
11 $.mobile.page.prototype.options.keepNative = keepNative;
20 $( document ).bind( "pagebeforecreate pagecreate", function( e ){
21 eventStack.push( e.type );
22 etargets.push( e.target );
25 $( "#c" ).live( "pagebeforecreate", function( e ){
26 cEvents.push( e.type );
27 cTargets.push( e.target );
31 test( "pagecreate event fires when page is created", function(){
32 ok( eventStack[0] === "pagecreate" || eventStack[1] === "pagecreate" );
35 test( "pagebeforecreate event fires when page is created", function(){
36 ok( eventStack[0] === "pagebeforecreate" || eventStack[1] === "pagebeforecreate" );
39 test( "pagebeforecreate fires before pagecreate", function(){
40 ok( eventStack[0] === "pagebeforecreate" );
43 test( "target of pagebeforecreate event was div #a", function(){
44 ok( $( etargets[0] ).is("#a") );
47 test( "target of pagecreate event was div #a" , function(){
48 ok( $( etargets[0] ).is("#a") );
51 test( "page element has ui-page class" , function(){
52 ok( $( "#a" ).hasClass( "ui-page" ) );
55 test( "page element has default body theme when not overidden" , function(){
56 ok( $( "#a" ).hasClass( "ui-body-" + themedefault ) );
59 test( "B page has non-default theme matching its data-theme attr" , function(){
61 var btheme = $( "#b" ).jqmData( "theme" );
62 ok( $( "#b" ).hasClass( "ui-body-" + btheme ) );
65 test( "Binding to pagebeforecreate and returning false prevents pagecreate event from firing" , function(){
68 ok( cEvents[0] === "pagebeforecreate" );
72 test( "Binding to pagebeforecreate and returning false prevents classes from being applied to page" , function(){
75 ok( !$( "#c" ).hasClass( "ui-body-" + themedefault ) );
76 ok( !$( "#c" ).hasClass( "ui-page" ) );
79 test( "keepNativeSelector returns the default where keepNative is not different", function() {
80 var pageProto = $.mobile.page.prototype;
81 pageProto.options.keepNative = pageProto.options.keepNativeDefault;
83 same(pageProto.keepNativeSelector(), pageProto.options.keepNativeDefault);
86 test( "keepNativeSelector returns the default where keepNative is empty, undefined, whitespace", function() {
87 var pageProto = $.mobile.page.prototype;
89 pageProto.options.keepNative = "";
90 same(pageProto.keepNativeSelector(), pageProto.options.keepNativeDefault);
92 pageProto.options.keepNative = undefined;
93 same(pageProto.keepNativeSelector(), pageProto.options.keepNativeDefault);
95 pageProto.options.keepNative = " ";
96 same(pageProto.keepNativeSelector(), pageProto.options.keepNativeDefault);
99 test( "keepNativeSelector returns a selector joined with the default", function() {
100 var pageProto = $.mobile.page.prototype;
102 pageProto.options.keepNative = "foo, bar";
103 same(pageProto.keepNativeSelector(), "foo, bar, " + pageProto.options.keepNativeDefault);
106 test( "links inside an ignored container do not enhance", function() {
107 var $ignored = $( "#ignored-link" ), $enhanced = $( "#enhanced-link" );
109 $.mobile.ignoreContentEnabled = true;
111 $ignored.parent().trigger( "create" );
112 same( $ignored.attr( "class" ), undefined, "ignored link doesn't have link class" );
114 $enhanced.parent().trigger( "create" );
115 same( $enhanced.attr( "class" ).indexOf("ui-link"), 0, "enhanced link has link class" );
117 $.mobile.ignoreContentEnabled = false;
121 asyncTest( "page container is updated to page theme at pagebeforeshow", function(){
125 var pageTheme = "ui-overlay-" + $.mobile.activePage.page( "option", "theme" );
127 $.mobile.pageContainer.removeClass( pageTheme );
130 .bind( "pagebeforeshow", function(){
131 ok( $.mobile.pageContainer.hasClass( pageTheme ), "Page container has the same theme as the page on pagebeforeshow" );
134 .trigger( "pagebeforeshow" );
138 asyncTest( "page container is updated to page theme at pagebeforeshow", function(){
142 var pageTheme = "ui-overlay-" + $.mobile.activePage.page( "option", "theme" );
144 $.mobile.pageContainer.addClass( pageTheme );
147 .bind( "pagebeforehide", function(){
148 ok( !$.mobile.pageContainer.hasClass( pageTheme ), "Page container does not have the same theme as the page on pagebeforeshow" );
151 .trigger( "pagebeforehide" );