Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
fixes for select tests and tests to cover basic functionality for new…
Browse files Browse the repository at this point in the history
… cached pages and select dialogs
  • Loading branch information
johnbender committed Aug 2, 2011
1 parent d958983 commit f7d5d91
Show file tree
Hide file tree
Showing 5 changed files with 500 additions and 68 deletions.
65 changes: 65 additions & 0 deletions tests/unit/select/cached-tests.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div id="dialog-select-parent-cache-test" data-nstest-role="page">
<div data-nstest-role="fieldcontain" id="cached-page-select-container">
<label for="cached-page-select" class="select">Your state:</label>
<select name="cached-page-select" id="cached-page-select" data-nstest-native-menu="false">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
</div>
</body>
</html>
3 changes: 1 addition & 2 deletions tests/unit/select/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<script src="select_events.js"></script>
<script src="select_core.js"></script>


<link rel="stylesheet" href="../../../themes/default/"/>
<link rel="stylesheet" href="../../../external/qunit.css"/>
</head>
Expand All @@ -25,7 +24,7 @@ <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>

<div id="foo" data-nstest-role="page">
<div id="default" data-nstest-role="page">
<div data-nstest-role="fieldcontain" id="select-choice-few-container">
<select name="select-choice-few" id="select-choice-few" data-nstest-native-menu="false">
<option value="standard">Standard: 7 day</option>
Expand Down
171 changes: 132 additions & 39 deletions tests/unit/select/select_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,117 @@
(function($){
var libName = "jquery.mobile.forms.select.js",
originalDefaultDialogTrans = $.mobile.defaultDialogTransition,
originalDefTransitionHandler = $.mobile.defaultTransitionHandler;
originalDefTransitionHandler = $.mobile.defaultTransitionHandler,
resetHash, closeDialog;

resetHash = function(timeout){
$.testHelper.openPage( location.hash.indexOf("#default") >= 0 ? "#" : "#default" );
};

closeDialog = function(timeout){
$.mobile.activePage.find("li a").first().click();
};

module(libName, {
teardown: function(){
location.hash = "";
$.mobile.defaultDialogTransition = originalDefaultDialogTrans;
$.mobile.defaultTransitionHandler = originalDefTransitionHandler;
}
});

asyncTest( "a large select menu should use the default dialog transition", function(){
var select = $("#select-choice-many-container-1 a");

//set to something else
asyncTest( "firing a click at least 400 ms later on the select screen overlay does close it", function(){
$.testHelper.sequence([
function(){
// bring up the smaller choice menu
ok($("#select-choice-few-container a").length > 0, "there is in fact a button in the page");
$("#select-choice-few-container a").trigger("click");
},

$.mobile.defaultTransitionHandler = $.testHelper.decorate({
fn: $.mobile.defaultTransitionHandler,
function(){
//select the first menu item
$("#select-choice-few-menu a:first").click();
},

before: function(name){
same(name, $.mobile.defaultDialogTransition);
function(){
same($("#select-choice-few-menu").parent(".ui-selectmenu-hidden").length, 1);
start();
}
});
], 1000);
});

asyncTest( "a large select menu should use the default dialog transition", function(){
var select;

setTimeout(function(){
$.testHelper.pageSequence([
function(){
resetHash,

function(timeout){
select = $("#select-choice-many-container-1 a");

//set to something else
$.mobile.defaultTransitionHandler = $.testHelper.decorate({
fn: $.mobile.defaultTransitionHandler,

before: function(name){
same(name, $.mobile.defaultDialogTransition);
}
});

// bring up the dialog
select.trigger("click");
},

function(){
$.mobile.activePage.find(".ui-header .ui-btn").click();
},
closeDialog,

function(){
start();
}
start
]);
}, 1000);
});

asyncTest( "a large select menu should come up in a dialog many times", function(){
var menu, select = $("#select-choice-many-container a");
var menu, select;

$.testHelper.pageSequence([
resetHash,

function(){
select = $("#select-choice-many-container a");

// bring up the dialog
select.trigger("click");
},


function(){
menu = $("#select-choice-many-menu");
same(menu.closest('.ui-dialog').length, 1);
},

function(){
// select and close the dialog
$.mobile.activePage.find(".ui-header .ui-btn").click();
closeDialog();
},

function(){
//bring up the dialog again
select.trigger("click");
},

function(){
$.mobile.activePage.find(".ui-header .ui-btn").click();
},
closeDialog,

function(){
start();
}
start
]);
});

asyncTest( "custom select menu always renders screen from the left", function(){
var select;

expect( 1 );
var select = $("ul#select-offscreen-menu");

$.testHelper.sequence([
resetHash,

function(){
select = $("ul#select-offscreen-menu");
$("#select-offscreen-container a").trigger("click");
},

function(){
ok(select.offset().left >= 30);
ok(select.offset().left >= 30, "offset from the left is greater than or equal to 30px" );
start();
}
], 1000);
Expand All @@ -101,13 +125,15 @@
var dialogHashKey = "ui-state=dialog";

$.testHelper.pageSequence([
function(){
resetHash,

function(timeout){
$("#select-choice-many-container-hash-check a").click();
},

function(){
ok(location.hash.indexOf(dialogHashKey) > -1);
$.mobile.activePage.find(".ui-header .ui-btn").click();
closeDialog();
},

function(){
Expand All @@ -121,13 +147,15 @@
var dialogHashKey = "ui-state=dialog",

openDialogSequence = [
resetHash,

function(){
$("#select-choice-many-container-many-clicks a").click();
},

function(){
ok(location.hash.indexOf(dialogHashKey) > -1, "hash should have the dialog hash key");
$(".ui-page-active li").click();
closeDialog();
}
],

Expand All @@ -147,10 +175,13 @@

asyncTest( "a large select option should not overflow", function(){
// https://github.com/jquery/jquery-mobile/issues/1338
var menu, select = $("#select-long-option-label");
var menu, select;

$.testHelper.sequence([
resetHash,

function(){
select = $("#select-long-option-label");
// bring up the dialog
select.trigger("click");
},
Expand All @@ -162,6 +193,68 @@
start();
}
], 500);
});

// https://github.com/jquery/jquery-mobile/issues/2181
asyncTest( "dialog sized select should alter the value of its parent select", function(){
var selectButton, value;

$.testHelper.pageSequence([
resetHash,

function(){
$.mobile.changePage( "cached-tests.html" );
},

function(){
selectButton = $( "#cached-page-select" ).siblings( 'a' );
selectButton.click();
},

function(){
ok( $.mobile.activePage.hasClass('ui-dialog'), "the dialog came up" );
var option = $.mobile.activePage.find( "li a" ).not(":contains('" + selectButton.text() + "')").last();
value = option.text();
option.click();
},

function(){
same( value, selectButton.text(), "the selected value is propogated back to the button text" );
start();
}
]);
});

// https://github.com/jquery/jquery-mobile/issues/2181
asyncTest( "dialog sized select should prevent the removal of its parent page from the dom", function(){
var selectButton, parentPageId;

expect( 2 );

$.testHelper.pageSequence([
resetHash,

function(){
$.mobile.changePage( "cached-tests.html" );
},

function(){
selectButton = $.mobile.activePage.find( "#cached-page-select" ).siblings( 'a' ),
parentPageId = $.mobile.activePage.attr( 'id' );
same( $("#" + parentPageId).length, 1, "establish the parent page exists" );
selectButton.click();
},

function(){
same( $( "#" + parentPageId).length, 1, "make sure parent page is still there after opening the dialog" );
$.mobile.activePage.find( "li a" ).last().click();
},

function(){
window.history.back();
},

start
]);
});
})(jQuery);
Loading

0 comments on commit f7d5d91

Please sign in to comment.