jquery-mobile/tests/unit/page/page_core.js
scottjehl 2a6c7fc1b9 This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.

- Unit tests have been added and adjusted to support some internal changes involved in this commit.

- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.

- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.

- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 22:25:23 -04:00

78 lines
2 KiB
JavaScript

/*
* mobile page unit tests
*/
(function($){
var libName = 'jquery.mobile.page.sections.js',
themedefault = $.mobile.page.prototype.options.theme;
module(libName);
var eventStack = [],
etargets = [],
cEvents=[],
cTargets=[];
$( document ).bind( "pagebeforecreate pagecreate", function( e ){
eventStack.push( e.type );
etargets.push( e.target );
});
$("#c").live( "pagebeforecreate", function( e ){
cEvents.push( e.type );
cTargets.push( e.target );
return false;
});
test( "pagecreate event fires when page is created", function(){
ok( eventStack[0] === "pagecreate" || eventStack[1] === "pagecreate" );
});
test( "pagebeforecreate event fires when page is created", function(){
ok( eventStack[0] === "pagebeforecreate" || eventStack[1] === "pagebeforecreate" );
});
test( "pagebeforecreate fires before pagecreate", function(){
ok( eventStack[0] === "pagebeforecreate" );
});
test( "target of pagebeforecreate event was div #a", function(){
ok( $( etargets[0] ).is("#a") );
});
test( "target of pagecreate event was div #a" , function(){
ok( $( etargets[0] ).is("#a") );
});
test( "page element has ui-page class" , function(){
ok( $( "#a" ).hasClass( "ui-page" ) );
});
test( "page element has default body theme when not overidden" , function(){
ok( $( "#a" ).hasClass( "ui-body-" + themedefault ) );
});
test( "B page has non-default theme matching its data-theme attr" , function(){
$( "#b" ).page();
var btheme = $( "#b" ).jqmData( "theme" );
ok( $( "#b" ).hasClass( "ui-body-" + btheme ) );
});
test( "Binding to pagebeforecreate and returning false prevents pagecreate event from firing" , function(){
$("#c").page();
ok( cEvents[0] === "pagebeforecreate" );
ok( !cTargets[1] );
});
test( "Binding to pagebeforecreate and returning false prevents classes from being applied to page" , function(){
ok( !$( "#b" ).hasClass( "ui-body-" + themedefault ) );
ok( !$( "#b" ).hasClass( "ui-page" ) );
});
})(jQuery);