Debian Codegraph @

dijit/tests/form/CheckBox.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <title>Checkbox unit Test</title>
6
7 <script type="text/javascript" src="../boilerplate.js"></script>
8
9 <script type="text/javascript">
10 function defaultSubmitHandler(values){
11 console.debug('actual submitted values: ' + json.stringify(values));
12 }
13 submittedValues = defaultSubmitHandler;
14
15 require([
16 "doh/runner",
17 "dojo/dom", "dojo/json", "dojo/parser", "dojo/query",
18 "dijit/registry", "dijit/form/CheckBox", "dijit/form/Form", "dojo/domReady!"
19 ], function(doh, dom, json, parser, query, registry, CheckBox){
20
21 // These are the values assigned to the widgets in the page's HTML
22 var originalGet = {
23 cb1: [],
24 cb2: ["on"],
25 cb4: ["on"],
26 cb5: [],
27 cb6: ["on"],
28 cb7: []
29 };
30
31 var originalSubmit = {
32 cb2: "on",
33 cb4: "on",
34 cb6: "on"
35 };
36
37 // attempt to change these values
38 var change = {
39 cb1: ["foo"],
40 cb2: [],
41 cb3: ["on"],
42 cb4: [],
43 cb5: ["on"],
44 cb6: ["foo"]
45 };
46
47 // changed values
48 var changedGet = {
49 cb1: ["foo"],
50 cb2: [],
51 cb4: [],
52 cb5: ["on"],
53 cb6: [],
54 cb7: []
55 };
56
57 var changedSubmit = {
58 cb1: "foo",
59 cb5: "on"
60 };
61
62 doh.register("setup", [
63 function parse(){
64 parser.parse();
65 },
66 function programmatic(){
67 new CheckBox({id: "cb6", name: "cb6", checked: true }, "cb6");
68 }
69 ]);
70
71 // should be able to query for all of the inputs, including hidden ones
72 doh.register("query input by checked state", [
73 {
74 name: "query checked",
75 runTest: function(){
76 var queried = query("input[checked]", dom.byId('myForm'));
77 doh.is(3, queried.length, "num checked widgets");
78 }
79 }
80 ]);
81
82 doh.register("query input by name", [
83 {
84 name: "query name",
85 runTest: function(){
86 var queried = query("input[name]", dom.byId('myForm'));
87 doh.is(7, queried.length, "input[name]");
88 }
89 }
90 ]);
91
92 var formWidget = registry.byId("myForm");
93
94 var submitForm = function(name, testValues){
95 return {
96 name: name,
97 timeout: 5000,
98 runTest: function(){
99 var d = new doh.Deferred();
100 submittedValues = function(formValues){
101 d.getTestCallback(function(){
102 for(var i in originalGet){ doh.is(testValues[i], formValues[i], i); }
103 })();
104 };
105 formWidget.submit();
106 return d;
107 },
108 tearDown: function(){
109 submittedValues = defaultSubmitHandler;
110 }
111 };
112 };
113
114 doh.register("CheckBox values", [
115 function getValues(){
116 doh.is( json.stringify(originalGet), json.stringify(registry.byId("myForm").get('value')) );
117 },
118 function resetWithoutStateChange(){
119 var dfd = new doh.Deferred();
120 var passed = true;
121 var handle = cb1.on("change", function () { passed = false; });
122 cb1.reset();
123 setTimeout(dfd.getTestCallback(function() {
124 handle.remove();
125 doh.t(passed, "Change event should not fire when checkbox state is not changed from its initial value");
126 }), 50);
127 return dfd;
128 },
129 {
130 timeout: 6000,
131 name: "setValues",
132 runTest: function(){
133 var d = new doh.Deferred();
134
135 setTimeout(d.getTestErrback(function(){
136 submitForm("original submit", originalSubmit);
137 setTimeout(d.getTestErrback(function(){
138 registry.byId("myForm").set('value', change);
139 setTimeout(d.getTestCallback(function(){
140 doh.is(json.stringify(changedGet), json.stringify(registry.byId("myForm").get('value')) );
141 }), 1000);
142 }), 500);
143 }), 500);
144
145 return d;
146 }
147 },
148 {
149 timeout: 6000,
150 name: "resetValues",
151 runTest: function(){
152 var d = new doh.Deferred();
153
154 setTimeout(d.getTestErrback(function(){
155 submitForm("changed submit", changedSubmit);
156 setTimeout(d.getTestErrback(function(){
157 registry.byId("myForm").reset();
158 setTimeout(d.getTestCallback(function(){
159 doh.is( json.stringify(originalGet), json.stringify(registry.byId("myForm").get('value')), "reset to original values" );
160 }), 1000);
161 }), 500);
162 }), 500);
163
164 return d;
165 }
166 },
167 {
168 name: "reset blank value",
169 runTest: function(){
170 doh.f(registry.byId('cb4').params.value, "blank parameter");
171 doh.is("on", registry.byId('cb4').value, "value initially on");
172 registry.byId('cb4').reset();
173 doh.is("on", registry.byId('cb4').value, "on after reset");
174 }
175 }
176 ]);
177
178 doh.register("CheckBox onChange", [
179 function fireOnChange(){
180 var d = new doh.Deferred();
181 var cb = registry.byId('cb2');
182 var changed;
183 cb.on("change", function(){ changed = true; });
184 cb.set('checked', !cb.get('checked'));
185 setTimeout(d.getTestCallback(function(){
186 doh.t(changed, "got onchange");
187 }), 50);
188 return d;
189 },
190
191 function skipOnChange(){
192 var d = new doh.Deferred();
193 var cb = registry.byId('cb2');
194 var changed;
195 cb.on("change", function(){ changed = true; });
196 cb.set('checked', !cb.get('checked'), false);
197 setTimeout(d.getTestCallback(function(){
198 doh.f(changed, "no onchange");
199 }), 50);
200 return d;
201 }
202 ]);
203
204 doh.register("CheckBox watch", [
205 function w(){
206 var cb = registry.byId('cb2');
207 cb.set("checked", true);
208
209 var oldWatch, newWatch;
210 cb.watch("checked", function(name, o, n){
211 oldWatch = o;
212 newWatch = n;
213 });
214
215 cb.set("checked", false);
216 doh.t(oldWatch, "old value was checked");
217 doh.f(newWatch, "new value is unchecked");
218
219 cb.set("checked", true);
220 doh.f(oldWatch, "old value was unchecked");
221 doh.t(newWatch, "new value is checked");
222 }
223 ]);
224
225 // ARIA tests. See also CheckBox_a11y.html.
226 doh.register("aria", function(){
227 var c1 = new CheckBox({
228 disabled: true
229 });
230 c1.placeAt(document.body);
231 doh.t(c1.focusNode.disabled, "disabled set")
232 doh.f(c1.focusNode.hasAttribute("aria-disabled"),
233 "aria-disabled not set, that would be redundant");
234 });
235
236 doh.run();
237 });
238 </script>
239 </head>
240 <body role="main">
241
242 <h1 class="testTitle">Dijit CheckBox Test</h1>
243 <p>
244 Here are some checkboxes. Try clicking, and hovering, tabbing, and using the space bar to select:
245 </p>
246 <!-- to test form submission, you'll need to create an action handler similar to
247 http://www.utexas.edu/teamweb/cgi-bin/generic.cgi -->
248 <form id="myForm" data-dojo-type="dijit/form/Form" data-dojo-props='action:"../formAction.html", method:"", target:"formSubmitIframe"'>
249 <input id="cb1" data-dojo-id="cb1" data-dojo-type="dijit/form/CheckBox" name="cb1" value="foo"/>
250 <label for="cb1">cb1: normal checkbox, with value=foo</label>
251 <br>
252 <input id="cb2" data-dojo-type="dijit/form/CheckBox" name="cb2" checked/>
253 <label for="cb2">cb2: normal checkbox, with default value, initially turned on.</label>
254 <br>
255 <input id="cb3" data-dojo-type="dijit/form/CheckBox" name="cb3" disabled/>
256 <label for="cb3">cb3: disabled checkbox</label>
257 <br>
258 <input id="cb4" data-dojo-type="dijit/form/CheckBox" name="cb4" readOnly checked value=""/><!-- blank value => "on" -->
259 <label for="cb4">cb4: readOnly checkbox, turned on</label>
260 <br>
261 <input id="cb5" data-dojo-type="dijit/form/CheckBox" name="cb5" value=""/>
262 <label for="cb5">cb5: normal checkbox, with specified value=""</label>
263 <br>
264 <input id="cb6"/>
265 <label for="cb6">cb6: instantiated from script</label>
266 <br>
267 <input id="cb7" data-dojo-type="dijit/form/CheckBox" name="cb7"/>
268 <label for="cb7">cb7: normal checkbox.</label>
269 <br>
270 </form>
271 <iframe name="formSubmitIframe" src="about:blank" onload="if(this.values)submittedValues(this.values)" style="display:none;"></iframe>
272 </body>
273 </html>