2 * mobile Fixed Toolbar unit tests
5 module('jquery.mobile.fixedToolbar.js');
7 $( "html" ).height( screen.height * 3 );
10 window.scrollTo(0,screen.height );
17 module("jquery.mobile.fixedToolbar.js", {setup: function() {
20 // swallow the inital page change
22 $(document).one("pagechange", function() {
23 clearTimeout(startTimeout);
26 startTimeout = setTimeout(start, 1000);
30 test( "Fixed Header Structural Classes are applied correctly", function(){
33 ok( !$('#classes-test-a').hasClass('ui-header-fixed'), 'An ordinary header should not have fixed classes');
34 ok( $('#classes-test-b').hasClass('ui-header-fixed'), 'An header with data-position=fixed should have ui-header-fixed class');
35 ok( $('#classes-test-c').hasClass('ui-header-fullscreen'), 'An header with data-position=fixed and data-fullscreen should have ui-header-fullscreen class');
38 ok( !$('#classes-test-d').hasClass('ui-footer-fixed'), 'An ordinary footer should not have fixed classes');
39 ok( $('#classes-test-e').hasClass('ui-footer-fixed'), 'A footer with data-position=fixed should have ui-footer-fixed class"');
40 ok( $('#classes-test-f').hasClass('ui-footer-fullscreen'), 'A footer with data-position=fixed and data-fullscreen should have ui-footer-fullscreen class');
43 ok( $('#classes-test-b').closest( ".ui-page" ).hasClass( "ui-page-header-fixed" ), "Parent page of a fixed header has class ui-page-header-fixed" );
44 ok( $('#classes-test-e').closest( ".ui-page" ).hasClass( "ui-page-footer-fixed" ), "Parent page of a fixed footer has class ui-page-header-fixed" );
45 ok( $('#classes-test-c').closest( ".ui-page" ).hasClass( "ui-page-header-fullscreen" ), "Parent page of a fullscreen header has class ui-page-header-fullscreen" );
46 ok( $('#classes-test-f').closest( ".ui-page" ).hasClass( "ui-page-footer-fullscreen" ), "Parent page of a fullscreen footer has class ui-page-header-fullscreen" );
51 asyncTest( "Fixed header and footer transition classes are applied correctly", function(){
55 $.testHelper.sequence([
57 $( '#classes-test-b, #classes-test-g, #classes-test-e,#classes-test-h,#classes-test-i,#classes-test-j, #classes-test-k' ).fixedtoolbar( "hide" );
63 $( '#classes-test-b, #classes-test-g, #classes-test-e,#classes-test-h,#classes-test-i,#classes-test-j, #classes-test-k' ).fixedtoolbar( "show" );
68 ok( $( '#classes-test-g' ).hasClass('slidedown'), 'The slidedown class should be applied by default');
69 ok( $( '#classes-test-k' ).hasClass('in'), 'The "in" class should be applied for fade transitions');
70 ok( !$( '#classes-test-h' ).hasClass('slidedown'), 'The slidedown class should not be applied when the header has a data-transition of "none"');
72 ok( !$( '#classes-test-h' ).hasClass('in'), 'The "in" class should not be applied when the header has a data-transition of "none"');
73 ok( $( '#classes-test-i' ).hasClass('slidedown'), 'The "slidedown" class should be applied when the header has a data-transition of "slide"');
74 ok( $( '#classes-test-j' ).hasClass('slideup'), 'The "slideup" class should be applied when the footer has a data-transition of "slide"');
86 test( "User zooming is disabled when the header is visible and disablePageZoom is true", function(){
87 $.mobile.zoom.enable();
88 var defaultZoom = $.mobile.fixedtoolbar.prototype.options.disablePageZoom;
89 $( ".ui-page-active .ui-header-fixed" ).fixedtoolbar("option", "disablePageZoom", true );
91 $( ".ui-page-active" ).trigger( "pagebeforeshow" );
92 ok( !$.mobile.zoom.enabled, "Viewport scaling is disabled before page show." );
93 $( ".ui-page-active .ui-header-fixed" ).fixedtoolbar("option", "disablePageZoom", defaultZoom );
94 $.mobile.zoom.enable();
97 test( "Meta viewport content is restored to previous state, and zooming renabled, after pagebeforehide", function(){
98 $.mobile.zoom.enable( true );
99 var defaultZoom = $.mobile.fixedtoolbar.prototype.options.disablePageZoom;
100 $( ".ui-page-active .ui-header-fixed" ).fixedtoolbar("option", "disablePageZoom", true );
102 $( ".ui-page-active" ).trigger( "pagebeforeshow" );
103 ok( !$.mobile.zoom.enabled, "Viewport scaling is disabled before page show." );
104 $( ".ui-page-active" ).trigger( "pagebeforehide" );
105 ok( $.mobile.zoom.enabled, "Viewport scaling is enabled." );
106 $( ".ui-page-active .ui-header-fixed" ).fixedtoolbar("option", "disablePageZoom", defaultZoom );
107 $.mobile.zoom.enable( true );
110 test( "User zooming is not disabled when the header is visible and disablePageZoom is false", function(){
111 $.mobile.zoom.enable( true );
112 var defaultZoom = $.mobile.fixedtoolbar.prototype.options.disablePageZoom;
113 $( ".ui-page :jqmData(position='fixed')" ).fixedtoolbar( "option", "disablePageZoom", false );
115 $( ".ui-page-active" ).trigger( "pagebeforeshow" );
117 ok( $.mobile.zoom.enabled, "Viewport scaling is not disabled before page show." );
119 $( ".ui-page :jqmData(position='fixed')" ).fixedtoolbar( "option", "disablePageZoom", defaultZoom );
121 $.mobile.zoom.enable( true );
125 asyncTest( "The hide method is working properly", function() {
129 $.testHelper.sequence([
131 $( '#classes-test-g' ).fixedtoolbar( "show" );
136 $( '#classes-test-g' ).fixedtoolbar( "hide" );
138 ok( $( '#classes-test-g' ).hasClass('out'), 'The out class should be applied when hide is called');
142 ok( $( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar has the ui-fixed-hidden class applied after hide');
143 $( '#classes-test-g' ).fixedtoolbar( "show" );
157 asyncTest( "The show method is working properly", function() {
161 $.testHelper.sequence([
167 $( '#classes-test-g' ).fixedtoolbar( "hide" );
171 $( '#classes-test-g' ).fixedtoolbar( "show" );
173 ok( $( '#classes-test-g' ).hasClass('in'), 'The in class should be applied when show is called');
177 ok( !$( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar does not have the ui-fixed-hidden class applied after show');
189 asyncTest( "The toggle method is working properly", function() {
193 $.testHelper.sequence([
199 $( '#classes-test-g' ).fixedtoolbar( "show" );
203 ok( !$( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar does not have the ui-fixed-hidden class');
204 $( '#classes-test-g' ).fixedtoolbar( "toggle" );
208 ok( $( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar does have the ui-fixed-hidden class');
209 $( '#classes-test-g' ).fixedtoolbar( "toggle" );
213 ok( !$( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar does not have the ui-fixed-hidden class');
226 asyncTest( "The persistent headers and footers are working properly", function() {
230 $( "#persist-test-b, #persist-test-a" ).page();
232 var nextpageheader = $( "#persist-test-b .ui-header-fixed" ),
233 nextpagefooter = $( "#persist-test-b .ui-footer-fixed" );
236 $.testHelper.pageSequence([
238 ok( nextpageheader.length && nextpagefooter.length, "next page has fixed header and fixed footer" );
239 $.mobile.changePage( "#persist-test-a" );
243 $( "#persist-test-b" )
244 .one( "pagebeforeshow", function(){
245 ok( nextpageheader.parent( ".ui-mobile-viewport" ).length, "fixed header and footer are now a child of page container" );
248 $.mobile.changePage( "#persist-test-b" );
252 ok( nextpageheader.parent( ".ui-page" ).length, "fixed header and footer are now a child of page again" );
253 $.mobile.changePage( "#default" );
260 asyncTest( "The persistent headers should work without a footer", function() {
264 $( "#persist-test-c, #persist-test-d" ).page();
266 var nextpageheader = $( "#persist-test-d .ui-header-fixed" );
268 $.testHelper.pageSequence([
270 ok( nextpageheader.length, "next page has fixed header and fixed footer" );
271 $.mobile.changePage( "#persist-test-c" );
275 $( "#persist-test-d" )
276 .one( "pagebeforeshow", function(){
277 same( nextpageheader.parent()[0], $.mobile.pageContainer[0], "fixed header is now a child of page container" );
280 $.mobile.changePage( "#persist-test-d" );
284 same( nextpageheader.parent()[0], $.mobile.activePage[0], "fixed header is now a child of page again" );
285 $.mobile.changePage( "#default" );
292 asyncTest( "The persistent footers should work without a header", function() {
296 $( "#persist-test-e, #persist-test-f" ).page();
298 var nextpagefooter = $( "#persist-test-f .ui-footer-fixed" );
300 $.testHelper.pageSequence([
302 ok( nextpagefooter.length, "next page has fixed footer and fixed footer" );
303 $.mobile.changePage( "#persist-test-e" );
307 $( "#persist-test-f" )
308 .one( "pagebeforeshow", function(){
309 same( nextpagefooter.parent()[0], $.mobile.pageContainer[0], "fixed footer is now a child of page container" );
312 $.mobile.changePage( "#persist-test-f" );
316 same( nextpagefooter.parent()[0], $.mobile.activePage[0], "fixed footer is now a child of page again" );
317 $.mobile.changePage( "#default" );
325 var asyncTestFooterAndHeader = function( pageSelector, areHidden ) {
326 $.testHelper.pageSequence([
328 $.mobile.changePage( pageSelector );
332 var $footer = $.mobile.activePage.find( ".ui-footer" ),
333 $header = $.mobile.activePage.find( ".ui-header" ),
334 hidden = areHidden ? "hidden" : "visible";
336 equal( $footer.length, 1, "there should be one footer" );
337 equal( $header.length, 1, "there should be one header" );
339 equal( $footer.hasClass( "ui-fixed-hidden" ), areHidden, "the footer should be " + hiddenStr );
340 equal( $header.hasClass( "ui-fixed-hidden" ), areHidden, "the header should be " + hiddenStr );
342 $.mobile.changePage( "#default" );
349 asyncTest( "data-visible-on-page-show hides toolbars when false", function() {
350 asyncTestFooterAndHeader( "#page-show-visible-false", false );
353 asyncTest( "data-visible-on-page-show shows toolbars when explicitly true", function() {
354 asyncTestFooterAndHeader( "#page-show-visible-true", true );
357 asyncTest( "data-visible-on-page-show shows toolbars when undefined", function() {
358 asyncTestFooterAndHeader( "#page-show-visible-undefined", true );