|
| 1 | +/* |
| 2 | + * mobile dialog unit tests |
| 3 | + */ |
| 4 | +(function($) { |
| 5 | + var home = $.mobile.path.parseUrl(location.pathname).directory, |
| 6 | + homeWithSearch = home + location.search; |
| 7 | + |
| 8 | + module( "jquery.mobile.dialog.js", { |
| 9 | + setup: function() { |
| 10 | + $.mobile.page.prototype.options.contentTheme = "d"; |
| 11 | + $.testHelper.navReset( homeWithSearch ); |
| 12 | + } |
| 13 | + }); |
| 14 | + |
| 15 | + asyncTest( "Test option data-close-btn", function() { |
| 16 | + expect( 7 ); |
| 17 | + |
| 18 | + $.testHelper.pageSequence([ |
| 19 | + function() { |
| 20 | + // bring up the dialog |
| 21 | + $( "#close-btn-test-link" ).click(); |
| 22 | + }, |
| 23 | + |
| 24 | + function() { |
| 25 | + var a = $( "#close-btn-test .ui-header a" ); |
| 26 | + deepEqual( a.length, 0, "Initially, the dialog header has no anchor elements (option value 'none')" ); |
| 27 | + |
| 28 | + $( "#close-btn-test" ).page( "option", "closeBtn", "left" ); |
| 29 | + a = $( "#close-btn-test .ui-header a" ); |
| 30 | + deepEqual( a.length, 1, "The dialog header has eactly one anchor element when the option value is set to 'left'" ); |
| 31 | + ok( a.hasClass( "ui-btn-left" ), "The close button has class ui-btn-left when the closeBtn option is set to 'left'" ); |
| 32 | + deepEqual( a.attr( "role" ), "button", "The close button has the attribute " + '"' + "role='button'" + '"' + "set" ); |
| 33 | + |
| 34 | + $( "#close-btn-test" ).page( "option", "closeBtn", "right" ); |
| 35 | + a = $( "#close-btn-test .ui-header a" ); |
| 36 | + deepEqual( a.length, 1, "The dialog header has eactly one anchor element when the option value is set to 'right'" ); |
| 37 | + ok( a.hasClass( "ui-btn-right" ), "The close button has class ui-btn-right when the closeBtn option is set to 'right'" ); |
| 38 | + deepEqual( a.attr( "role" ), "button", "The close button has the attribute " + '"' + "role='button'" + '"' + "set" ); |
| 39 | + |
| 40 | + |
| 41 | + }, |
| 42 | + |
| 43 | + function() { |
| 44 | + start(); |
| 45 | + } |
| 46 | + ]); |
| 47 | + }); |
| 48 | + |
| 49 | + asyncTest( "clicking dialog 'Close' button twice in quick succession does not cause the browser history to retreat by two", function() { |
| 50 | + var correctLocation; |
| 51 | + |
| 52 | + expect(1); |
| 53 | + |
| 54 | + $.testHelper.pageSequence([ |
| 55 | + function() { |
| 56 | + $.mobile.changePage( $( "#mypage" ) ); |
| 57 | + }, |
| 58 | + |
| 59 | + function() { |
| 60 | + |
| 61 | + $.mobile.changePage( $( "#doubleCloseTestPage" ) ); |
| 62 | + }, |
| 63 | + |
| 64 | + function() { |
| 65 | + |
| 66 | + $( "#doubleCloseTestPage a" ).click(); |
| 67 | + }, |
| 68 | + |
| 69 | + function( timedOut ) { |
| 70 | + ok( !timedOut, "Clicking dialog 'Close' has resulted in a pagechange event" ); |
| 71 | + start(); |
| 72 | + } |
| 73 | + ]); |
| 74 | + }); |
| 75 | + |
| 76 | + asyncTest( "dialog element with no theming", function() { |
| 77 | + expect(5); |
| 78 | + |
| 79 | + $.testHelper.pageSequence([ |
| 80 | + function() { |
| 81 | + $.mobile.changePage( $( "#mypage" ) ); |
| 82 | + }, |
| 83 | + |
| 84 | + function() { |
| 85 | + //bring up the dialog |
| 86 | + $( "#link-a" ).click(); |
| 87 | + }, |
| 88 | + |
| 89 | + function() { |
| 90 | + var dialog = $( "#dialog-a" ); |
| 91 | + |
| 92 | + // Assert dialog theme inheritance (issue 1375): |
| 93 | + ok( dialog.hasClass( "ui-page-theme-a" ), "Expected explicit theme ui-page-theme-a" ); |
| 94 | + ok( $.mobile.pageContainer.hasClass( "ui-overlay-a" ), "Expected default overlay theme ui-overlay-a" ); |
| 95 | + ok( dialog.find( ":jqmData(role=header)" ).hasClass( "ui-bar-inherit" ), "Expected header to inherit from dialog" ); |
| 96 | + ok( dialog.find( ":jqmData(role=content)" ).hasClass( "ui-body-" + $.mobile.page.prototype.options.contentTheme ), "Expect content to inherit from $.mobile.page.prototype.options.contentTheme" ); |
| 97 | + ok( dialog.find( ":jqmData(role=footer)" ).hasClass( "ui-bar-inherit" ), "Expected footer to inherit from dialog" ); |
| 98 | + |
| 99 | + start(); |
| 100 | + } |
| 101 | + ]); |
| 102 | + }); |
| 103 | + |
| 104 | + asyncTest( "dialog element with data-theme", function() { |
| 105 | + // Reset fallback theme for content |
| 106 | + $.mobile.page.prototype.options.contentTheme = null; |
| 107 | + |
| 108 | + expect(6); |
| 109 | + |
| 110 | + $.testHelper.pageSequence([ |
| 111 | + function() { |
| 112 | + $.mobile.changePage( $( "#mypage" ) ); |
| 113 | + }, |
| 114 | + |
| 115 | + function() { |
| 116 | + //bring up the dialog |
| 117 | + $( "#link-b" ).click(); |
| 118 | + }, |
| 119 | + |
| 120 | + function() { |
| 121 | + var dialog = $( "#dialog-b" ); |
| 122 | + |
| 123 | + // Assert dialog theme inheritance (issue 1375): |
| 124 | + ok( dialog.hasClass( "ui-page-theme-e" ), "Expected explicit theme ui-page-theme-e" ); |
| 125 | + ok( !$.mobile.pageContainer.hasClass( "ui-overlay-b" ), "Expected no overlay theme ui-overlay-b" ); |
| 126 | + ok( $.mobile.pageContainer.hasClass( "ui-overlay-a" ), "Expected default overlay theme ui-overlay-a" ); |
| 127 | + ok( dialog.find( ":jqmData(role=header)" ).hasClass( "ui-bar-inherit" ), "Expected header to inherit from dialog" ); |
| 128 | + ok( dialog.find( ":jqmData(role=content)" ).hasClass( "ui-body-e" ), "Expect content to inherit from data-theme" ); |
| 129 | + ok( dialog.find( ":jqmData(role=footer)" ).hasClass( "ui-bar-inherit" ), "Expected footer to inherit from dialog" ); |
| 130 | + |
| 131 | + start(); |
| 132 | + } |
| 133 | + ]); |
| 134 | + }); |
| 135 | + |
| 136 | + asyncTest( "dialog element with data-theme & data-overlay-theme", function() { |
| 137 | + expect(5); |
| 138 | + |
| 139 | + $.testHelper.pageSequence([ |
| 140 | + function() { |
| 141 | + $.mobile.changePage( $( "#mypage" ) ); |
| 142 | + }, |
| 143 | + |
| 144 | + function() { |
| 145 | + //bring up the dialog |
| 146 | + $( "#link-c" ).click(); |
| 147 | + }, |
| 148 | + |
| 149 | + function() { |
| 150 | + var dialog = $( "#dialog-c" ); |
| 151 | + // Assert dialog theme inheritance (issue 1375): |
| 152 | + ok( dialog.hasClass( "ui-page-theme-e" ), "Expected explicit theme ui-page-theme-e" ); |
| 153 | + ok( $.mobile.pageContainer.hasClass( "ui-overlay-b" ), "Expected explicit overlay theme ui-overlay-b" ); |
| 154 | + ok( dialog.find( ":jqmData(role=header)" ).hasClass( "ui-bar-inherit" ), "Expected header to inherit from dialog" ); |
| 155 | + ok( dialog.find( ":jqmData(role=content)" ).hasClass( "ui-body-" + $.mobile.page.prototype.options.contentTheme ), "Expect content to inherit from $.mobile.page.prototype.options.contentTheme" ); |
| 156 | + ok( dialog.find( ":jqmData(role=footer)" ).hasClass( "ui-bar-inherit" ), "Expected footer to inherit from dialog" ); |
| 157 | + |
| 158 | + start(); |
| 159 | + } |
| 160 | + ]); |
| 161 | + }); |
| 162 | + |
| 163 | + asyncTest( "page container is updated to dialog overlayTheme at pagebeforeshow", function(){ |
| 164 | + var pageTheme; |
| 165 | + |
| 166 | + expect( 1 ); |
| 167 | + |
| 168 | + $.testHelper.pageSequence([ |
| 169 | + function() { |
| 170 | + $.mobile.changePage( "#mypage" ); |
| 171 | + }, |
| 172 | + |
| 173 | + function() { |
| 174 | + //bring up the dialog |
| 175 | + $( "#foo-dialog-link" ).click(); |
| 176 | + }, |
| 177 | + |
| 178 | + function() { |
| 179 | + pageTheme = "ui-overlay-" + $.mobile.activePage.page( "option", "overlayTheme" ); |
| 180 | + |
| 181 | + $.mobile.pageContainer.removeClass( pageTheme ); |
| 182 | + |
| 183 | + $.mobile.activePage |
| 184 | + .bind( "pagebeforeshow", function(){ |
| 185 | + ok( $.mobile.pageContainer.hasClass( pageTheme ), "Page container has the same theme as the dialog overlayTheme on pagebeforeshow" ); |
| 186 | + start(); |
| 187 | + }).trigger( "pagebeforeshow" ); |
| 188 | + } |
| 189 | + ]); |
| 190 | + }); |
| 191 | +})( jQuery ); |
0 commit comments