|
5 | 5 |
|
6 | 6 | (function($) {
|
7 | 7 |
|
8 |
| -module("button: core"); |
| 8 | +module( "Button: core" ); |
9 | 9 |
|
10 |
| -test("checkbox", function() { |
11 |
| - expect( 4 ); |
12 |
| - var input = $("#check"), |
13 |
| - label = $("label[for=check]"); |
14 |
| - ok( input.is(":visible") ); |
15 |
| - ok( label.is(":not(.ui-button)") ); |
16 |
| - input.button(); |
17 |
| - ok( input.is(".ui-helper-hidden-accessible") ); |
18 |
| - ok( label.is(".ui-button") ); |
19 |
| -}); |
20 |
| - |
21 |
| -test("radios", function() { |
22 |
| - expect( 4 ); |
23 |
| - var inputs = $("#radio0 input"), |
24 |
| - labels = $("#radio0 label"); |
25 |
| - ok( inputs.is(":visible") ); |
26 |
| - ok( labels.is(":not(.ui-button)") ); |
27 |
| - inputs.button(); |
28 |
| - ok( inputs.is(".ui-helper-hidden-accessible") ); |
29 |
| - ok( labels.is(".ui-button") ); |
30 |
| -}); |
31 |
| - |
32 |
| -function assert(noForm, form1, form2) { |
33 |
| - ok( $("#radio0 .ui-button" + noForm).is(".ui-state-active") ); |
34 |
| - ok( $("#radio1 .ui-button" + form1).is(".ui-state-active") ); |
35 |
| - ok( $("#radio2 .ui-button" + form2).is(".ui-state-active") ); |
36 |
| -} |
37 |
| - |
38 |
| -test("radio groups", function() { |
39 |
| - expect( 12 ); |
40 |
| - $("input[type=radio]").button(); |
41 |
| - assert(":eq(0)", ":eq(1)", ":eq(2)"); |
42 |
| - |
43 |
| - // click outside of forms |
44 |
| - $("#radio0 .ui-button:eq(1)").click(); |
45 |
| - assert(":eq(1)", ":eq(1)", ":eq(2)"); |
46 |
| - |
47 |
| - // click in first form |
48 |
| - $("#radio1 .ui-button:eq(0)").click(); |
49 |
| - assert(":eq(1)", ":eq(0)", ":eq(2)"); |
50 |
| - |
51 |
| - // click in second form |
52 |
| - $("#radio2 .ui-button:eq(0)").click(); |
53 |
| - assert(":eq(1)", ":eq(0)", ":eq(0)"); |
54 |
| -}); |
55 |
| - |
56 |
| -test( "radio groups - ignore elements with same name", function() { |
57 |
| - expect( 1 ); |
58 |
| - var form = $( "form:first" ), |
59 |
| - radios = form.find( "[type=radio]" ).button(), |
60 |
| - checkbox = $( "<input>", { |
61 |
| - type: "checkbox", |
62 |
| - name: radios.attr( "name" ) |
63 |
| - }); |
64 |
| - |
65 |
| - form.append( checkbox ); |
66 |
| - radios.button( "refresh" ); |
67 |
| - ok( true, "no exception from accessing button instance of checkbox" ); |
68 |
| -}); |
69 |
| - |
70 |
| -test("input type submit, don't create child elements", function() { |
| 10 | +test( "Input type submit, don't create child elements", function() { |
71 | 11 | expect( 2 );
|
72 | 12 | var input = $("#submit");
|
73 | 13 | deepEqual( input.children().length, 0 );
|
74 | 14 | input.button();
|
75 | 15 | deepEqual( input.children().length, 0 );
|
76 | 16 | });
|
77 | 17 |
|
78 |
| -test("buttonset", function() { |
79 |
| - expect( 6 ); |
80 |
| - var set = $("#radio1").buttonset(); |
81 |
| - ok( set.is(".ui-buttonset") ); |
82 |
| - deepEqual( set.children(".ui-button").length, 3 ); |
83 |
| - deepEqual( set.children("input[type=radio].ui-helper-hidden-accessible").length, 3 ); |
84 |
| - ok( set.children("label:eq(0)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") ); |
85 |
| - ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") ); |
86 |
| - ok( set.children("label:eq(2)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") ); |
87 |
| -}); |
88 |
| - |
89 |
| -test("buttonset (rtl)", function() { |
90 |
| - expect( 6 ); |
91 |
| - var set, |
92 |
| - parent = $("#radio1").parent(); |
93 |
| - // Set to rtl |
94 |
| - parent.attr("dir", "rtl"); |
95 |
| - |
96 |
| - set = $("#radio1").buttonset(); |
97 |
| - ok( set.is(".ui-buttonset") ); |
98 |
| - deepEqual( set.children(".ui-button").length, 3 ); |
99 |
| - deepEqual( set.children("input[type=radio].ui-helper-hidden-accessible").length, 3 ); |
100 |
| - ok( set.children("label:eq(0)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") ); |
101 |
| - ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") ); |
102 |
| - ok( set.children("label:eq(2)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") ); |
103 |
| -}); |
104 |
| - |
105 |
| -// TODO: simulated click events don't behave like real click events in IE |
106 |
| -// remove this when simulate properly simulates this |
107 |
| -// see http://yuilibrary.com/projects/yui2/ticket/2528826 fore more info |
108 |
| -if ( !$.ui.ie || ( document.documentMode && document.documentMode > 8 ) ) { |
109 |
| - asyncTest( "ensure checked and aria after single click on checkbox label button, see #5518", function() { |
110 |
| - expect( 3 ); |
111 |
| - |
112 |
| - $("#check2").button().change( function() { |
113 |
| - var lbl = $( this ).button("widget"); |
114 |
| - ok( this.checked, "checked ok" ); |
115 |
| - ok( lbl.attr("aria-pressed") === "true", "aria ok" ); |
116 |
| - ok( lbl.hasClass("ui-state-active"), "ui-state-active ok" ); |
117 |
| - }); |
118 |
| - |
119 |
| - // support: Opera |
120 |
| - // Opera doesn't trigger a change event when this is done synchronously. |
<
10000
code>121 |
| - // This seems to be a side effect of another test, but until that can be |
122 |
| - // tracked down, this delay will have to do. |
123 |
| - setTimeout(function() { |
124 |
| - $("#check2").button("widget").simulate("click"); |
125 |
| - start(); |
126 |
| - }, 1 ); |
127 |
| - }); |
128 |
| -} |
129 |
| - |
130 |
| -test( "#7092 - button creation that requires a matching label does not find label in all cases", function() { |
131 |
| - expect( 5 ); |
132 |
| - var group = $( "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>" ); |
133 |
| - group.find( "input[type=checkbox]" ).button(); |
134 |
| - ok( group.find( "label" ).is( ".ui-button" ) ); |
135 |
| - |
136 |
| - group = $( "<input type='checkbox' id='t7092b'><label for='t7092b'></label>" ); |
137 |
| - group.filter( "input[type=checkbox]" ).button(); |
138 |
| - ok( group.filter( "label" ).is( ".ui-button" ) ); |
139 |
| - |
140 |
| - group = $( "<span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label>" ); |
141 |
| - group.find( "input[type=checkbox]" ).button(); |
142 |
| - ok( group.filter( "label" ).is( ".ui-button" ) ); |
143 |
| - |
144 |
| - group = $( "<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>" ); |
145 |
| - group.find( "input[type=checkbox]" ).button(); |
146 |
| - ok( group.find( "label" ).is( ".ui-button" ) ); |
147 |
| - |
148 |
| - group = $( "<input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span>" ); |
149 |
| - group.filter( "input[type=checkbox]" ).button(); |
150 |
| - ok( group.find( "label" ).is( ".ui-button" ) ); |
151 |
| -}); |
152 |
| - |
153 |
| -test( "#5946 - buttonset should ignore buttons that are not :visible", function() { |
154 |
| - expect( 2 ); |
155 |
| - $( "#radio01" ).next().addBack().hide(); |
156 |
| - var set = $( "#radio0" ).buttonset({ items: "input[type=radio]:visible" }); |
157 |
| - ok( set.find( "label:eq(0)" ).is( ":not(.ui-button):not(.ui-corner-left)" ) ); |
158 |
| - ok( set.find( "label:eq(1)" ).is( ".ui-button.ui-corner-left" ) ); |
159 |
| -}); |
160 |
| - |
161 |
| -test( "#6262 - buttonset not applying ui-corner to invisible elements", function() { |
162 |
| - expect( 3 ); |
163 |
| - $( "#radio0" ).hide(); |
164 |
| - var set = $( "#radio0" ).buttonset(); |
165 |
| - ok( set.find( "label:eq(0)" ).is( ".ui-button.ui-corner-left" ) ); |
166 |
| - ok( set.find( "label:eq(1)" ).is( ".ui-button" ) ); |
167 |
| - ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) ); |
168 |
| -}); |
169 |
| - |
170 |
| -asyncTest( "Resetting a button's form should refresh the visual state of the button widget to match.", function() { |
171 |
| - expect( 2 ); |
172 |
| - var form = $( "<form>" + |
173 |
| - "<button></button>" + |
174 |
| - "<label for='c1'></label><input id='c1' type='checkbox' checked>" + |
175 |
| - "</form>" ), |
176 |
| - button = form.find( "button" ).button(), |
177 |
| - checkbox = form.find( "input[type=checkbox]" ).button(); |
178 |
| - |
179 |
| - checkbox.prop( "checked", false ).button( "refresh" ); |
180 |
| - ok( !checkbox.button( "widget" ).hasClass( "ui-state-active" ) ); |
181 |
| - |
182 |
| - form.get( 0 ).reset(); |
183 |
| - |
184 |
| - // #9213: If a button has been removed, refresh should not be called on it when |
185 |
| - // its corresponding form is reset. |
186 |
| - button.remove(); |
187 |
| - |
188 |
| - setTimeout(function() { |
189 |
| - ok( checkbox.button( "widget" ).hasClass( "ui-state-active" )); |
190 |
| - start(); |
191 |
| - }, 1 ); |
192 |
| -}); |
193 |
| - |
194 |
| -asyncTest( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function() { |
195 |
| - expect( 2 ); |
196 |
| - var check = $( "#check" ).button(), |
197 |
| - label = $( "label[for='check']" ); |
198 |
| - ok( !label.is( ".ui-state-focus" ) ); |
199 |
| - check.focus(); |
200 |
| - setTimeout(function() { |
201 |
| - ok( label.is( ".ui-state-focus" ) ); |
202 |
| - start(); |
203 |
| - }); |
204 |
| -}); |
205 |
| - |
206 |
| -test( "#7534 - Button label selector works for ids with \":\"", function() { |
207 |
| - expect( 1 ); |
208 |
| - var group = $( "<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>" ); |
209 |
| - group.find( "input" ).button(); |
210 |
| - ok( group.find( "label" ).is( ".ui-button" ), "Found an id with a :" ); |
211 |
| -}); |
212 |
| - |
213 |
| -asyncTest( "#9169 - Disabled button maintains ui-state-focus", function() { |
| 18 | +asyncTest( "Disabled button maintains ui-state-focus", function() { |
214 | 19 | expect( 2 );
|
215 | 20 | var element = $( "#button1" ).button();
|
216 |
| - element[ 0 ].focus(); |
| 21 | + element.simulate( "focus" ); |
217 | 22 | setTimeout(function() {
|
218 |
| - ok( element.hasClass( "ui-state-focus" ), "button has ui-state-focus" ); |
| 23 | + ok( element.is( ":focus" ), "Button is focused" ); |
219 | 24 | element.button( "disable" );
|
220 |
| - ok( !element.hasClass( "ui-state-focus" ), |
221 |
| - "button does not have ui-state-focus when disabled" ); |
| 25 | + ok( !element.is( ":focus" ), |
| 26 | + "Button has had focus removed" ); |
222 | 27 | start();
|
223 | 28 | });
|
224 | 29 | });
|
|
0 commit comments