PageRenderTime 71ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/integration/fixed-toolbar/fixedToolbar.js

https://github.com/gseguin/jquery-mobile
JavaScript | 316 lines | 226 code | 85 blank | 5 comment | 1 complexity | 2c4d5c90a746e4e5df7681e248fea0f1 MD5 | raw file
  1. /*
  2. * mobile Fixed Toolbar unit tests
  3. */
  4. (function($){
  5. $( "html" ).height( screen.height * 3 );
  6. function scrollDown(){
  7. window.scrollTo(0,screen.height );
  8. }
  9. function scrollUp(){
  10. window.scrollTo(0,0);
  11. }
  12. module("jquery.mobile.toolbar.js", {setup: function() {
  13. var startTimeout;
  14. // swallow the inital page change
  15. stop();
  16. $(document).one("pagechange", function() {
  17. clearTimeout(startTimeout);
  18. });
  19. startTimeout = setTimeout( start , 1000);
  20. }});
  21. asyncTest( "Fixed header and footer transition classes are applied correctly", function(){
  22. expect( 5 );
  23. $.testHelper.sequence([
  24. function(){
  25. $( '#classes-test-b, #classes-test-g, #classes-test-e,#classes-test-h,#classes-test-i,#classes-test-j, #classes-test-k' ).toolbar( "hide" );
  26. scrollDown();
  27. },
  28. function(){
  29. //show first
  30. $( '#classes-test-b, #classes-test-g, #classes-test-e,#classes-test-h,#classes-test-i,#classes-test-j, #classes-test-k' ).toolbar( "show" );
  31. },
  32. function() {
  33. ok( $( '#classes-test-g' ).hasClass('slidedown'), 'The slidedown class should be applied by default');
  34. ok( !$( '#classes-test-h' ).hasClass('slidedown'), 'The slidedown class should not be applied when the header has a data-transition of "none"');
  35. ok( !$( '#classes-test-h' ).hasClass('in'), 'The "in" class should not be applied when the header has a data-transition of "none"');
  36. ok( $( '#classes-test-i' ).hasClass('slidedown'), 'The "slidedown" class should be applied when the header has a data-transition of "slide"');
  37. ok( $( '#classes-test-j' ).hasClass('slideup'), 'The "slideup" class should be applied when the footer has a data-transition of "slide"');
  38. },
  39. function(){
  40. scrollUp();
  41. start();
  42. }
  43. ], 1000);
  44. });
  45. asyncTest( "The hide method is working properly", function() {
  46. expect( 2 );
  47. $.testHelper.sequence([
  48. function(){
  49. $( '#classes-test-g' ).toolbar( "show" );
  50. scrollDown();
  51. },
  52. function() {
  53. $( '#classes-test-g' ).toolbar( "hide" );
  54. ok( $( '#classes-test-g' ).hasClass('out'), 'The out class should be applied when hide is called');
  55. },
  56. function() {
  57. ok( $( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar has the ui-fixed-hidden class applied after hide');
  58. $( '#classes-test-g' ).toolbar( "show" );
  59. },
  60. function(){
  61. scrollUp();
  62. start();
  63. }
  64. ], 700);
  65. });
  66. asyncTest( "The show method is working properly", function() {
  67. expect( 2 );
  68. $.testHelper.sequence([
  69. function(){
  70. scrollDown();
  71. },
  72. function() {
  73. $( '#classes-test-g' ).toolbar( "hide" );
  74. },
  75. function() {
  76. $( '#classes-test-g' ).toolbar( "show" );
  77. ok( $( '#classes-test-g' ).hasClass('in'), 'The in class should be applied when show is called');
  78. },
  79. function() {
  80. ok( !$( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar does not have the ui-fixed-hidden class applied after show');
  81. },
  82. function(){
  83. scrollUp();
  84. start();
  85. }
  86. ], 700);
  87. });
  88. asyncTest( "The toggle method is working properly", function() {
  89. expect( 3 );
  90. $.testHelper.sequence([
  91. function(){
  92. scrollDown();
  93. },
  94. function(){
  95. $( '#classes-test-g' ).toolbar( "show" );
  96. },
  97. function() {
  98. ok( !$( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar does not have the ui-fixed-hidden class');
  99. },
  100. function() {
  101. $( '#classes-test-g' ).toolbar( "toggle" );
  102. },
  103. function() {
  104. ok( $( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar does have the ui-fixed-hidden class');
  105. },
  106. function() {
  107. $( '#classes-test-g' ).toolbar( "toggle" );
  108. },
  109. function() {
  110. ok( !$( '#classes-test-g' ).hasClass('ui-fixed-hidden'), 'The toolbar does not have the ui-fixed-hidden class');
  111. },
  112. function(){
  113. scrollUp();
  114. start();
  115. }
  116. ], 500);
  117. });
  118. asyncTest( "Fullscreen toolbars add classes to page", function() {
  119. expect( 2 );
  120. $.testHelper.sequence([
  121. function(){
  122. $.mobile.changePage( "#fullscreen-test-a" );
  123. },
  124. function(){
  125. ok( $('#classes-test-l').closest( ".ui-page" ).hasClass( "ui-page-header-fullscreen" ), "Parent page of a fullscreen header has class ui-page-header-fullscreen" );
  126. ok( $('#classes-test-m').closest( ".ui-page" ).hasClass( "ui-page-footer-fullscreen" ), "Parent page of a fullscreen footer has class ui-page-header-fullscreen" );
  127. },
  128. function(){
  129. scrollUp();
  130. start();
  131. }
  132. ], 500);
  133. });
  134. asyncTest( "The persistent headers and footers are working properly", function() {
  135. expect( 3 );
  136. $( "#persist-test-b, #persist-test-a" ).page();
  137. var nextpageheader = $( "#persist-test-b .ui-header-fixed" ),
  138. nextpagefooter = $( "#persist-test-b .ui-footer-fixed" );
  139. $.testHelper.pageSequence([
  140. function(){
  141. ok( nextpageheader.length && nextpagefooter.length, "next page has fixed header and fixed footer" );
  142. $.mobile.changePage( "#persist-test-a" );
  143. },
  144. function(){
  145. $( "#persist-test-b" )
  146. .one( "pagebeforeshow", function(){
  147. ok( nextpageheader.parent( ".ui-mobile-viewport" ).length, "fixed header and footer are now a child of page container" );
  148. });
  149. $.mobile.changePage( "#persist-test-b" );
  150. },
  151. function() {
  152. ok( nextpageheader.parent( ".ui-page" ).length, "fixed header and footer are now a child of page again" );
  153. $.mobile.changePage( "#default" );
  154. },
  155. start
  156. ]);
  157. });
  158. asyncTest( "The persistent headers should work without a footer", function() {
  159. expect( 3 );
  160. $( "#persist-test-c, #persist-test-d" ).page();
  161. var nextpageheader = $( "#persist-test-d .ui-header-fixed" );
  162. $.testHelper.pageSequence([
  163. function(){
  164. ok( nextpageheader.length, "next page has fixed header and fixed footer" );
  165. $.mobile.changePage( "#persist-test-c" );
  166. },
  167. function(){
  168. $( "#persist-test-d" )
  169. .one( "pagebeforeshow", function(){
  170. deepEqual( nextpageheader.parent()[0], $.mobile.pageContainer[0], "fixed header is now a child of page container" );
  171. });
  172. $.mobile.changePage( "#persist-test-d" );
  173. },
  174. function() {
  175. deepEqual( nextpageheader.parent()[0], $.mobile.activePage[0], "fixed header is now a child of page again" );
  176. $.mobile.changePage( "#default" );
  177. },
  178. start
  179. ]);
  180. });
  181. asyncTest( "The persistent footers should work without a header", function() {
  182. expect( 3 );
  183. $( "#persist-test-e, #persist-test-f" ).page();
  184. var nextpagefooter = $( "#persist-test-f .ui-footer-fixed" );
  185. $.testHelper.pageSequence([
  186. function(){
  187. ok( nextpagefooter.length, "next page has fixed footer and fixed footer" );
  188. $.mobile.changePage( "#persist-test-e" );
  189. },
  190. function(){
  191. $( "#persist-test-f" )
  192. .one( "pagebeforeshow", function(){
  193. deepEqual( nextpagefooter.parent()[0], $.mobile.pageContainer[0], "fixed footer is now a child of page container" );
  194. });
  195. $.mobile.changePage( "#persist-test-f" );
  196. },
  197. function() {
  198. deepEqual( nextpagefooter.parent()[0], $.mobile.activePage[0], "fixed footer is now a child of page again" );
  199. $.mobile.changePage( "#default" );
  200. },
  201. start
  202. ]);
  203. });
  204. var asyncTestFooterAndHeader = function( pageSelector, visible ) {
  205. $.testHelper.pageSequence([
  206. function() {
  207. $.mobile.changePage( pageSelector );
  208. },
  209. function() {
  210. var $footer = $.mobile.activePage.find( ".ui-footer" ),
  211. $header = $.mobile.activePage.find( ".ui-header" ),
  212. hiddenStr = visible ? "hidden" : "visible";
  213. equal( $footer.length, 1, "there should be one footer" );
  214. equal( $header.length, 1, "there should be one header" );
  215. equal( !$footer.hasClass( "ui-fixed-hidden" ), visible, "the footer should be " + hiddenStr );
  216. equal( !$header.hasClass( "ui-fixed-hidden" ), visible, "the header should be " + hiddenStr );
  217. $.mobile.changePage( "#default" );
  218. },
  219. start
  220. ]);
  221. };
  222. asyncTest( "data-visible-on-page-show hides toolbars when false", function() {
  223. asyncTestFooterAndHeader( "#page-show-visible-false", false );
  224. });
  225. asyncTest( "data-visible-on-page-show shows toolbars when explicitly true", function() {
  226. asyncTestFooterAndHeader( "#page-show-visible-true", true );
  227. });
  228. asyncTest( "data-visible-on-page-show shows toolbars when undefined", function() {
  229. asyncTestFooterAndHeader( "#page-show-visible-undefined", true );
  230. });
  231. })(jQuery);