forked from jquery-archive/jquery-mobile
/
select_core.js
127 lines (99 loc) · 2.93 KB
/
select_core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* mobile select unit tests
*/
(function($){
var libName = "jquery.mobile.forms.select.js";
$(document).bind("mobileinit", function(){
$.mobile.selectmenu.prototype.options.nativeMenu = false;
});
module(libName, {
teardown: function(){ location.hash = ""; }
});
asyncTest( "a large select menu should come up in a dialog many times", function(){
var menu, select = $("#select-choice-many-container a");
$.testHelper.sequence([
function(){
// bring up the dialog
select.trigger("click");
},
function(){
menu = $("#select-choice-many-menu");
same(menu.parents('.ui-dialog').length, 1);
},
function(){
// select and close the dialog
menu.parents('ui-dialog').find("span.ui-icon-delete").click();
},
function(){
//bring up the dialog again
select.trigger("click");
},
function(){
same(menu.parents('.ui-dialog').length, 1);
start();
}
], 500);
});
asyncTest( "custom select menu always renders screen from the left", function(){
expect( 1 );
var select = $("ul#select-offscreen-menu");
$("#select-offscreen-container a").trigger("click");
setTimeout(function(){
ok(select.offset().left >= 30);
start();
}, 1000);
});
asyncTest( "selecting an item from a dialog sized custom select menu leaves no dialog hash key", function(){
var dialogHashKey = "ui-state=dialog";
$.testHelper.sequence([
function(){
$("#select-choice-many-container-hash-check a").trigger("click");
},
function(){
ok(location.hash.indexOf(dialogHashKey) > -1);
$(".ui-page-active li").trigger("click");
},
function(){
ok(location.hash.indexOf(dialogHashKey) == -1);
start();
}
], 500);
});
asyncTest( "dialog sized select menu opened many times remains a dialog", function(){
var dialogHashKey = "ui-state=dialog",
openDialogSequence = [
function(){
$("#select-choice-many-container-many-clicks a").trigger("vclick");
},
function(){
ok(location.hash.indexOf(dialogHashKey) > -1, "hash should have the dialog hash key");
$(".ui-page-active li").trigger("click");
}
],
sequence = openDialogSequence.concat(openDialogSequence).concat([start]);
$.testHelper.sequence(sequence, 1000);
});
module("Non native menus", {
setup: function() {
$.mobile.selectmenu.prototype.options.nativeMenu = false;
},
teardown: function() {
$.mobile.selectmenu.prototype.options.nativeMenu = true;
}
});
asyncTest( "a large select option should not overflow", function(){
// https://github.com/jquery/jquery-mobile/issues/1338
var menu, select = $("#select-long-option-label");
$.testHelper.sequence([
function(){
// bring up the dialog
select.trigger("click");
},
function() {
menu = $(".ui-selectmenu-list");
equal(menu.width(), menu.find("li:nth-child(2) .ui-btn-text").width(), "ui-btn-text element should not overflow")
start();
}
], 500);
});
})(jQuery);