Debian Codegraph @

dojox/mobile/tests/doh/spinwheeldatepicker/SpinWheelDatePicker.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5 <meta name="viewport"
6 content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
7 <meta name="apple-mobile-web-app-capable" content="yes"/>
8 <title>SpinWheelDatePicker</title>
9
10 <script type="text/javascript"
11 src="../../../deviceTheme.js" data-dojo-config="mblThemeFiles: ['base','SpinWheel']"></script>
12 <script type="text/javascript"
13 src="../../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script>
14
15 <script type="text/javascript">
16 var onYearSet, onMonthSet, onDaySet;
17 require([
18 "dojo/ready", "dijit/registry", "doh/runner", "dojo/_base/array",
19 "dojo/dom-class", "dojox/mobile", "dojox/mobile/compat", "dojox/mobile/parser",
20 "dojox/mobile/SpinWheelDatePicker"],
21 function(ready, registry, runner, array, domClass){
22
23 var onYearSetCounter = 0, onMonthSetCounter = 0, onDaySetCounter = 0,
24 yearWatchCounter = 0, monthWatchCounter = 0, dayWatchCounter = 0;
25 var initCounters, checkCounters;
26
27 onYearSet = function(){
28 onYearSetCounter++;
29 };
30 onMonthSet = function(){
31 onMonthSetCounter++;
32 };
33 onDaySet = function(){
34 onDaySetCounter++;
35 };
36
37 var initCounters = function(){
38 onYearSetCounter = onMonthSetCounter = onDaySetCounter = 0;
39 yearWatchCounter = monthWatchCounter = dayWatchCounter = 0;
40 };
41
42 ready(function(){
43 var picker = registry.byId("picker1"),
44 yearSlot = picker.slots[0],
45 monthSlot = picker.slots[1],
46 daySlot = picker.slots[2];
47
48 yearSlot.watch("value", function(name, oldVal, newVal){
49 yearWatchCounter++;
50 });
51 monthSlot.watch("value", function(name, oldVal, newVal){
52 monthWatchCounter++;
53 });
54 daySlot.watch("value", function(name, oldVal, newVal){
55 dayWatchCounter++;
56 });
57
58 var showCounters = function(txt){
59 // Just for debugging.
60 console.log("==============================");
61 if(txt) console.log(txt + ":");
62 console.log("yearSetCounter: " + onYearSetCounter);
63 console.log("monthSetCounter: " + onMonthSetCounter);
64 console.log("daySetCounter: " + onDaySetCounter);
65 console.log("yearWatchCounter: " + yearWatchCounter);
66 console.log("monthWatchCounter: " + monthWatchCounter);
67 console.log("dayWatchCounter: " + dayWatchCounter);
68 console.log("==============================");
69 };
70
71 var checkCounters = function(
72 expectedOnYearSetCounter, expectedOnMonthSetCounter, expectedOnDaySetCounter,
73 expectedYearWatchCounter, expectedMonthWatchCounter, expectedDayWatchCounter){
74 // showCounters();
75 runner.assertEqual(expectedOnYearSetCounter, onYearSetCounter, "Unexpected onYearSetCounter");
76 runner.assertEqual(expectedOnMonthSetCounter, onMonthSetCounter, "Unexpected onMonthSetCounter");
77 runner.assertEqual(expectedOnDaySetCounter, onDaySetCounter, "Unexpected onDaySetCounter");
78 runner.assertEqual(expectedYearWatchCounter, yearWatchCounter, "Unexpected yearWatchCounter");
79 runner.assertEqual(expectedMonthWatchCounter, monthWatchCounter, "Unexpected monthWatchCounter");
80 runner.assertEqual(expectedDayWatchCounter, dayWatchCounter, "Unexpected dayWatchCounter");
81 };
82
83 var checkSlotValues = function(expectedYear, expectedMonth, expectedDay){
84 runner.assertEqual(expectedYear, picker.slots[0].get("value"), "Unexpected value of year slot");
85 runner.assertEqual(expectedDay, picker.slots[2].get("value"), "Unexpected value of day slot");
86 // For the month, note that the label (and value) of the month slot is
87 // localized, and is also browser-dependant (for instance, on IE8 in English
88 // locale, the value for the fifth month is "may", while on other browsers
89 // it is "May". Hence, in this test, instead of comparing directly the
90 // value of the slot with a given string ("May"), we start from the month
91 // number and we compare the current value of the slot with the label
92 // at the corresponding index. Thus the test is independent on locale
93 // and browser localization of month names.
94 var monthSlot = picker.slots[1];
95 var expectedMonthLabel = monthSlot.labels[expectedMonth - 1];
96 runner.assertEqual(expectedMonthLabel, monthSlot.get("value"), "Unexpected value of month slot");
97 };
98
99 var checkGrayedDaySlots = function(minGrayDay, title){
100 minGrayDay--; // index 0 holds for day 1
101 var daySlot = picker.slots[2];
102 var child, i;
103 array.forEach(daySlot.panelNodes, function(panel){
104 for(i = 0; i < minGrayDay; i++){
105 child = panel.childNodes[i];
106 runner.assertFalse(domClass.contains(child, "mblSpinWheelSlotLabelGray"),
107 " Day " + (i + 1) + " should NOT be grayed. " +
108 "Actual child.className: " + child.className + " (" + title + ")");
109 }
110 });
111 array.forEach(daySlot.panelNodes, function(panel){
112 for(i = minGrayDay; i < panel.childNodes.length; i++){
113 child = panel.childNodes[i];
114 runner.assertTrue(domClass.contains(child, "mblSpinWheelSlotLabelGray"),
115 " Day " + (i + 1) + " should be grayed. " +
116 "Actual child.className: " + child.className + " (" + title + ")");
117 }
118 });
119 };
120
121 // Test case for #16502
122 runner.register("dojox.mobile.test.doh.SpinWheelTests", [
123 {
124 name: "SpinWheelTest1",
125 timeout: 4000,
126 runTest: function(){
127 picker.set('value', '2020-06-06');
128 // setTimeout used because the handlers onYearSet, onMonthSet
129 // and onDaySet are called asynchronously
130 var d = new runner.Deferred();
131 setTimeout(function(){
132 initCounters();
133 // ensure year, month, and day change:
134 picker.set('value', '2019-05-05');
135 // setTimeout used because the handlers onYearSet, onMonthSet
136 // and onDaySet are called asynchronously
137 setTimeout(d.getTestCallback(function(){
138 // notifications for year, month and day
139 checkCounters(1, 1, 1, 1, 1, 1);
140 checkSlotValues("2019", 5/*"May"*/, "5");
141 }), 1000);
142 }, 1000);
143 return d;
144 }
145 },
146 {
147 name: "SpinWheelTest2",
148 timeout: 4000,
149 runTest: function(){
150 picker.set('value', '2020-06-06');
151 // setTimeout used because the handlers onYearSet, onMonthSet
152 // and onDaySet are called asynchronously
153 var d = new runner.Deferred();
154 setTimeout(function(){
155 initCounters();
156 // now only the year changes
157 picker.set('value', '2021-06-06');
158 // setTimeout used because the handlers onYearSet, onMonthSet
159 // and onDaySet are called asynchronously
160 setTimeout(d.getTestCallback(function(){
161 // notifications for year, not for month and day
162 checkCounters(1, 0, 0, 1, 0, 0);
163 checkSlotValues("2021", 6/*"Jun"*/, "6");
164 }), 1000);
165 }, 1000);
166 return d;
167 }
168 },
169 {
170 name: "SpinWheelTest3",
171 timeout: 4000,
172 runTest: function(){
173 picker.set('value', '2013-01-31');
174 // setTimeout used because the handlers onYearSet, onMonthSet
175 // and onDaySet are called asynchronously
176 var d = new runner.Deferred();
177 setTimeout(function(){
178 initCounters();
179 // now change the month from Jan to Feb
180 // The labels/values being localized, let's set
181 var februaryLabel = picker.slots[1].labels[1]; // the second label is for February
182 picker.slots[1].set("value", februaryLabel);
183 // setTimeout used because the handlers onYearSet, onMonthSet
184 // and onDaySet are called asynchronously
185 setTimeout(d.getTestCallback(function(){
186 // notifications for month and day, not for year
187 checkCounters(0, 1, 1, 0, 1, 1);
188 // Check that changing the month also changes the day value
189 // to the last day of Feb. 2012 (leap year, hence last day is 29).
190 checkSlotValues("2013", 2/*"Feb"*/, "28");
191 checkGrayedDaySlots(29, "SpinWheelTest3"); // grayed out starting with day 29
192 }), 1000);
193 }, 1000);
194 return d;
195 }
196 },
197 {
198 name: "SpinWheelTest4",
199 timeout: 4000,
200 runTest: function(){
201 picker.set('value', '2012-02-29');
202 // setTimeout used because the handlers onYearSet, onMonthSet
203 // and onDaySet are called asynchronously
204 var d = new runner.Deferred();
205 setTimeout(function(){
206 initCounters();
207 // now change the year to 2013
208 picker.slots[0].set("value", "2013");
209 // setTimeout used because the handlers onYearSet, onMonthSet
210 // and onDaySet are called asynchronously
211 setTimeout(d.getTestCallback(function(){
212 // notifications for year and day, not for month
213 checkCounters(1, 0, 1, 1, 0, 1);
214 // Check that changing the year also changes the day value
215 // to the last day of Feb. 2013 (non leap year, hence last day is 28).
216 checkSlotValues("2013", 2/*"Feb"*/, "28");
217 checkGrayedDaySlots(29, "SpinWheelTest4"); // grayed out starting with day 29
218 }), 1000);
219 }, 1000);
220 return d;
221 }
222 },
223 {
224 name: "SpinWheelTest5",
225 timeout: 4000,
226 runTest: function(){
227 picker.set('value', '2012-02-29');
228 // setTimeout used because the handlers onYearSet, onMonthSet
229 // and onDaySet are called asynchronously
230 var d = new runner.Deferred();
231 setTimeout(function(){
232 initCounters();
233 // now try to change the day to Feb. 31 which is an invalid date
234 picker.slots[2].spin(-2);
235 // setTimeout used because the handlers onYearSet, onMonthSet
236 // and onDaySet are called asynchronously
237 setTimeout(d.getTestCallback(function(){
238 // no notifications for year, month or day
239 checkCounters(0, 0, 0, 0, 0, 0);
240 // Check that the slots kept their initial value after trying
241 // to set an invalid day
242 checkSlotValues("2012", 2/*"Feb"*/, "29");
243 checkGrayedDaySlots(30, "SpinWheelTest5"); // grayed out starting with day 30
244 }), 1000);
245 }, 1000);
246 return d;
247 }
248 }
249 ]);
250
251 runner.run();
252 });
253 });
254 </script>
255 </head>
256 <body style="visibility:hidden;">
257 <div data-dojo-type="dojox/mobile/View">
258 <form>
259 <div data-dojo-type="dojox/mobile/Heading">
260 SpinWheel
261 </div>
262 <div id="picker1" data-dojo-type="dojox/mobile/SpinWheelDatePicker"
263 data-dojo-props="onYearSet: onYearSet, onMonthSet: onMonthSet, onDaySet: onDaySet"></div>
264 </form>
265 </div>
266 </body>
267 </html>