Skip to content

Commit 53a8023

Browse files
committed
fixed select tests to click the button instead of calling the select menu method
1 parent 2e2f318 commit 53a8023

File tree

3 files changed

+74
-44
lines changed

3 files changed

+74
-44
lines changed

tests/jquery.testHelper.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@
103103
// invoke the function which should, in some fashion,
104104
// trigger the defined event
105105
fn(timedOut);
106+
},
107+
108+
decorate: function(opts){
109+
var thisVal = opts.this || window;
110+
111+
return function(){
112+
var returnVal;
113+
opts.before && opts.before.apply(thisVal, arguments);
114+
returnVal = opts.fn.apply(thisVal, arguments);
115+
opts.after && opts.after.apply(thisVal, arguments);
116+
117+
return returnVal;
118+
};
106119
}
107120
};
108121
})(jQuery);

tests/unit/select/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<script src="../jquery.setNameSpace.js"></script>
1010
<script src="../../../external/qunit.js"></script>
1111
<script src="../../../tests/jquery.testHelper.js"></script>
12+
<script src="../../../js"></script>
1213
<script src="select_events.js"></script>
1314
<script src="select_core.js"></script>
14-
<script src="../../../js"></script>
1515

1616

1717
<link rel="stylesheet" href="../../../themes/default/"/>
@@ -27,7 +27,7 @@ <h2 id="qunit-userAgent"></h2>
2727

2828
<div id="foo" data-nstest-role="page">
2929
<div data-nstest-role="fieldcontain" id="select-choice-few-container">
30-
<select name="select-choice-few" id="select-choice-few">
30+
<select name="select-choice-few" id="select-choice-few" data-nstest-native-menu="false">
3131
<option value="standard">Standard: 7 day</option>
3232
<option value="rush">Rush: 3 days</option>
3333
<option value="express">Express: next day</option>
@@ -45,17 +45,17 @@ <h2 id="qunit-userAgent"></h2>
4545
</div>
4646

4747
<div data-nstest-role="fieldcontain" id="select-choice-global-native-container">
48-
<select name="select-choice-global-native" id="select-choice-global-native">
48+
<select name="select-choice-global-native" id="select-choice-global-native" data-nstest-native-menu="false">
4949
<option value="standard">Standard: 7 day</option>
5050
<option value="rush">Rush: 3 days</option>
5151
<option value="express">Express: next day</option>
5252
<option value="overnight">Overnight</option>
5353
</select>
5454
</div>
55-
55+
5656
<div data-nstest-role="fieldcontain" id="select-choice-many-container-1">
5757
<label for="select-choice-many-1" class="select">Your state:</label>
58-
<select name="select-choice-many-1" id="select-choice-many-1">
58+
<select name="select-choice-many-1" id="select-choice-many-1" data-nstest-native-menu="false">
5959
<option value="AL">Alabama</option>
6060
<option value="AK">Alaska</option>
6161
<option value="AZ">Arizona</option>
@@ -111,7 +111,7 @@ <h2 id="qunit-userAgent"></h2>
111111

112112
<div data-nstest-role="fieldcontain" id="select-choice-many-container">
113113
<label for="select-choice-many" class="select">Your state:</label>
114-
<select name="select-choice-many" id="select-choice-many">
114+
<select name="select-choice-many" id="select-choice-many" data-nstest-native-menu="false">
115115
<option value="AL">Alabama</option>
116116
<option value="AK">Alaska</option>
117117
<option value="AZ">Arizona</option>
@@ -167,7 +167,7 @@ <h2 id="qunit-userAgent"></h2>
167167

168168
<div data-nstest-role="fieldcontain" id="select-choice-many-container-hash-check">
169169
<label for="select-choice-many-hash-check" class="select">Your state:</label>
170-
<select name="select-choice-many-hash-check" id="select-choice-many-hash-check">
170+
<select name="select-choice-many-hash-check" id="select-choice-many-hash-check" data-nstest-native-menu="false">
171171
<option value="AL">Alabama</option>
172172
<option value="AK">Alaska</option>
173173
<option value="AZ">Arizona</option>
@@ -223,7 +223,7 @@ <h2 id="qunit-userAgent"></h2>
223223

224224
<div data-nstest-role="fieldcontain" id="select-choice-many-container-many-clicks">
225225
<label for="select-choice-many-many-clicks" class="select">Your state:</label>
226-
<select name="select-choice-many-many-clicks" id="select-choice-many-many-clicks">
226+
<select name="select-choice-many-many-clicks" id="select-choice-many-many-clicks" data-nstest-native-menu="false">
227227
<option value="AL">Alabama</option>
228228
<option value="AK">Alaska</option>
229229
<option value="AZ">Arizona</option>
@@ -288,7 +288,7 @@ <h2 id="qunit-userAgent"></h2>
288288
}
289289
</style>
290290

291-
<select name="select-choice-few" id="select-offscreen">
291+
<select name="select-choice-few" id="select-offscreen" data-nstest-native-menu="false">
292292
<option value="standard">Standard: 7 day</option>
293293
<option value="rush">Rush: 3 days</option>
294294
<option value="express">Express: next day</option>
@@ -297,7 +297,7 @@ <h2 id="qunit-userAgent"></h2>
297297
</div>
298298

299299
<div data-nstest-role="fieldcontain" id="select-long-option-label-container">
300-
<select name="select-long-option-label" id="select-long-option-label">
300+
<select name="select-long-option-label" id="select-long-option-label" data-nstest-native-menu="false">
301301
<option value="short">Choice 1</option>
302302
<option value="long">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</option>
303303
</select>

