datatables.net-datetime 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ describe('dateTime - api - valFormat() Luxon', function () {
2
+ dt.libs({
3
+ js: ['jquery', 'datatables', 'luxon', 'datetime'],
4
+ css: ['datatables', 'datetime']
5
+ });
6
+
7
+ let el;
8
+
9
+ function pad(num) {
10
+ return num < 10 ? '0' + num : num;
11
+ }
12
+
13
+ // TK COLIN make this a generic function somewhere as repeated
14
+ function format(d) {
15
+ return d.getFullYear() + '-' + pad(1 + d.getMonth()) + '-' + pad(d.getDate());
16
+ }
17
+
18
+ let today = format(new Date());
19
+
20
+ describe('Check the defaults', function () {
21
+ dt.html('input');
22
+ it('Ensure its a function', function () {
23
+ DateTime.use(window.luxon);
24
+ el = new DateTime(document.getElementById('test'));
25
+ expect(typeof el.valFormat).toBe('function');
26
+ });
27
+ it('Getter returns null if no date set', function () {
28
+ expect(el.valFormat('yyyy-MM-dd')).toBe(null);
29
+ });
30
+ it('Setter returns an API instance', function () {
31
+ expect(el.valFormat('yyyy-MM-dd', today) instanceof DateTime).toBe(true);
32
+ });
33
+ it('Getter returns a string when date set', function () {
34
+ expect(el.valFormat('yyyy-MM-dd')).toBe(today);
35
+ });
36
+ });
37
+
38
+ describe('Functional tests', function () {
39
+ dt.html('input');
40
+ it('Write a formatted value', function () {
41
+ el = new DateTime(document.getElementById('value'));
42
+ el.valFormat('MM-dd-yyyy', '01-18-2023');
43
+ expect(format(el.val())).toBe('2023-01-18');
44
+ });
45
+
46
+ it('Write a complicated formatted value', function () {
47
+ el.valFormat('EEEE d MMMM yyyy', 'Friday 14 October 2011');
48
+ expect(format(el.val())).toBe('2011-10-14');
49
+ });
50
+
51
+ it('Read to a format', function () {
52
+ let res = el.valFormat('M-d-yy');
53
+ expect(res).toBe('10-14-11');
54
+ });
55
+
56
+ it('Read to a complicated format', function () {
57
+ let res = el.valFormat('EEE d MMM yy');
58
+ expect(res).toBe('Fri 14 Oct 11');
59
+ });
60
+ });
61
+
62
+ describe('With a format', function () {
63
+ dt.html('input');
64
+
65
+ it('Write a standard value', function () {
66
+ el = new DateTime(document.getElementById('value'), {
67
+ format: 'EEEE d MMMM yyyy'
68
+ });
69
+ el.val('Friday 14 October 2011');
70
+ expect(document.getElementById('value').value).toBe('Friday 14 October 2011');
71
+ });
72
+
73
+ it('Write a formatted value', function () {
74
+ el.valFormat('yy-MM-dd', '23-01-19');
75
+ expect(document.getElementById('value').value).toBe('Thursday 19 January 2023');
76
+ });
77
+
78
+ it('Read to a format', function () {
79
+ let res = el.valFormat('M-d-yy');
80
+ expect(res).toBe('1-19-23');
81
+ });
82
+ });
83
+ });
@@ -0,0 +1,83 @@
1
+ describe('dateTime - api - valFormat() Moment', function () {
2
+ dt.libs({
3
+ js: ['jquery', 'datatables', 'moment', 'datetime'],
4
+ css: ['datatables', 'datetime']
5
+ });
6
+
7
+ let el;
8
+
9
+ function pad(num) {
10
+ return num < 10 ? '0' + num : num;
11
+ }
12
+
13
+ // TK COLIN make this a generic function somewhere as repeated
14
+ function format(d) {
15
+ return d.getFullYear() + '-' + pad(1 + d.getMonth()) + '-' + pad(d.getDate());
16
+ }
17
+
18
+ let today = format(new Date());
19
+
20
+ describe('Check the defaults', function () {
21
+ dt.html('input');
22
+ it('Ensure its a function', function () {
23
+ DateTime.use(window.moment);
24
+ el = new DateTime(document.getElementById('test'));
25
+ expect(typeof el.valFormat).toBe('function');
26
+ });
27
+ it('Getter returns null if no date set', function () {
28
+ expect(el.valFormat('YYYY-MM-DD')).toBe(null);
29
+ });
30
+ it('Setter returns an API instance', function () {
31
+ expect(el.valFormat('YYYY-MM-DD', today) instanceof DateTime).toBe(true);
32
+ });
33
+ it('Getter returns a string when date set', function () {
34
+ expect(el.valFormat('YYYY-MM-DD')).toBe(today);
35
+ });
36
+ });
37
+
38
+ describe('Functional tests', function () {
39
+ dt.html('input');
40
+ it('Write a formatted value', function () {
41
+ el = new DateTime(document.getElementById('value'));
42
+ el.valFormat('MM-DD-YYYY', '01-18-2023');
43
+ expect(format(el.val())).toBe('2023-01-18');
44
+ });
45
+
46
+ it('Write a complicated formatted value', function () {
47
+ el.valFormat('dddd D MMMM YYYY', 'Friday 14 October 2011');
48
+ expect(format(el.val())).toBe('2011-10-14');
49
+ });
50
+
51
+ it('Read to a format', function () {
52
+ let res = el.valFormat('M-D-YY');
53
+ expect(res).toBe('10-14-11');
54
+ });
55
+
56
+ it('Read to a complicated format', function () {
57
+ let res = el.valFormat('ddd D MMM YY');
58
+ expect(res).toBe('Fri 14 Oct 11');
59
+ });
60
+ });
61
+
62
+ describe('With a format', function () {
63
+ dt.html('input');
64
+
65
+ it('Write a standard value', function () {
66
+ el = new DateTime(document.getElementById('value'), {
67
+ format: 'dddd D MMMM YYYY'
68
+ });
69
+ el.val('Friday 14 October 2011');
70
+ expect(document.getElementById('value').value).toBe('Friday 14 October 2011');
71
+ });
72
+
73
+ it('Write a formatted value', function () {
74
+ el.valFormat('YY-MM-DD', '23-01-19');
75
+ expect(document.getElementById('value').value).toBe('Thursday 19 January 2023');
76
+ });
77
+
78
+ it('Read to a format', function () {
79
+ let res = el.valFormat('M-D-YY');
80
+ expect(res).toBe('1-19-23');
81
+ });
82
+ });
83
+ });
Binary file