Debian Codegraph @

dojox/mobile/tests/doh/valuepickerdatepicker/ValuePickerDatePicker.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>ValuePickerDatePicker</title>
9
10 <script type="text/javascript"
11 src="../../../deviceTheme.js" data-dojo-config="mblThemeFiles: ['base','ValuePicker']"></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",
19 "dojox/mobile", "dojox/mobile/compat", "dojox/mobile/parser",
20 "dojox/mobile/ValuePickerDatePicker"],
21 function(ready, registry, runner){
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 checkEndDaysOfMonth = function(nDaysInMonth, title){
100 var daySlot = picker.slots[2];
101 runner.assertEqual(nDaysInMonth, daySlot.items.length, title);
102 };
103
104 // Test case for #16502
105 runner.register("dojox.mobile.test.doh.SpinWheelTests", [
106 {
107 name: "SpinWheelTest1",
108 timeout: 4000,
109 runTest: function(){
110 picker.set('value', '2020-06-06');
111 // setTimeout used because the handlers onYearSet, onMonthSet
112 // and onDaySet are called asynchronously
113 var d = new runner.Deferred();
114 setTimeout(function(){
115 initCounters();
116 // ensure year, month, and day change:
117 picker.set('value', '2019-05-05');
118 // setTimeout used because the handlers onYearSet, onMonthSet
119 // and onDaySet are called asynchronously
120 setTimeout(d.getTestCallback(function(){
121 // notifications for year, month and day
122 checkCounters(1, 1, 1, 1, 1, 1);
123 checkSlotValues("2019", 5/*"May"*/, "5");
124 }), 1000);
125 }, 1000);
126 return d;
127 }
128 },
129 {
130 name: "SpinWheelTest2",
131 timeout: 4000,
132 runTest: function(){
133 picker.set('value', '2020-06-06');
134 // setTimeout used because the handlers onYearSet, onMonthSet
135 // and onDaySet are called asynchronously
136 var d = new runner.Deferred();
137 setTimeout(function(){
138 initCounters();
139 // now only the year changes
140 picker.set('value', '2021-06-06');
141 // setTimeout used because the handlers onYearSet, onMonthSet
142 // and onDaySet are called asynchronously
143 setTimeout(d.getTestCallback(function(){
144 // notifications for year, not for month and day
145 checkCounters(1, 0, 0, 1, 0, 0);
146 checkSlotValues("2021", 6/*"Jun"*/, "6");
147 }), 1000);
148 }, 1000);
149 return d;
150 }
151 },
152 {
153 name: "SpinWheelTest3",
154 timeout: 4000,
155 runTest: function(){
156 picker.set('value', '2013-01-31');
157 // setTimeout used because the handlers onYearSet, onMonthSet
158 // and onDaySet are called asynchronously
159 var d = new runner.Deferred();
160 setTimeout(function(){
161 initCounters();
162 // now change the month from Jan to Feb
163 // The labels/values being localized, let's set
164 var februaryLabel = picker.slots[1].labels[1]; // the second label is for February
165 picker.slots[1].set("value", februaryLabel);
166 // setTimeout used because the handlers onYearSet, onMonthSet
167 // and onDaySet are called asynchronously
168 setTimeout(d.getTestCallback(function(){
169 // notifications for month and day, not for year
170 checkCounters(0, 1, 1, 0, 1, 1);
171 // Check that changing the month also changes the day value
172 // to the last day of Feb. 2012 (leap year, hence last day is 29).
173 checkSlotValues("2013", 2/*"Feb"*/, "28");
174 checkEndDaysOfMonth(28, "SpinWheelTest3"); // grayed out starting with day 29
175 }), 1000);
176 }, 1000);
177 return d;
178 }
179 },
180 {
181 name: "SpinWheelTest4",
182 timeout: 4000,
183 runTest: function(){
184 picker.set('value', '2012-02-29');
185 // setTimeout used because the handlers onYearSet, onMonthSet
186 // and onDaySet are called asynchronously
187 var d = new runner.Deferred();
188 setTimeout(function(){
189 initCounters();
190 // now change the year to 2013
191 picker.slots[0].set("value", "2013");
192 // setTimeout used because the handlers onYearSet, onMonthSet
193 // and onDaySet are called asynchronously
194 setTimeout(d.getTestCallback(function(){
195 // notifications for year and day, not for month
196 checkCounters(1, 0, 1, 1, 0, 1);
197 // Check that changing the year also changes the day value
198 // to the last day of Feb. 2013 (non leap year, hence last day is 28).
199 checkSlotValues("2013", 2/*"Feb"*/, "28");
200 checkEndDaysOfMonth(28, "SpinWheelTest4"); // grayed out starting with day 29
201 }), 1000);
202 }, 1000);
203 return d;
204 }
205 }
206 ]);
207
208 runner.run();
209 });
210 });
211 </script>
212 </head>
213 <body style="visibility:hidden;">
214 <div data-dojo-type="dojox/mobile/View">
215 <form>
216 <div data-dojo-type="dojox/mobile/Heading">
217 SpinWheel
218 </div>
219 <div id="picker1" data-dojo-type="dojox/mobile/ValuePickerDatePicker"
220 data-dojo-props="onYearSet: onYearSet, onMonthSet: onMonthSet, onDaySet: onDaySet"></div>
221 </form>
222 </div>
223 </body>
224 </html>