blob: bcab2259846bcda3bb3c9646245fde9c9a73bdf8 [file] [log] [blame]
Nils Diewalda79b2682015-05-18 18:34:06 +00001define(['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
49 var e = dp.show(9998, 2);
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
62 var e = dp.show(2, 2);
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();
81 var e = dp.show(2013, 6);
82 });
83 });
84});