tests/unit/select/select_core.js

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,67 @@
33
*/
44

55
(function($){
6-
var libName = "jquery.mobile.forms.select.js";
7-
8-
$(document).bind("mobileinit", function(){
9-
$.mobile.selectmenu.prototype.options.nativeMenu = false;
10-
});
6+
var libName = "jquery.mobile.forms.select.js",
7+
originalDefaultDialogTrans = $.mobile.defaultDialogTransition,
8+
originalDefTransitionHandler = $.mobile.defaultTransitionHandler;
119

1210
module(libName, {
13-
teardown: function(){ location.hash = ""; }
11+
teardown: function(){
12+
location.hash = "";
13+
$.mobile.defaultDialogTransition = originalDefaultDialogTrans;
14+
$.mobile.defaultTransitionHandler = originalDefTransitionHandler;
15+
}
1416
});
15-
17+
1618
asyncTest( "a large select menu should use the default dialog transition", function(){
17-
var select = $("#select-choice-many-container-1 a"),
18-
prevDefault = $.mobile.defaultDialogTransition;
19-
20-
//set to something else
21-
$.mobile.defaultDialogTransition = "fooz";
22-
23-
$.testHelper.sequence([
19+
var select = $("#select-choice-many-container-1 a");
20+
21+
//set to something else
22+
23+
$.mobile.defaultTransitionHandler = $.testHelper.decorate({
24+
fn: $.mobile.defaultTransitionHandler,
25+
26+
before: function(name){
27+
same(name, $.mobile.defaultDialogTransition);
28+
}
29+
});
30+
31+
setTimeout(function(){
32+
$.testHelper.pageSequence([
2433
function(){
2534
// bring up the dialog
2635
select.trigger("click");
27-
ok( $("#select-choice-many-1-menu").closest(".ui-page").hasClass( $.mobile.defaultDialogTransition ) );
28-
$("#select-choice-many-1").selectmenu("close");
2936
},
30-
37+
38+
function(){
39+
$.mobile.activePage.find(".ui-header .ui-btn").click();
40+
},
41+
3142
function(){
3243
start();
3344
}
34-
], 500);
45+
]);
46+
}, 1000);
3547
});
3648

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

40-
$.testHelper.sequence([
52+
$.testHelper.pageSequence([
4153
function(){
4254
// bring up the dialog
4355
select.trigger("click");
4456
},
4557

58+
4659
function(){
4760
menu = $("#select-choice-many-menu");
4861
same(menu.closest('.ui-dialog').length, 1);
4962
},
5063

5164
function(){
5265
// select and close the dialog
53-
$("#select-choice-many-menu").selectmenu("close");
66+
$.mobile.activePage.find(".ui-header .ui-btn").click();
5467
},
5568

5669
function(){
@@ -59,38 +72,42 @@
5972
},
6073

6174
function(){
62-
same(menu.closest('.ui-dialog').length, 1);
63-
$("#select-choice-many-menu").selectmenu("close");
75+
$.mobile.activePage.find(".ui-header .ui-btn").click();
6476
},
77+
6578
function(){
6679
start();
6780
}
68-
], 500);
81+
]);
6982
});
7083

7184
asyncTest( "custom select menu always renders screen from the left", function(){
7285
expect( 1 );
7386
var select = $("ul#select-offscreen-menu");
7487

75-
$("#select-offscreen-container a").trigger("click");
88+
$.testHelper.sequence([
89+
function(){
90+
$("#select-offscreen-container a").trigger("click");
91+
},
7692

77-
setTimeout(function(){
78-
ok(select.offset().left >= 30);
79-
start();
80-
}, 1000);
93+
function(){
94+
ok(select.offset().left >= 30);
95+
start();
96+
}
97+
], 1000);
8198
});
8299

83100
asyncTest( "selecting an item from a dialog sized custom select menu leaves no dialog hash key", function(){
84101
var dialogHashKey = "ui-state=dialog";
85102

86103
$.testHelper.pageSequence([
87104
function(){
88-
$("#select-choice-many-container-hash-check a").trigger("click");
105+
$("#select-choice-many-container-hash-check a").click();
89106
},
90107

91108
function(){
92109
ok(location.hash.indexOf(dialogHashKey) > -1);
93-
$(".ui-page-active li:first a").trigger("click");
110+
$.mobile.activePage.find(".ui-header .ui-btn").click();
94111
},
95112

96113
function(){
@@ -100,17 +117,17 @@
100117
]);
101118
});
102119

103-
asyncTest( "dialog sized select menu opened many times remains a dialog", function(){
120+
asyncTest( "dialog sized select menu opened many times remains a dialog", function(){
104121
var dialogHashKey = "ui-state=dialog",
105122

106123
openDialogSequence = [
107124
function(){
108-
$("#select-choice-many-container-many-clicks a").trigger("vclick");
125+
$("#select-choice-many-container-many-clicks a").click();
109126
},
110127

111128
function(){
112129
ok(location.hash.indexOf(dialogHashKey) > -1, "hash should have the dialog hash key");
113-
$(".ui-page-active li").trigger("click");
130+
$(".ui-page-active li").click();
114131
}
115132
],
116133

@@ -141,7 +158,7 @@
141158
function() {
142159
menu = $(".ui-selectmenu-list");
143160

144-
equal(menu.width(), menu.find("li:nth-child(2) .ui-btn-text").width(), "ui-btn-text element should not overflow")
161+
equal(menu.width(), menu.find("li:nth-child(2) .ui-btn-text").width(), "ui-btn-text element should not overflow");
145162
start();
146163
}
147164
], 500);

0 commit comments

Comments
 (0)