|
| 1 | +module('Events', { |
| 2 | + setup: function(){ |
| 3 | + this.input = $('<input type="text" value="31-03-2011">') |
| 4 | + .appendTo('#qunit-fixture') |
| 5 | + .datepicker({format: "dd-mm-yyyy"}) |
| 6 | + .focus(); // Activate for visibility checks |
| 7 | + this.dp = this.input.data('datepicker') |
| 8 | + this.picker = this.dp.picker; |
| 9 | + }, |
| 10 | + teardown: function(){ |
| 11 | + this.picker.remove(); |
| 12 | + } |
| 13 | +}); |
| 14 | + |
| 15 | +test('Selecting a year from decade view triggers pickYear', function(){ |
| 16 | + var target, |
| 17 | + triggered = 0; |
| 18 | + |
| 19 | + this.input.on('pickYear', function(){ |
| 20 | + triggered++; |
| 21 | + }); |
| 22 | + |
| 23 | + equal(this.dp.viewMode, 0); |
| 24 | + target = this.picker.find('.datepicker-days thead th.switch'); |
| 25 | + ok(target.is(':visible'), 'View switcher is visible'); |
| 26 | + |
| 27 | + target.click(); |
| 28 | + ok(this.picker.find('.datepicker-months').is(':visible'), 'Month picker is visible'); |
| 29 | + equal(this.dp.viewMode, 1); |
| 30 | + // Not modified when switching modes |
| 31 | + datesEqual(this.dp.viewDate, new Date(2011, 2, 31)); |
| 32 | + datesEqual(this.dp.date, new Date(2011, 2, 31)); |
| 33 | + |
| 34 | + target = this.picker.find('.datepicker-months thead th.switch'); |
| 35 | + ok(target.is(':visible'), 'View switcher is visible'); |
| 36 | + |
| 37 | + target.click(); |
| 38 | + ok(this.picker.find('.datepicker-years').is(':visible'), 'Year picker is visible'); |
| 39 | + equal(this.dp.viewMode, 2); |
| 40 | + // Not modified when switching modes |
| 41 | + datesEqual(this.dp.viewDate, new Date(2011, 2, 31)); |
| 42 | + datesEqual(this.dp.date, new Date(2011, 2, 31)); |
| 43 | + |
| 44 | + // Change years to test internal state changes |
| 45 | + target = this.picker.find('.datepicker-years tbody span:contains(2010)'); |
| 46 | + target.click(); |
| 47 | + equal(this.dp.viewMode, 1); |
| 48 | + // Only viewDate modified |
| 49 | + datesEqual(this.dp.viewDate, new Date(2010, 2, 1)); |
| 50 | + datesEqual(this.dp.date, new Date(2011, 2, 31)); |
| 51 | + equal(triggered, 1); |
| 52 | +}); |
| 53 | + |
| 54 | +test('Selecting a month from year view triggers pickMonth', function(){ |
| 55 | + var target, |
| 56 | + triggered = 0; |
| 57 | + |
| 58 | + this.input.on('pickMonth', function(){ |
| 59 | + triggered++; |
| 60 | + }); |
| 61 | + |
| 62 | + equal(this.dp.viewMode, 0); |
| 63 | + target = this.picker.find('.datepicker-days thead th.switch'); |
| 64 | + ok(target.is(':visible'), 'View switcher is visible'); |
| 65 | + |
| 66 | + target.click(); |
| 67 | + ok(this.picker.find('.datepicker-months').is(':visible'), 'Month picker is visible'); |
| 68 | + equal(this.dp.viewMode, 1); |
| 69 | + // Not modified when switching modes |
| 70 | + datesEqual(this.dp.viewDate, new Date(2011, 2, 31)); |
| 71 | + datesEqual(this.dp.date, new Date(2011, 2, 31)); |
| 72 | + |
| 73 | + target = this.picker.find('.datepicker-months tbody span:contains(Apr)'); |
| 74 | + target.click(); |
| 75 | + equal(this.dp.viewMode, 0); |
| 76 | + // Only viewDate modified |
| 77 | + datesEqual(this.dp.viewDate, new Date(2011, 3, 1)); |
| 78 | + datesEqual(this.dp.date, new Date(2011, 2, 31)); |
| 79 | + equal(triggered, 1); |
| 80 | +}); |
0 commit comments