]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.form.field.Time", function() {\r |
2 | var component, makeComponent;\r | |
3 | \r | |
4 | beforeEach(function() {\r | |
5 | makeComponent = function(config) {\r | |
6 | config = config || {};\r | |
7 | Ext.applyIf(config, {\r | |
8 | name: 'test',\r | |
9 | width: 100\r | |
10 | });\r | |
11 | component = new Ext.form.field.Time(config);\r | |
12 | };\r | |
13 | });\r | |
14 | \r | |
15 | afterEach(function() {\r | |
16 | if (component) {\r | |
17 | component.destroy();\r | |
18 | }\r | |
19 | component = makeComponent = null;\r | |
20 | });\r | |
21 | \r | |
22 | function clickTrigger() {\r | |
23 | var trigger = component.getTrigger('picker').getEl(),\r | |
24 | xy = trigger.getXY();\r | |
25 | jasmine.fireMouseEvent(trigger.dom, 'click', xy[0], xy[1]);\r | |
26 | }\r | |
27 | \r | |
28 | \r | |
29 | it("should be registered with xtype 'timefield'", function() {\r | |
30 | component = Ext.create("Ext.form.field.Time", {name: 'test'});\r | |
31 | expect(component instanceof Ext.form.field.Time).toBe(true);\r | |
32 | expect(Ext.getClass(component).xtype).toBe("timefield");\r | |
33 | });\r | |
34 | \r | |
35 | describe("initialization", function() {\r | |
36 | \r | |
37 | describe("initializing value as string", function() {\r | |
38 | it("should not mark component as dirty", function() {\r | |
39 | makeComponent({\r | |
40 | value: '11:00 AM'\r | |
41 | });\r | |
42 | expect(component.isDirty()).toBeFalsy();\r | |
43 | });\r | |
44 | });\r | |
45 | \r | |
46 | });\r | |
47 | \r | |
48 | \r | |
49 | describe("defaults", function() {\r | |
50 | beforeEach(function() {\r | |
51 | makeComponent();\r | |
52 | });\r | |
53 | it("should have triggerCls = 'x-form-time-trigger'", function() {\r | |
54 | expect(component.triggerCls).toEqual('x-form-time-trigger');\r | |
55 | });\r | |
56 | it("should have multiSelect = false", function() {\r | |
57 | expect(component.multiSelect).toBe(false);\r | |
58 | });\r | |
59 | it("should have delimiter = ', '", function() {\r | |
60 | expect(component.delimiter).toEqual(', ');\r | |
61 | });\r | |
62 | it("should have minValue = undefined", function() {\r | |
63 | expect(component.minValue).not.toBeDefined();\r | |
64 | });\r | |
65 | it("should have maxValue = undefined", function() {\r | |
66 | expect(component.maxValue).not.toBeDefined();\r | |
67 | });\r | |
68 | it("should have minText = 'The time in this field must be equal to or after {0}'", function() {\r | |
69 | expect(component.minText).toEqual('The time in this field must be equal to or after {0}');\r | |
70 | });\r | |
71 | it("should have maxText = 'The time in this field must be equal to or before {0}'", function() {\r | |
72 | expect(component.maxText).toEqual('The time in this field must be equal to or before {0}');\r | |
73 | });\r | |
74 | it("should have invalidText = '{0} is not a valid time'", function() {\r | |
75 | expect(component.invalidText).toEqual('{0} is not a valid time');\r | |
76 | });\r | |
77 | it("should have format = 'g:i A'", function() {\r | |
78 | expect(component.format).toEqual('g:i A');\r | |
79 | });\r | |
80 | it("should have altFormats = 'g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H|gi a|hi a|giA|hiA|gi A|hi A'", function() {\r | |
81 | expect(component.altFormats).toEqual('g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H|gi a|hi a|giA|hiA|gi A|hi A');\r | |
82 | });\r | |
83 | it("should have increment = 15", function() {\r | |
84 | expect(component.increment).toEqual(15);\r | |
85 | });\r | |
86 | });\r | |
87 | \r | |
88 | \r | |
89 | describe("rendering", function() {\r | |
90 | // Mostly handled by Trigger and Picker tests\r | |
91 | \r | |
92 | beforeEach(function() {\r | |
93 | makeComponent({\r | |
94 | renderTo: Ext.getBody()\r | |
95 | });\r | |
96 | });\r | |
97 | \r | |
98 | it("should give the trigger a class of 'x-form-time-trigger'", function() {\r | |
99 | expect(component.getTrigger('picker').el).toHaveCls('x-form-time-trigger');\r | |
100 | });\r | |
101 | });\r | |
102 | \r | |
103 | \r | |
104 | describe("trigger", function() {\r | |
105 | beforeEach(function() {\r | |
106 | makeComponent({\r | |
107 | renderTo: Ext.getBody()\r | |
108 | });\r | |
109 | clickTrigger();\r | |
110 | });\r | |
111 | it("should open a Ext.picker.Time", function() {\r | |
112 | expect(component.picker instanceof Ext.picker.Time).toBe(true);\r | |
113 | expect(component.picker.hidden).toBe(false);\r | |
114 | });\r | |
115 | it("should clear the value when text which cannot be matched to a value is entered", function() {\r | |
116 | waits(1);\r | |
117 | runs(function() {\r | |
118 | expect(component.picker.highlightedItem).toBeDefined();\r | |
119 | component.setValue('ASAP');\r | |
120 | expect(component.getValue()).toBeNull();\r | |
121 | expect(component.getRawValue()).toBe('ASAP');\r | |
122 | });\r | |
123 | });\r | |
124 | });\r | |
125 | \r | |
126 | describe("setting values", function() {\r | |
127 | describe("parsing", function(){\r | |
128 | it("should parse a string value using the format config", function() {\r | |
129 | makeComponent({\r | |
130 | format: 'g:iA',\r | |
131 | value: '8:32PM'\r | |
132 | });\r | |
133 | expect(component.getValue()).toEqualTime(20, 32);\r | |
134 | });\r | |
135 | \r | |
136 | it("should parse a string value using the altFormats config", function() {\r | |
137 | makeComponent({\r | |
138 | format: 'g:i.A',\r | |
139 | altFormats: 'g.i a',\r | |
140 | value: '8.32 pm'\r | |
141 | });\r | |
142 | expect(component.getValue()).toEqualTime(20, 32);\r | |
143 | });\r | |
144 | \r | |
145 | it("should parse a string value using the format config and snap to increment", function() {\r | |
146 | makeComponent({\r | |
147 | snapToIncrement: true,\r | |
148 | format: 'g:iA',\r | |
149 | value: '8:32PM'\r | |
150 | });\r | |
151 | expect(component.getValue()).toEqualTime(20, 30);\r | |
152 | });\r | |
153 | \r | |
154 | it("should parse a string value using the altFormats config and snap to increment", function() {\r | |
155 | makeComponent({\r | |
156 | snapToIncrement: true,\r | |
157 | format: 'g:i.A',\r | |
158 | altFormats: 'g.i a',\r | |
159 | value: '8.32 pm'\r | |
160 | });\r | |
161 | expect(component.getValue()).toEqualTime(20, 30);\r | |
162 | });\r | |
163 | });\r | |
164 | \r | |
165 | describe("setValue", function(){\r | |
166 | it("should accept a date object", function(){\r | |
167 | makeComponent();\r | |
168 | component.setValue(new Date(2010, 10, 5, 9, 46));\r | |
169 | expect(component.getValue()).toEqualTime(9, 46);\r | |
170 | });\r | |
171 | \r | |
172 | it("should accept an array of date objects", function(){\r | |
173 | makeComponent({\r | |
174 | multiSelect: true\r | |
175 | });\r | |
176 | component.setValue([new Date(2008, 0, 1, 10, 30), new Date(2008, 0, 1, 23, 15)]);\r | |
177 | expect(component.getValue()[0]).toEqualTime(10, 30);\r | |
178 | expect(component.getValue()[1]).toEqualTime(23, 15);\r | |
179 | });\r | |
180 | \r | |
181 | it("should accept a string value", function(){\r | |
182 | makeComponent();\r | |
183 | component.setValue('9:46 AM');\r | |
184 | expect(component.getValue()).toEqualTime(9, 46);\r | |
185 | });\r | |
186 | \r | |
187 | it("should accept an array of string values", function() {\r | |
188 | makeComponent({\r | |
189 | multiSelect: true,\r | |
190 | value: ['10:30AM', '11:15PM']\r | |
191 | });\r | |
192 | expect(component.value[0]).toEqualTime(10, 30);\r | |
193 | expect(component.value[1]).toEqualTime(23, 15);\r | |
194 | });\r | |
195 | \r | |
196 | it("should accept a date object and snap to increment", function(){\r | |
197 | makeComponent({\r | |
198 | snapToIncrement: true\r | |
199 | });\r | |
200 | component.setValue(new Date(2010, 10, 5, 9, 46));\r | |
201 | expect(component.getValue()).toEqualTime(9, 45);\r | |
202 | });\r | |
203 | \r | |
204 | it("should accept a string value and snap to increment", function(){\r | |
205 | makeComponent({\r | |
206 | snapToIncrement: true\r | |
207 | });\r | |
208 | component.setValue('9:46 AM');\r | |
209 | expect(component.getValue()).toEqualTime(9, 45);\r | |
210 | });\r | |
211 | \r | |
212 | it("should accept a null value", function(){\r | |
213 | makeComponent();\r | |
214 | component.setValue(null);\r | |
215 | expect(component.getValue()).toBeNull();\r | |
216 | });\r | |
217 | \r | |
218 | it("should set null if an invalid time string is passed", function(){\r | |
219 | makeComponent();\r | |
220 | component.setValue('6:::37');\r | |
221 | expect(component.getValue()).toBeNull();\r | |
222 | });\r | |
223 | \r | |
224 | it("should ignore the date part when setting the value", function() {\r | |
225 | makeComponent({\r | |
226 | minValue: '9:00 AM',\r | |
227 | maxValue: '5:00 PM'\r | |
228 | });\r | |
229 | // The date year/month/day will be equal to whenever the spec is run\r | |
230 | // But the time field defaults all dates to 2008/01/01.\r | |
231 | var d = new Date();\r | |
232 | d.setHours(12, 0);\r | |
233 | component.setValue(d);\r | |
234 | expect(component.isValid()).toBe(true);\r | |
235 | });\r | |
236 | it("should update the expanded dropdown's selection - multi select", function() {\r | |
237 | makeComponent({\r | |
238 | renderTo: Ext.getBody(),\r | |
239 | multiSelect: true\r | |
240 | });\r | |
241 | component.expand();\r | |
242 | waits(1);\r | |
243 | runs(function() {\r | |
244 | component.setValue([new Date(2008, 0, 1, 0, 0), new Date(2008, 0, 1, 0, 15)]);\r | |
245 | expect(component.picker.getSelectionModel().getSelection()[0]).toEqual(component.store.getAt(0));\r | |
246 | expect(component.picker.getSelectionModel().getSelection()[1]).toEqual(component.store.getAt(1));\r | |
247 | });\r | |
248 | });\r | |
249 | \r | |
250 | describe("selecting a value", function() {\r | |
251 | it("should be able to select a value when the current value is not in the store", function() {\r | |
252 | makeComponent({\r | |
253 | increment: 15,\r | |
254 | format: 'H:i',\r | |
255 | increment: 15,\r | |
256 | allowBlank: false,\r | |
257 | value: '15:03',\r | |
258 | renderTo: document.body\r | |
259 | });\r | |
260 | \r | |
261 | component.expand();\r | |
262 | jasmine.fireMouseEvent(component.getPicker().getNode(component.store.getAt(0)), 'click');\r | |
263 | expect(component.getValue()).toEqualTime(0, 0);\r | |
264 | \r | |
265 | });\r | |
266 | });\r | |
267 | \r | |
268 | describe("inputEl", function () {\r | |
269 | it("should accept a model", function(){\r | |
270 | makeComponent({\r | |
271 | minValue: '6:00 AM',\r | |
272 | maxValue: '8:00 PM',\r | |
273 | renderTo: document.body\r | |
274 | });\r | |
275 | component.setValue(component.store.getAt(0));\r | |
276 | expect(component.inputEl.getValue()).toBe('6:00 AM');\r | |
277 | });\r | |
278 | \r | |
279 | it("should parse a string value to lookup a record in the store", function(){\r | |
280 | makeComponent({\r | |
281 | minValue: '6:00 AM',\r | |
282 | maxValue: '8:00 PM',\r | |
283 | renderTo: document.body\r | |
284 | });\r | |
285 | component.setValue('15');\r | |
286 | expect(component.inputEl.getValue()).toBe('3:00 PM');\r | |
287 | });\r | |
288 | \r | |
289 | it("should display same value given to setValue when no lookups in the store", function(){\r | |
290 | makeComponent({\r | |
291 | minValue: '6:00 AM',\r | |
292 | maxValue: '8:00 PM',\r | |
293 | renderTo: document.body\r | |
294 | });\r | |
295 | component.setValue('21');\r | |
296 | expect(component.inputEl.getValue()).toBe('21');\r | |
297 | });\r | |
298 | });\r | |
299 | \r | |
300 | describe("change event", function () {\r | |
301 | it("should not fire the change event when the value stays the same - single value", function() {\r | |
302 | var spy = jasmine.createSpy();\r | |
303 | makeComponent({\r | |
304 | renderTo: Ext.getBody(),\r | |
305 | value: '10:00AM',\r | |
306 | listeners: {\r | |
307 | change: spy\r | |
308 | }\r | |
309 | });\r | |
310 | component.setValue('10:00AM');\r | |
311 | expect(spy).not.toHaveBeenCalled();\r | |
312 | });\r | |
313 | \r | |
314 | it("should fire the change event when the value changes - single value", function() {\r | |
315 | var spy = jasmine.createSpy();\r | |
316 | makeComponent({\r | |
317 | value: '10:00AM',\r | |
318 | renderTo: Ext.getBody(),\r | |
319 | listeners: {\r | |
320 | change: spy\r | |
321 | }\r | |
322 | });\r | |
323 | component.setValue('11:15PM');\r | |
324 | expect(spy).toHaveBeenCalled();\r | |
325 | expect(spy.mostRecentCall.args[0]).toBe(component);\r | |
326 | expect(spy.mostRecentCall.args[1]).toEqualTime(23, 15);\r | |
327 | });\r | |
328 | \r | |
329 | it("should not fire the change event when the value stays the same - multiple values", function() {\r | |
330 | var spy = jasmine.createSpy();\r | |
331 | makeComponent({\r | |
332 | multiSelect: true,\r | |
333 | valueField: 'val',\r | |
334 | value: ['10:00AM', '11:15PM'],\r | |
335 | renderTo: Ext.getBody(),\r | |
336 | listeners: {\r | |
337 | change: spy\r | |
338 | }\r | |
339 | });\r | |
340 | component.setValue(['10:00AM', '11:15PM']);\r | |
341 | expect(spy).not.toHaveBeenCalled();\r | |
342 | });\r | |
343 | \r | |
344 | it("should fire the change event when the value changes - multiple values", function() {\r | |
345 | var spy = jasmine.createSpy();\r | |
346 | makeComponent({\r | |
347 | multiSelect: true,\r | |
348 | valueField: 'val',\r | |
349 | value: ['10:00AM', '11:15PM'],\r | |
350 | renderTo: Ext.getBody(),\r | |
351 | listeners: {\r | |
352 | change: spy\r | |
353 | }\r | |
354 | });\r | |
355 | component.setValue(['3:00PM', '4:30PM']);\r | |
356 | expect(spy).toHaveBeenCalled();\r | |
357 | expect(spy.mostRecentCall.args[0]).toBe(component);\r | |
358 | expect(spy.mostRecentCall.args[2][0]).toEqualTime(10);\r | |
359 | expect(spy.mostRecentCall.args[2][1]).toEqualTime(23, 15);\r | |
360 | expect(spy.mostRecentCall.args[1][0]).toEqualTime(15);\r | |
361 | expect(spy.mostRecentCall.args[1][1]).toEqualTime(16, 30);\r | |
362 | });\r | |
363 | });\r | |
364 | });\r | |
365 | });\r | |
366 | \r | |
367 | describe("submit value", function(){\r | |
368 | it("should use the format as the default", function () {\r | |
369 | makeComponent({\r | |
370 | value:new Date(2010, 0, 15, 15, 30),\r | |
371 | format:'H:i'\r | |
372 | });\r | |
373 | expect(component.getSubmitValue()).toBe('15:30');\r | |
374 | });\r | |
375 | \r | |
376 | it("should give precedence to submitFormat", function(){\r | |
377 | makeComponent({\r | |
378 | value: new Date(2010, 0, 15, 15, 45),\r | |
379 | submitFormat: 'H:i'\r | |
380 | });\r | |
381 | expect(component.getSubmitValue()).toBe('15:45');\r | |
382 | });\r | |
383 | \r | |
384 | it("should still return null if the value isn't a valid date", function(){\r | |
385 | makeComponent({\r | |
386 | value: 'wontparse',\r | |
387 | submitFormat: 'H:i'\r | |
388 | });\r | |
389 | expect(component.getSubmitValue()).toBeNull();\r | |
390 | });\r | |
391 | });\r | |
392 | \r | |
393 | describe("getModelData", function(){\r | |
394 | it("should use the format as the default", function(){\r | |
395 | makeComponent({\r | |
396 | name: 'myname',\r | |
397 | value: new Date(2010, 0, 15, 15, 45)\r | |
398 | });\r | |
399 | var modelData = component.getModelData();\r | |
400 | expect(modelData.myname).toEqualTime(15, 45);\r | |
401 | });\r | |
402 | \r | |
403 | it("should return null if the value isn't a valid date", function(){\r | |
404 | makeComponent({\r | |
405 | name: 'myname',\r | |
406 | value: 'wontparse',\r | |
407 | submitFormat: 'H:i'\r | |
408 | });\r | |
409 | expect(component.getModelData()).toEqual({myname: null});\r | |
410 | });\r | |
411 | });\r | |
412 | \r | |
413 | \r | |
414 | describe("minValue", function() {\r | |
415 | describe("minValue config", function() {\r | |
416 | it("should allow a string, parsed according to the format config", function() {\r | |
417 | makeComponent({\r | |
418 | format: 'g:i.A',\r | |
419 | minValue: '8:30.AM'\r | |
420 | });\r | |
421 | expect(component.minValue).toEqualTime(8,30);\r | |
422 | });\r | |
423 | \r | |
424 | it("should allow times after it to pass validation", function() {\r | |
425 | makeComponent({\r | |
426 | minValue: '8:45 AM',\r | |
427 | value: '9:15 AM'\r | |
428 | });\r | |
429 | expect(component.getErrors().length).toEqual(0);\r | |
430 | });\r | |
431 | \r | |
432 | it("should cause times before it to fail validation", function() {\r | |
433 | makeComponent({\r | |
434 | minValue: '10:45 AM',\r | |
435 | value: '9:15 AM'\r | |
436 | });\r | |
437 | expect(component.getErrors().length).toEqual(1);\r | |
438 | expect(component.getErrors()[0]).toEqual('The time in this field must be equal to or after 10:45 AM');\r | |
439 | });\r | |
440 | \r | |
441 | it("should fall back to 12AM if the string cannot be parsed", function() {\r | |
442 | makeComponent({\r | |
443 | minValue: 'foopy',\r | |
444 | value: '12:00 AM'\r | |
445 | });\r | |
446 | expect(component.getErrors().length).toEqual(0);\r | |
447 | });\r | |
448 | \r | |
449 | it("should allow a Date object", function() {\r | |
450 | makeComponent({\r | |
451 | minValue: new Date(2010, 1, 1, 8, 30)\r | |
452 | });\r | |
453 | expect(component.minValue).toEqualTime(8,30);\r | |
454 | });\r | |
455 | \r | |
456 | it("should be passed to the time picker object", function() {\r | |
457 | makeComponent({\r | |
458 | minValue: '8:45 AM'\r | |
459 | });\r | |
460 | component.expand();\r | |
461 | expect(component.getPicker().minValue).toEqualTime(8, 45);\r | |
462 | });\r | |
463 | });\r | |
464 | \r | |
465 | describe("setMinValue method", function() {\r | |
466 | it("should allow a string, parsed according to the format config", function() {\r | |
467 | makeComponent({\r | |
468 | format: 'g:i A'\r | |
469 | });\r | |
470 | component.setMinValue('1:15 PM');\r | |
471 | expect(component.minValue).toEqualTime(13, 15);\r | |
472 | });\r | |
473 | \r | |
474 | it("should allow times after it to pass validation", function() {\r | |
475 | makeComponent({\r | |
476 | value: '9:15 AM'\r | |
477 | });\r | |
478 | component.setMinValue('7:45 AM');\r | |
479 | expect(component.getErrors().length).toEqual(0);\r | |
480 | });\r | |
481 | \r | |
482 | it("should cause times before it to fail validation", function() {\r | |
483 | makeComponent({\r | |
484 | value: '9:15 AM'\r | |
485 | });\r | |
486 | component.setMinValue('10:45 AM');\r | |
487 | expect(component.getErrors().length).toEqual(1);\r | |
488 | expect(component.getErrors()[0]).toEqual('The time in this field must be equal to or after 10:45 AM');\r | |
489 | });\r | |
490 | \r | |
491 | it("should fall back to 12AM if the string cannot be parsed", function() {\r | |
492 | makeComponent({\r | |
493 | value: '12:00 AM'\r | |
494 | });\r | |
495 | component.setMinValue('foopy');\r | |
496 | expect(component.getErrors().length).toEqual(0);\r | |
497 | });\r | |
498 | \r | |
499 | it("should allow a Date object", function() {\r | |
500 | makeComponent();\r | |
501 | component.setMinValue(new Date(2010, 1, 1, 8, 30));\r | |
502 | expect(component.minValue).toEqualTime(8,30);\r | |
503 | });\r | |
504 | \r | |
505 | it("should call the time picker's setMinValue method", function() {\r | |
506 | makeComponent();\r | |
507 | component.expand();\r | |
508 | var spy = spyOn(component.getPicker(), 'setMinValue');\r | |
509 | component.setMinValue('11:15 AM');\r | |
510 | expect(spy).toHaveBeenCalled();\r | |
511 | expect(spy.mostRecentCall.args[0]).toEqualTime(11, 15);\r | |
512 | });\r | |
513 | });\r | |
514 | });\r | |
515 | \r | |
516 | describe("maxValue", function() {\r | |
517 | describe("maxValue config", function() {\r | |
518 | it("should allow a string, parsed according to the format config", function() {\r | |
519 | makeComponent({\r | |
520 | format: 'g:i.A',\r | |
521 | maxValue: '8:30.PM'\r | |
522 | });\r | |
523 | expect(component.maxValue).toEqualTime(20,30);\r | |
524 | });\r | |
525 | \r | |
526 | it("should allow times before it to pass validation", function() {\r | |
527 | makeComponent({\r | |
528 | maxValue: '8:45 PM',\r | |
529 | value: '7:15 PM'\r | |
530 | });\r | |
531 | expect(component.getErrors().length).toEqual(0);\r | |
532 | });\r | |
533 | \r | |
534 | it("should cause times after it to fail validation", function() {\r | |
535 | makeComponent({\r | |
536 | maxValue: '8:45 PM',\r | |
537 | value: '9:15 PM'\r | |
538 | });\r | |
539 | expect(component.getErrors().length).toEqual(1);\r | |
540 | expect(component.getErrors()[0]).toEqual('The time in this field must be equal to or before 8:45 PM');\r | |
541 | });\r | |
542 | \r | |
543 | it("should fall back to the end of the day if the string cannot be parsed", function() {\r | |
544 | makeComponent({\r | |
545 | maxValue: 'foopy',\r | |
546 | value: '11:59 PM'\r | |
547 | });\r | |
548 | expect(component.getErrors().length).toEqual(0);\r | |
549 | });\r | |
550 | \r | |
551 | it("should allow a Date object", function() {\r | |
552 | makeComponent({\r | |
553 | maxValue: new Date(2010, 1, 1, 20, 30)\r | |
554 | });\r | |
555 | expect(component.maxValue).toEqualTime(20, 30);\r | |
556 | });\r | |
557 | \r | |
558 | it("should be passed to the time picker object", function() {\r | |
559 | makeComponent({\r | |
560 | maxValue: '8:45 PM'\r | |
561 | });\r | |
562 | component.expand();\r | |
563 | expect(component.getPicker().maxValue).toEqualTime(20, 45);\r | |
564 | });\r | |
565 | });\r | |
566 | \r | |
567 | describe("setMaxValue method", function() {\r | |
568 | it("should allow a string, parsed according to the format config", function() {\r | |
569 | makeComponent({\r | |
570 | format: 'g:i A'\r | |
571 | });\r | |
572 | component.setMaxValue('1:15 PM');\r | |
573 | expect(component.maxValue).toEqualTime(13, 15);\r | |
574 | });\r | |
575 | \r | |
576 | it("should allow times before it to pass validation", function() {\r | |
577 | makeComponent({\r | |
578 | value: '5:15 PM'\r | |
579 | });\r | |
580 | component.setMaxValue('7:45 PM');\r | |
581 | expect(component.getErrors().length).toEqual(0);\r | |
582 | });\r | |
583 | \r | |
584 | it("should cause times after it to fail validation", function() {\r | |
585 | makeComponent({\r | |
586 | value: '9:15 PM'\r | |
587 | });\r | |
588 | component.setMaxValue('7:45 PM');\r | |
589 | expect(component.getErrors().length).toEqual(1);\r | |
590 | expect(component.getErrors()[0]).toEqual('The time in this field must be equal to or before 7:45 PM');\r | |
591 | });\r | |
592 | \r | |
593 | it("should fall back to the end of the day if the string cannot be parsed", function() {\r | |
594 | makeComponent({\r | |
595 | value: '11:59 PM'\r | |
596 | });\r | |
597 | component.setMaxValue('foopy');\r | |
598 | expect(component.getErrors().length).toEqual(0);\r | |
599 | });\r | |
600 | \r | |
601 | it("should allow a Date object", function() {\r | |
602 | makeComponent();\r | |
603 | component.setMaxValue(new Date(2010, 1, 1, 20, 30));\r | |
604 | expect(component.maxValue).toEqualTime(20, 30);\r | |
605 | });\r | |
606 | \r | |
607 | it("should call the time picker's setMaxValue method", function() {\r | |
608 | makeComponent();\r | |
609 | component.expand();\r | |
610 | var spy = spyOn(component.getPicker(), 'setMaxValue');\r | |
611 | component.setMaxValue('11:15 PM');\r | |
612 | expect(spy).toHaveBeenCalled();\r | |
613 | expect(spy.mostRecentCall.args[0]).toEqualTime(23, 15);\r | |
614 | });\r | |
615 | });\r | |
616 | });\r | |
617 | \r | |
618 | describe('onBlur', function() {\r | |
619 | beforeEach(function() {\r | |
620 | makeComponent({\r | |
621 | renderTo: Ext.getBody()\r | |
622 | });\r | |
623 | });\r | |
624 | \r | |
625 | it('should format the raw value', function () {\r | |
626 | jasmine.focusAndWait(component);\r | |
627 | \r | |
628 | runs(function() {\r | |
629 | component.setRawValue('123');\r | |
630 | \r | |
631 | // Programmatic blur fails on IEs. Focus then remove a button\r | |
632 | Ext.getBody().createChild({ tag: 'button' }).focus().remove();\r | |
633 | });\r | |
634 | \r | |
635 | waitsFor(function() {\r | |
636 | return !component.hasFocus;\r | |
637 | }, 'the TimeField to blur', 1000);\r | |
638 | \r | |
639 | runs(function() {\r | |
640 | expect(component.getRawValue()).toEqual('1:23 AM');\r | |
641 | });\r | |
642 | });\r | |
643 | \r | |
644 | it('should not reset the hours, minutes or seconds', function () {\r | |
645 | var parts, d;\r | |
646 | \r | |
647 | parts = component.initDateParts;\r | |
648 | d = new Date(parts[0], parts[1], parts[2], 13, 22, 42);\r | |
649 | \r | |
650 | jasmine.focusAndWait(component);\r | |
651 | \r | |
652 | runs(function() {\r | |
653 | component.setValue(d);\r | |
654 | component.blur();\r | |
655 | });\r | |
656 | \r | |
657 | waitsFor(function() {\r | |
658 | return !component.hasFocus;\r | |
659 | }, 'the TimeField to blur', 1000);\r | |
660 | \r | |
661 | runs(function() {\r | |
662 | expect(component.getValue()).toEqual(d);\r | |
663 | });\r | |
664 | });\r | |
665 | });\r | |
666 | \r | |
667 | describe("validation", function() {\r | |
668 | it("should return the invalidText if an invalid time string is entered via text", function () {\r | |
669 | makeComponent();\r | |
670 | component.setRawValue('01:000 AM');\r | |
671 | expect(component.getErrors()[0]).toBe(Ext.String.format(component.invalidText, '01:000 AM'));\r | |
672 | });\r | |
673 | });\r | |
674 | \r | |
675 | describe('syncSelection', function () {\r | |
676 | it('should call select on the selection model with the new value record if there are no valid selections and forceSelect is false', function () {\r | |
677 | makeComponent({\r | |
678 | minValue: '7:00 PM',\r | |
679 | maxValue: '9:15 PM'\r | |
680 | });\r | |
681 | \r | |
682 | spyOn(component.picker.selModel, 'select');\r | |
683 | component.setValue('1');\r | |
684 | \r | |
685 | expect(component.picker.selModel.select).toHaveBeenCalled();\r | |
686 | });\r | |
687 | });\r | |
688 | \r | |
689 | describe('forceSelection', function () {\r | |
690 | function doTest(value) {\r | |
691 | makeComponent({\r | |
692 | forceSelection: true,\r | |
693 | minValue: '7:00 PM',\r | |
694 | maxValue: '9:15 PM',\r | |
695 | value: value\r | |
696 | });\r | |
697 | }\r | |
698 | \r | |
699 | it('should work with a legitimate value', function () {\r | |
700 | var v = '9:00 PM';\r | |
701 | doTest(v);\r | |
702 | \r | |
703 | expect(component.selection.data.disp).toBe(v);\r | |
704 | });\r | |
705 | \r | |
706 | it('should work with an illegitimate value', function () {\r | |
707 | doTest('9:01 PM');\r | |
708 | \r | |
709 | expect(component.selection).toBe(null);\r | |
710 | });\r | |
711 | });\r | |
712 | });\r |