Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 1 | define(['datepicker'], function (dpClass) { |
| 2 | describe('KorAP.Datepicker', function () { |
| 3 | |
| 4 | it('should be initializable', function () { |
| 5 | var dp = dpClass.create(); |
| 6 | var e = dp.show(); |
| 7 | expect(e.nodeName).toEqual('DIV'); |
| 8 | expect(e.classList.contains('datepicker')).toBeTruthy(); |
| 9 | expect(e.getAttribute('tabindex')).toEqual('0'); |
| 10 | }); |
| 11 | |
| 12 | it('should generate valid dates', function () { |
| 13 | var dp = dpClass.create(); |
| 14 | expect(dp.today()).toMatch("\\d{4}-[01\\d-[01]\\d"); |
| 15 | }); |
| 16 | |
| 17 | it('should have year and month helpers', function () { |
| 18 | var dp = dpClass.create(); |
| 19 | var e = dp.show(2013, 2); |
| 20 | expect(e.nodeName).toEqual('DIV'); |
| 21 | expect(e.classList.contains('datepicker')).toBeTruthy(); |
| 22 | expect(e.getAttribute('tabindex')).toEqual('0'); |
| 23 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2013'); |
| 24 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 25 | }); |
| 26 | |
| 27 | it('should have modifyable year', function () { |
| 28 | var dp = dpClass.create(); |
| 29 | var e = dp.show(2013, 2); |
| 30 | expect(e.nodeName).toEqual('DIV'); |
| 31 | expect(e.classList.contains('datepicker')).toBeTruthy(); |
| 32 | expect(e.getAttribute('tabindex')).toEqual('0'); |
| 33 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2013'); |
| 34 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 35 | |
| 36 | dp.incrYear(); |
| 37 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2014'); |
| 38 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 39 | |
| 40 | dp.incrYear(); |
| 41 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2015'); |
| 42 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 43 | |
| 44 | dp.decrYear(); |
| 45 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2014'); |
| 46 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 47 | |
| 48 | // Max value |
Akron | 56ea7e3 | 2016-04-20 12:25:52 +0200 | [diff] [blame] | 49 | e = dp.show(9998, 2); |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 50 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('9998'); |
| 51 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 52 | |
| 53 | dp.incrYear(); |
| 54 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('9999'); |
| 55 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 56 | |
| 57 | dp.incrYear(); |
| 58 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('9999'); |
| 59 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 60 | |
| 61 | // Min value |
Akron | 56ea7e3 | 2016-04-20 12:25:52 +0200 | [diff] [blame] | 62 | e = dp.show(2, 2); |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 63 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2'); |
| 64 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 65 | |
| 66 | dp.decrYear(); |
| 67 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('1'); |
| 68 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 69 | |
| 70 | dp.decrYear(); |
| 71 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('0'); |
| 72 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 73 | |
| 74 | dp.decrYear(); |
| 75 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('0'); |
| 76 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 77 | }); |
| 78 | |
| 79 | it('should have modifyable month', function () { |
| 80 | var dp = dpClass.create(); |
Akron | 56ea7e3 | 2016-04-20 12:25:52 +0200 | [diff] [blame] | 81 | var e = dp.show(2012, 9); |
| 82 | |
| 83 | expect(e.nodeName).toEqual('DIV'); |
| 84 | expect(e.classList.contains('datepicker')).toBeTruthy(); |
| 85 | |
| 86 | expect(e.getAttribute('tabindex')).toEqual('0'); |
| 87 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2012'); |
| 88 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('September'); |
| 89 | |
| 90 | dp.incrMonth(); |
| 91 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2012'); |
| 92 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('October'); |
| 93 | |
| 94 | dp.incrMonth(); |
| 95 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2012'); |
| 96 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('November'); |
| 97 | |
| 98 | dp.incrMonth(); |
| 99 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2012'); |
| 100 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('December'); |
| 101 | |
| 102 | dp.incrMonth(); |
| 103 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2013'); |
| 104 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('January'); |
| 105 | |
| 106 | dp.decrMonth(); |
| 107 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('2012'); |
| 108 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('December'); |
| 109 | |
| 110 | // Max value |
| 111 | e = dp.show(9999, 12); |
| 112 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('9999'); |
| 113 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('December'); |
| 114 | |
| 115 | dp.incrMonth(); |
| 116 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('9999'); |
| 117 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('December'); |
| 118 | |
| 119 | // Min value |
| 120 | e = dp.show(1, 2); |
| 121 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('1'); |
| 122 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 123 | |
| 124 | dp.decrMonth(); |
| 125 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('1'); |
| 126 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('January'); |
| 127 | |
| 128 | dp.decrMonth(); |
| 129 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('0'); |
| 130 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('December'); |
| 131 | |
| 132 | e = dp.show(0, 2); |
| 133 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('0'); |
| 134 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('February'); |
| 135 | |
| 136 | dp.decrMonth(); |
| 137 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('0'); |
| 138 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('January'); |
| 139 | |
| 140 | dp.decrMonth(); |
| 141 | expect(e.querySelector('div.year > span:nth-child(2)').firstChild.data).toEqual('0'); |
| 142 | expect(e.querySelector('div.month > span:nth-child(2)').firstChild.data).toEqual('January'); |
| 143 | |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 144 | }); |
| 145 | }); |
| 146 | }); |