2 * mobile dialog unit tests
5 var home = $.mobile.path.parseUrl(location.pathname).directory,
6 homeWithSearch = home + location.search;
8 module( "jquery.mobile.dialog.js", {
10 $.mobile.page.prototype.options.contentTheme = "d";
11 $.testHelper.navReset( homeWithSearch );
15 asyncTest( "dialog hash is added when the dialog is opened and removed when closed", function() {
18 $.testHelper.pageSequence([
21 $( "#foo-dialog-link" ).click();
25 var fooDialog = $( "#foo-dialog" );
27 // make sure the dialog came up
28 ok( /&ui-state=dialog/.test(location.hash), "ui-state=dialog =~ location.hash", "dialog open" );
31 $( ".ui-dialog" ).dialog( "close" );
35 ok( !(/&ui-state=dialog/.test(location.hash)), "ui-state=dialog !~ location.hash" );
41 asyncTest( "clicking dialog 'Close' button twice in quick succession does not cause the browser history to retreat by two", function() {
46 $.testHelper.pageSequence([
48 $.mobile.changePage( $( "#mypage" ) );
52 $.mobile.changePage( $( "#doubleCloseTestPage" ) );
56 correctLocation = location.href;
57 $( "#doubleCloseTestPage a" ).click();
61 $( "#foo-dialog a" ).click();
62 setTimeout( function() { $( "#foo-dialog a" ).click(); }, 0 );
65 function( timedOut ) {
66 ok( !timedOut, "Clicking dialog 'Close' has resulted in a pagechange event" );
69 function( timedOut ) {
70 ok( timedOut, "Clicking dialog 'Close' has not resulted in two pagechange events" );
71 ok( location.href === correctLocation, "Location is correct afterwards" );
77 asyncTest( "dialog element with no theming", function() {
80 $.testHelper.pageSequence([
82 $.mobile.changePage( $( "#mypage" ) );
87 $( "#link-a" ).click();
91 var dialog = $( "#dialog-a" );
93 // Assert dialog theme inheritance (issue 1375):
94 ok( dialog.hasClass( "ui-body-c" ), "Expected explicit theme ui-body-c" );
95 ok( dialog.find( ":jqmData(role=header)" ).hasClass( "ui-bar-" + $.mobile.page.prototype.options.footerTheme ), "Expected header to inherit from $.mobile.page.prototype.options.headerTheme" );
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-" + $.mobile.page.prototype.options.footerTheme ), "Expected footer to inherit from $.mobile.page.prototype.options.footerTheme" );
104 asyncTest( "dialog element with data-theme", function() {
105 // Reset fallback theme for content
106 $.mobile.page.prototype.options.contentTheme = null;
110 $.testHelper.pageSequence([
112 $.mobile.changePage( $( "#mypage" ) );
116 //bring up the dialog
117 $( "#link-b" ).click();
121 var dialog = $( "#dialog-b" );
123 // Assert dialog theme inheritance (issue 1375):
124 ok( dialog.hasClass( "ui-body-e" ), "Expected explicit theme ui-body-e" );
125 ok( !dialog.hasClass( "ui-overlay-b" ), "Expected no theme ui-overlay-b" );
126 ok( dialog.find( ":jqmData(role=header)" ).hasClass( "ui-bar-" + $.mobile.page.prototype.options.footerTheme ), "Expected header to inherit from $.mobile.page.prototype.options.headerTheme" );
127 ok( dialog.find( ":jqmData(role=content)" ).hasClass( "ui-body-e" ), "Expect content to inherit from data-theme" );
128 ok( dialog.find( ":jqmData(role=footer)" ).hasClass( "ui-bar-" + $.mobile.page.prototype.options.footerTheme ), "Expected footer to inherit from $.mobile.page.prototype.options.footerTheme" );
135 asyncTest( "dialog element with data-theme & data-overlay-theme", function() {
138 $.testHelper.pageSequence([
140 $.mobile.changePage( $( "#mypage" ) );
144 //bring up the dialog
145 $( "#link-c" ).click();
149 var dialog = $( "#dialog-c" );
151 // Assert dialog theme inheritance (issue 1375):
152 ok( dialog.hasClass( "ui-body-e" ), "Expected explicit theme ui-body-e" );
153 ok( dialog.hasClass( "ui-overlay-b" ), "Expected explicit theme ui-overlay-b" );
154 ok( dialog.find( ":jqmData(role=header)" ).hasClass( "ui-bar-" + $.mobile.page.prototype.options.footerTheme ), "Expected header to inherit from $.mobile.page.prototype.options.headerTheme" );
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-" + $.mobile.page.prototype.options.footerTheme ), "Expected footer to inherit from $.mobile.page.prototype.options.footerTheme" );
164 asyncTest( "page container is updated to dialog overlayTheme at pagebeforeshow", function(){
169 $.testHelper.pageSequence([
171 $.mobile.changePage( "#mypage" );
175 //bring up the dialog
176 $( "#foo-dialog-link" ).click();
180 pageTheme = "ui-overlay-" + $.mobile.activePage.dialog( "option", "overlayTheme" );
182 $.mobile.pageContainer.removeClass( pageTheme );
185 .bind( "pagebeforeshow", function(){
186 ok( $.mobile.pageContainer.hasClass( pageTheme ), "Page container has the same theme as the dialog overlayTheme on pagebeforeshow" );
188 }).trigger( "pagebeforeshow" );