datatables.net-datetime 1.0.1 → 1.1.2
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.
- package/css/{dateTime.scss → dataTables.dateTime.scss} +15 -0
- package/dist/dataTables.dateTime.css +218 -0
- package/{js/dateTime.js → dist/dataTables.dateTime.js} +191 -51
- package/dist/dataTables.dateTime.min.css +1 -0
- package/dist/dataTables.dateTime.min.js +43 -0
- package/docs/api/DateTime.use().xml +32 -0
- package/docs/api/destroy().xml +28 -0
- package/docs/api/errorMsg().xml +52 -0
- package/docs/api/hide().xml +36 -0
- package/docs/api/max().xml +35 -0
- package/docs/api/min().xml +35 -0
- package/docs/api/owns().xml +30 -0
- package/docs/api/val().xml +44 -0
- package/docs/option/buttons.clear.xml +27 -0
- package/docs/option/buttons.today.xml +29 -0
- package/docs/option/buttons.xml +28 -0
- package/docs/option/disableDays.xml +45 -0
- package/docs/option/firstDay.xml +34 -0
- package/docs/option/format.xml +31 -0
- package/docs/option/hoursAvailable.xml +36 -0
- package/docs/option/i18n.amPm.xml +32 -0
- package/docs/option/i18n.clear.xml +28 -0
- package/docs/option/i18n.hours.xml +33 -0
- package/docs/option/i18n.minutes.xml +33 -0
- package/docs/option/i18n.months.xml +32 -0
- package/docs/option/i18n.next.xml +32 -0
- package/docs/option/i18n.previous.xml +32 -0
- package/docs/option/i18n.seconds.xml +33 -0
- package/docs/option/i18n.today.xml +28 -0
- package/docs/option/i18n.unknown.xml +32 -0
- package/docs/option/i18n.weekdays.xml +32 -0
- package/docs/option/i18n.xml +37 -0
- package/docs/option/locale.xml +31 -0
- package/docs/option/maxDate.xml +51 -0
- package/docs/option/minDate.xml +52 -0
- package/docs/option/minutesAvailable.xml +36 -0
- package/docs/option/onChange.xml +38 -0
- package/docs/option/secondsAvailable.xml +36 -0
- package/docs/option/showWeekNumber.xml +30 -0
- package/docs/option/yearRange.xml +35 -0
- package/examples/index.xml +12 -0
- package/examples/initialisation/buttons.xml +38 -0
- package/examples/initialisation/datetime.xml +30 -0
- package/examples/initialisation/dayjs.xml +34 -0
- package/examples/initialisation/hidden.xml +28 -0
- package/examples/initialisation/i18n.xml +37 -0
- package/examples/initialisation/index.xml +12 -0
- package/examples/initialisation/jquery.xml +28 -0
- package/examples/initialisation/luxon.xml +29 -0
- package/examples/initialisation/moment.xml +29 -0
- package/examples/initialisation/simple.xml +30 -0
- package/examples/integration/datatables.xml +74 -0
- package/examples/integration/form.xml +65 -0
- package/gulpfile.js +3 -3
- package/js/{dateTime.d.ts → dataTables.dateTime.d.ts} +0 -1
- package/{dist/dateTime.js → js/dataTables.dateTime.js} +191 -51
- package/license.txt +9 -0
- package/make.sh +50 -0
- package/nuget.nuspec +20 -0
- package/package.json +6 -4
- package/readme.md +3 -1
- package/test/api/dateTime.destroy().js +49 -0
- package/test/api/dateTime.errorMsg().js +52 -0
- package/test/api/dateTime.hide().js +49 -0
- package/test/api/dateTime.max().js +86 -0
- package/test/api/dateTime.min().js +85 -0
- package/test/api/dateTime.owns().js +53 -0
- package/test/api/dateTime.val().js +70 -0
- package/test/options/dateTime.YearRange.js +51 -0
- package/test/options/dateTime.disableDays.js +46 -0
- package/test/options/dateTime.firstDay.js +33 -0
- package/test/options/dateTime.format.js +85 -0
- package/test/options/dateTime.i18n.amPm.js +35 -0
- package/test/options/dateTime.i18n.hours.js +33 -0
- package/test/options/dateTime.i18n.minutes.js +33 -0
- package/test/options/dateTime.i18n.months.js +33 -0
- package/test/options/dateTime.i18n.next.js +31 -0
- package/test/options/dateTime.i18n.previous.js +31 -0
- package/test/options/dateTime.i18n.seconds.js +33 -0
- package/test/options/dateTime.i18n.unknown.js +33 -0
- package/test/options/dateTime.i18n.weekdays.js +30 -0
- package/test/options/dateTime.init.js +54 -0
- package/test/options/dateTime.maxDate.js +66 -0
- package/test/options/dateTime.minDate.js +66 -0
- package/test/options/dateTime.onChange.js +130 -0
- package/test/options/dateTime.showWeekNumber.js +36 -0
- package/dist/dateTime.css +0 -168
- package/examples/basic.html +0 -26
- package/examples/datetime.html +0 -29
- package/examples/dayjs.html +0 -32
- package/examples/hidden.html +0 -26
- package/examples/jquery.html +0 -26
- package/examples/moment.html +0 -29
- package/examples/right.html +0 -39
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
describe('dateTime - api - errorMsg()', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
let el;
|
|
8
|
+
|
|
9
|
+
describe('Check the defaults', function () {
|
|
10
|
+
dt.html('input');
|
|
11
|
+
it('Ensure its a function', function () {
|
|
12
|
+
el = new DateTime(document.getElementById('test'));
|
|
13
|
+
expect(typeof el.errorMsg).toBe('function');
|
|
14
|
+
});
|
|
15
|
+
it('Clearer returns an API instance', function () {
|
|
16
|
+
expect(el.errorMsg() instanceof DateTime).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it('Setter returns an API instance', function () {
|
|
19
|
+
expect(el.errorMsg('test') instanceof DateTime).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('Functional tests', function () {
|
|
24
|
+
dt.html('input');
|
|
25
|
+
it('When picker closed', function () {
|
|
26
|
+
el = new DateTime(document.getElementById('test'), {});
|
|
27
|
+
el.errorMsg('test');
|
|
28
|
+
|
|
29
|
+
expect($('.dt-datetime-error').length).toBe(0);
|
|
30
|
+
});
|
|
31
|
+
it('... displayed when opened', function () {
|
|
32
|
+
$('#test').click();
|
|
33
|
+
expect($('.dt-datetime-error').length).toBe(1);
|
|
34
|
+
expect($('.dt-datetime-error').text()).toBe('test');
|
|
35
|
+
});
|
|
36
|
+
it('... changed when opened', function () {
|
|
37
|
+
el.errorMsg('unittest');
|
|
38
|
+
expect($('.dt-datetime-error').length).toBe(1);
|
|
39
|
+
expect($('.dt-datetime-error').text()).toBe('unittest');
|
|
40
|
+
});
|
|
41
|
+
it('... changed when opened', function () {
|
|
42
|
+
el.errorMsg('this is a long string for testing purposes to see how it looks');
|
|
43
|
+
expect($('.dt-datetime-error').length).toBe(1);
|
|
44
|
+
expect($('.dt-datetime-error').text()).toBe('this is a long string for testing purposes to see how it looks');
|
|
45
|
+
});
|
|
46
|
+
it('... cleared when opened', function () {
|
|
47
|
+
el.errorMsg();
|
|
48
|
+
expect($('.dt-datetime-error').length).toBe(1);
|
|
49
|
+
expect($('.dt-datetime-error').text()).toBe('');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
describe('dateTime - api - hide()', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
let el;
|
|
8
|
+
|
|
9
|
+
describe('Check the defaults', function () {
|
|
10
|
+
dt.html('input');
|
|
11
|
+
it('Ensure its a function', function () {
|
|
12
|
+
el = new DateTime(document.getElementById('test'));
|
|
13
|
+
expect(typeof el.hide).toBe('function');
|
|
14
|
+
});
|
|
15
|
+
it('Returns an API instance', function () {
|
|
16
|
+
expect(el.hide('test') instanceof DateTime).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('Functional tests', function () {
|
|
21
|
+
dt.html('input');
|
|
22
|
+
it('Hide when picker closed', function () {
|
|
23
|
+
el = new DateTime(document.getElementById('test'), {});
|
|
24
|
+
el.hide();
|
|
25
|
+
|
|
26
|
+
expect($('.dt-datetime').length).toBe(0);
|
|
27
|
+
});
|
|
28
|
+
it('... date picker can be opened', function () {
|
|
29
|
+
$('#test').click();
|
|
30
|
+
expect($('.dt-datetime').length).toBe(1);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
dt.html('input');
|
|
34
|
+
it('Hide when picker open', function () {
|
|
35
|
+
el = new DateTime(document.getElementById('test'), {});
|
|
36
|
+
$('#test').click();
|
|
37
|
+
|
|
38
|
+
expect($('.dt-datetime').length).toBe(1);
|
|
39
|
+
|
|
40
|
+
el.hide();
|
|
41
|
+
|
|
42
|
+
expect($('.dt-datetime').length).toBe(0);
|
|
43
|
+
});
|
|
44
|
+
it('... date picker can be opened', function () {
|
|
45
|
+
$('#test').click();
|
|
46
|
+
expect($('.dt-datetime').length).toBe(1);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
describe('dateTime - api - max()', 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
|
+
function getToday() {
|
|
14
|
+
let d = new Date();
|
|
15
|
+
return d.getFullYear() + '-' + pad(1 + d.getMonth()) + '-' + pad(d.getDate());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getMidMonth() {
|
|
19
|
+
let d = new Date();
|
|
20
|
+
return d.getFullYear() + '-' + pad(1 + d.getMonth()) + '-' + '15';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function get20YearsAgo() {
|
|
24
|
+
let d = new Date();
|
|
25
|
+
return d.getFullYear() - 20 + '-' + pad(1 + d.getMonth()) + '-' + '15';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let thisYear = new Date().getFullYear().toString();
|
|
29
|
+
|
|
30
|
+
describe('Check the defaults', function () {
|
|
31
|
+
dt.html('input');
|
|
32
|
+
it('Ensure its a function', function () {
|
|
33
|
+
el = new DateTime(document.getElementById('test'));
|
|
34
|
+
expect(typeof el.max).toBe('function');
|
|
35
|
+
});
|
|
36
|
+
it('Setting with a string returns an API instance', function () {
|
|
37
|
+
expect(el.max(getToday()) instanceof DateTime).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
it('Setter returns an API instance', function () {
|
|
40
|
+
expect(el.max(new Date(getToday())) instanceof DateTime).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('Functional tests', function () {
|
|
45
|
+
dt.html('input');
|
|
46
|
+
it('String - When picker closed', function () {
|
|
47
|
+
el = new DateTime(document.getElementById('test'), {});
|
|
48
|
+
el.max(getMidMonth());
|
|
49
|
+
expect($('.dt-datetime-error').length).toBe(0);
|
|
50
|
+
});
|
|
51
|
+
it('... applied when opened', function () {
|
|
52
|
+
$('#test').click();
|
|
53
|
+
expect($('select.dt-datetime-year option').length).toBe(26);
|
|
54
|
+
expect($('select.dt-datetime-year option:last-child').val()).toBe(thisYear);
|
|
55
|
+
expect($('tbody tr:eq(1) td:eq(0)').hasClass('disabled')).toBe(false);
|
|
56
|
+
expect($('tbody tr:eq(3) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
it('... set when opened', function () {
|
|
59
|
+
el.max(get20YearsAgo());
|
|
60
|
+
expect($('select.dt-datetime-year option').length).toBe(6);
|
|
61
|
+
expect($('tbody tr:eq(1) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
62
|
+
expect($('tbody tr:eq(3) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
dt.html('input');
|
|
66
|
+
it('Date - When picker closed', function () {
|
|
67
|
+
el = new DateTime(document.getElementById('test'), {});
|
|
68
|
+
el.max(new Date(getMidMonth()));
|
|
69
|
+
expect($('.dt-datetime-error').length).toBe(0);
|
|
70
|
+
});
|
|
71
|
+
it('... applied when opened', function () {
|
|
72
|
+
$('#test').click();
|
|
73
|
+
expect($('select.dt-datetime-year option').length).toBe(26);
|
|
74
|
+
expect($('select.dt-datetime-year option:last-child').val()).toBe(thisYear);
|
|
75
|
+
expect($('tbody tr:eq(1) td:eq(0)').hasClass('disabled')).toBe(false);
|
|
76
|
+
expect($('tbody tr:eq(3) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
it('... set when opened', function () {
|
|
79
|
+
el.max(new Date(get20YearsAgo()));
|
|
80
|
+
expect($('select.dt-datetime-year option').length).toBe(6);
|
|
81
|
+
expect($('tbody tr:eq(1) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
82
|
+
expect($('tbody tr:eq(3) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
describe('dateTime - api - min()', 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
|
+
function getToday() {
|
|
14
|
+
let d = new Date();
|
|
15
|
+
return d.getFullYear() + '-' + pad(1 + d.getMonth()) + '-' + pad(d.getDate());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getMidMonth() {
|
|
19
|
+
let d = new Date();
|
|
20
|
+
return d.getFullYear() + '-' + pad(1 + d.getMonth()) + '-' + '15';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function get20YearsAhead() {
|
|
24
|
+
let d = new Date();
|
|
25
|
+
return d.getFullYear() + 20 + '-' + pad(1 + d.getMonth()) + '-' + '15';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let thisYear = new Date().getFullYear().toString();
|
|
29
|
+
|
|
30
|
+
describe('Check the defaults', function () {
|
|
31
|
+
dt.html('input');
|
|
32
|
+
it('Ensure its a function', function () {
|
|
33
|
+
el = new DateTime(document.getElementById('test'));
|
|
34
|
+
expect(typeof el.min).toBe('function');
|
|
35
|
+
});
|
|
36
|
+
it('Setting with a string returns an API instance', function () {
|
|
37
|
+
expect(el.min(getToday()) instanceof DateTime).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
it('Setter returns an API instance', function () {
|
|
40
|
+
expect(el.min(new Date(getToday())) instanceof DateTime).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('Functional tests', function () {
|
|
45
|
+
dt.html('input');
|
|
46
|
+
it('String - When picker closed', function () {
|
|
47
|
+
el = new DateTime(document.getElementById('test'), {});
|
|
48
|
+
el.min(getMidMonth());
|
|
49
|
+
expect($('.dt-datetime-error').length).toBe(0);
|
|
50
|
+
});
|
|
51
|
+
it('... applied when opened', function () {
|
|
52
|
+
$('#test').click();
|
|
53
|
+
expect($('select.dt-datetime-year option').length).toBe(26);
|
|
54
|
+
expect($('select.dt-datetime-year option:first-child').val()).toBe(thisYear);
|
|
55
|
+
expect($('tbody tr:eq(1) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
56
|
+
expect($('tbody tr:eq(3) td:eq(0)').hasClass('disabled')).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
it('... set when opened', function () {
|
|
59
|
+
el.min(get20YearsAhead());
|
|
60
|
+
expect($('select.dt-datetime-year option').length).toBe(6);
|
|
61
|
+
expect($('tbody tr:eq(1) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
62
|
+
expect($('tbody tr:eq(3) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
dt.html('input');
|
|
66
|
+
it('Date - When picker closed', function () {
|
|
67
|
+
el = new DateTime(document.getElementById('test'), {});
|
|
68
|
+
el.min(new Date(getMidMonth()));
|
|
69
|
+
expect($('.dt-datetime-error').length).toBe(0);
|
|
70
|
+
});
|
|
71
|
+
it('... applied when opened', function () {
|
|
72
|
+
$('#test').click();
|
|
73
|
+
expect($('select.dt-datetime-year option').length).toBe(26);
|
|
74
|
+
expect($('select.dt-datetime-year option:first-child').val()).toBe(thisYear);
|
|
75
|
+
expect($('tbody tr:eq(1) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
76
|
+
expect($('tbody tr:eq(3) td:eq(0)').hasClass('disabled')).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
it('... set when opened', function () {
|
|
79
|
+
el.min(new Date(get20YearsAhead()));
|
|
80
|
+
expect($('select.dt-datetime-year option').length).toBe(6);
|
|
81
|
+
expect($('tbody tr:eq(1) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
82
|
+
expect($('tbody tr:eq(3) td:eq(0)').hasClass('disabled')).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
describe('dateTime - api - owns()', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
let el, el2;
|
|
8
|
+
|
|
9
|
+
describe('Check the defaults', function () {
|
|
10
|
+
dt.html('input');
|
|
11
|
+
it('Ensure its a function', function () {
|
|
12
|
+
el = new DateTime(document.getElementById('test'));
|
|
13
|
+
expect(typeof el.owns).toBe('function');
|
|
14
|
+
});
|
|
15
|
+
it('Returns a boolean', function () {
|
|
16
|
+
expect(typeof el.owns()).toBe('boolean');
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('Functional tests', function () {
|
|
21
|
+
dt.html('input');
|
|
22
|
+
it('When picker closed', function () {
|
|
23
|
+
el = new DateTime(document.getElementById('test'), {format: 'YYYY-MM-DD HH:mm:ss'});
|
|
24
|
+
expect(el.owns('')).toBe(false);
|
|
25
|
+
expect(el.owns($('#test'))).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
it('... when opened', function () {
|
|
28
|
+
$('#test').click();
|
|
29
|
+
expect(el.owns('')).toBe(false);
|
|
30
|
+
expect(el.owns($('#test'))).toBe(false);
|
|
31
|
+
expect(el.owns($('.dt-datetime-month'))).toBe(true);
|
|
32
|
+
expect(el.owns($('.dt-datetime-minutes'))).toBe(true);
|
|
33
|
+
expect(el.owns($('.now'))).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('Initialise second element', function () {
|
|
37
|
+
el2 = new DateTime(document.getElementById('value'));
|
|
38
|
+
|
|
39
|
+
expect(el2.owns('')).toBe(false);
|
|
40
|
+
expect(el2.owns($('#test'))).toBe(false);
|
|
41
|
+
expect(el2.owns($('.dt-datetime-month'))).toBe(false);
|
|
42
|
+
expect(el2.owns($('.dt-datetime-minutes'))).toBe(false);
|
|
43
|
+
expect(el2.owns($('.now'))).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
it('... first still owns', function () {
|
|
46
|
+
expect(el.owns('')).toBe(false);
|
|
47
|
+
expect(el.owns($('#test'))).toBe(false);
|
|
48
|
+
expect(el.owns($('.dt-datetime-month'))).toBe(true);
|
|
49
|
+
expect(el.owns($('.dt-datetime-minutes'))).toBe(true);
|
|
50
|
+
expect(el.owns($('.now'))).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
describe('dateTime - api - val()', 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
|
+
el = new DateTime(document.getElementById('test'));
|
|
24
|
+
expect(typeof el.min).toBe('function');
|
|
25
|
+
});
|
|
26
|
+
it('Getter returns null if no date set', function () {
|
|
27
|
+
expect(el.val()).toBe(null);
|
|
28
|
+
});
|
|
29
|
+
it('Setter returns an API instance', function () {
|
|
30
|
+
expect(el.val(today) instanceof DateTime).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
it('Getter returns an Date instance', function () {
|
|
33
|
+
expect(el.val() instanceof Date).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('Functional tests', function () {
|
|
38
|
+
dt.html('input');
|
|
39
|
+
it('Get value when set in element', function () {
|
|
40
|
+
el = new DateTime(document.getElementById('value'));
|
|
41
|
+
expect(format(el.val())).toBe('2021-10-20');
|
|
42
|
+
});
|
|
43
|
+
it('... applied when opened', function () {
|
|
44
|
+
$('#value').click();
|
|
45
|
+
expect(format(el.val())).toBe('2021-10-20');
|
|
46
|
+
});
|
|
47
|
+
it('... set when opened', function () {
|
|
48
|
+
el.val(today);
|
|
49
|
+
expect(format(el.val())).toBe(today);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
dt.html('input');
|
|
53
|
+
it('Set time element', function () {
|
|
54
|
+
el = new DateTime(document.getElementById('test'), {format: 'HH:mm'});
|
|
55
|
+
el.val('11:22');
|
|
56
|
+
expect(el.val().getHours()).toBe(11);
|
|
57
|
+
expect(el.val().getMinutes()).toBe(22);
|
|
58
|
+
});
|
|
59
|
+
it('... set when opened', function () {
|
|
60
|
+
$('#test').click();
|
|
61
|
+
el.val('10:33');
|
|
62
|
+
expect(el.val().getHours()).toBe(10);
|
|
63
|
+
expect(el.val().getMinutes()).toBe(33);
|
|
64
|
+
});
|
|
65
|
+
it('... updates display', function () {
|
|
66
|
+
expect($('.dt-datetime-hours .selected').text()).toBe('10');
|
|
67
|
+
expect($('.dt-datetime-minutes .selected').text()).toBe('33');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
describe('dateTime - options - yearRange', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
function pad(num) {
|
|
8
|
+
return num < 10 ? '0' + num : num;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getToday() {
|
|
12
|
+
let d = new Date();
|
|
13
|
+
return d.getFullYear() + '-' + pad(1 + d.getMonth()) + '-' + pad(d.getDate());
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('Functional tests', function () {
|
|
17
|
+
let thisYear = new Date().getFullYear();
|
|
18
|
+
|
|
19
|
+
dt.html('input');
|
|
20
|
+
it('Default', function () {
|
|
21
|
+
new DateTime(document.getElementById('test'), {});
|
|
22
|
+
$('#test').click();
|
|
23
|
+
expect($('select.dt-datetime-year option').length).toBe(51);
|
|
24
|
+
expect($('select.dt-datetime-year option:first-child').val()).toBe((thisYear - 25).toString());
|
|
25
|
+
expect($('select.dt-datetime-year option:last-child').val()).toBe((thisYear + 25).toString());
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
dt.html('input');
|
|
29
|
+
it('Custom number', function () {
|
|
30
|
+
new DateTime(document.getElementById('test'), {
|
|
31
|
+
yearRange: 5
|
|
32
|
+
});
|
|
33
|
+
$('#test').click();
|
|
34
|
+
expect($('select.dt-datetime-year option').length).toBe(11);
|
|
35
|
+
expect($('select.dt-datetime-year option:first-child').val()).toBe((thisYear - 5).toString());
|
|
36
|
+
expect($('select.dt-datetime-year option:last-child').val()).toBe((thisYear + 5).toString());
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
dt.html('input');
|
|
40
|
+
it('When used with maxDate', function () {
|
|
41
|
+
new DateTime(document.getElementById('test'), {
|
|
42
|
+
yearRange: 5,
|
|
43
|
+
maxDate: getToday()
|
|
44
|
+
});
|
|
45
|
+
$('#test').click();
|
|
46
|
+
expect($('select.dt-datetime-year option').length).toBe(6);
|
|
47
|
+
expect($('select.dt-datetime-year option:first-child').val()).toBe((thisYear - 5).toString());
|
|
48
|
+
expect($('select.dt-datetime-year option:last-child').val()).toBe(thisYear.toString());
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
describe('dateTime - options - disableDays', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
let table;
|
|
8
|
+
|
|
9
|
+
function checkDays(expected) {
|
|
10
|
+
for (i in expected) {
|
|
11
|
+
expect($('.dt-datetime-date tbody tr:eq(1) td:eq(' + i + ')').hasClass('disabled')).toBe(expected[i]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('Functional tests', function () {
|
|
16
|
+
dt.html('input');
|
|
17
|
+
it('Default - all enabled', function () {
|
|
18
|
+
new DateTime(document.getElementById('value'), {});
|
|
19
|
+
$('#value').click();
|
|
20
|
+
checkDays([false, false, false, false, false, false, false]);
|
|
21
|
+
expect($('.dt-datetime-date tbody td.disabled').length).toBe(0);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
dt.html('input');
|
|
25
|
+
it('Array', function () {
|
|
26
|
+
new DateTime(document.getElementById('value'), {
|
|
27
|
+
disableDays: [1, 2]
|
|
28
|
+
});
|
|
29
|
+
$('#value').click();
|
|
30
|
+
checkDays([true, true, false, false, false, false, false]);
|
|
31
|
+
expect($('.dt-datetime-date tbody td.disabled').length).toBeGreaterThan(7);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
dt.html('input');
|
|
35
|
+
it('Function', function () {
|
|
36
|
+
new DateTime(document.getElementById('value'), {
|
|
37
|
+
disableDays: function (day) {
|
|
38
|
+
return day.toString().includes('Oct 0')? true : false;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
$('#value').click();
|
|
42
|
+
checkDays([true, true, true, true, true, true, false]);
|
|
43
|
+
expect($('.dt-datetime-date tbody td.disabled').length).toBe(9);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
describe('dateTime - options - firstDay', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
describe('Functional tests', function () {
|
|
8
|
+
dt.html('input');
|
|
9
|
+
it('Default', function () {
|
|
10
|
+
new DateTime(document.getElementById('test'), {});
|
|
11
|
+
$('#test').click();
|
|
12
|
+
expect($('.dt-datetime-date thead th').text()).toBe('MonTueWedThuFriSatSun');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
dt.html('input');
|
|
16
|
+
it('Mid-week', function () {
|
|
17
|
+
new DateTime(document.getElementById('test'), {firstDay: 3});
|
|
18
|
+
|
|
19
|
+
expect($('.dt-datetime').length).toBe(0);
|
|
20
|
+
$('#test').click();
|
|
21
|
+
expect($('.dt-datetime-date thead th').text()).toBe('WedThuFriSatSunMonTue');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
dt.html('input');
|
|
25
|
+
it('end of week', function () {
|
|
26
|
+
new DateTime(document.getElementById('test'), {firstDay: 6});
|
|
27
|
+
|
|
28
|
+
expect($('.dt-datetime').length).toBe(0);
|
|
29
|
+
$('#test').click();
|
|
30
|
+
expect($('.dt-datetime-date thead th').text()).toBe('SatSunMonTueWedThuFri');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
describe('dateTime - options - format', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
function pad(num) {
|
|
8
|
+
return num < 10 ? '0' + num : num;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getToday(rev = false) {
|
|
12
|
+
let d = new Date();
|
|
13
|
+
return rev
|
|
14
|
+
? pad(d.getDate()) + '-' + pad(1 + d.getMonth()) + '-' + d.getFullYear()
|
|
15
|
+
: d.getFullYear() + '-' + pad(1 + d.getMonth()) + '-' + pad(d.getDate());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getNow() {
|
|
19
|
+
let d = new Date();
|
|
20
|
+
return (
|
|
21
|
+
d.getFullYear() +
|
|
22
|
+
'-' +
|
|
23
|
+
pad(1 + d.getMonth()) +
|
|
24
|
+
'-' +
|
|
25
|
+
pad(d.getDate()) +
|
|
26
|
+
' ' +
|
|
27
|
+
pad(d.getUTCHours()) +
|
|
28
|
+
':' +
|
|
29
|
+
pad(d.getUTCMinutes()) +
|
|
30
|
+
':' +
|
|
31
|
+
pad(d.getUTCSeconds())
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let time1, time2;
|
|
36
|
+
|
|
37
|
+
describe('Functional tests', function () {
|
|
38
|
+
dt.html('input');
|
|
39
|
+
it('Default - no time', function () {
|
|
40
|
+
new DateTime(document.getElementById('test'), {});
|
|
41
|
+
$('#test').click();
|
|
42
|
+
expect($('.dt-datetime-time').is(':visible')).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('... confirm setting', function () {
|
|
45
|
+
$('.now button span').click();
|
|
46
|
+
expect($('#test').val()).toBe(getToday());
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
dt.html('input');
|
|
50
|
+
it('Reverse', function () {
|
|
51
|
+
new DateTime(document.getElementById('test'), {format: 'DD-MM-YYYY'});
|
|
52
|
+
$('#test').click();
|
|
53
|
+
$('.now button span').click();
|
|
54
|
+
expect($('#test').val()).toBe(getToday(true));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
dt.html('input');
|
|
58
|
+
it('Only year', function () {
|
|
59
|
+
new DateTime(document.getElementById('test'), {format: 'YYYY'});
|
|
60
|
+
$('#test').click();
|
|
61
|
+
$('.now button span').click();
|
|
62
|
+
expect($('#test').val()).toBe(new Date().getFullYear().toString());
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
dt.html('input');
|
|
66
|
+
it('With time', function () {
|
|
67
|
+
new DateTime(document.getElementById('test'), {format: 'YYYY-MM-DD HH:mm:ss'});
|
|
68
|
+
time1 = getNow();
|
|
69
|
+
$('#test').click();
|
|
70
|
+
expect($('.dt-datetime-time').is(':visible')).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
it('... confirm setting', function () {
|
|
73
|
+
// get two times in case it flips over
|
|
74
|
+
$('.now button span').click();
|
|
75
|
+
time2 = getNow();
|
|
76
|
+
let val = $('#test').val();
|
|
77
|
+
|
|
78
|
+
console.log(time1);
|
|
79
|
+
console.log(time2);
|
|
80
|
+
console.log(val);
|
|
81
|
+
|
|
82
|
+
expect(val == time1 || val == time2).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
describe('dateTime - i18n - amPm', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
describe('Functional tests', function () {
|
|
8
|
+
dt.html('input');
|
|
9
|
+
it('Default', function () {
|
|
10
|
+
let el = new DateTime(document.getElementById('test'), {
|
|
11
|
+
format: 'HH:mm A'
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
$('#test').click();
|
|
15
|
+
|
|
16
|
+
expect($('.dt-datetime-hours tbody tr:first-child td:last-child').text()).toBe('am');
|
|
17
|
+
expect($('.dt-datetime-hours tbody tr:last-child td:last-child').text()).toBe('pm');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
dt.html('input');
|
|
21
|
+
it('Change', function () {
|
|
22
|
+
let el = new DateTime(document.getElementById('test'), {
|
|
23
|
+
format: 'HH:mm A',
|
|
24
|
+
i18n: {
|
|
25
|
+
amPm: ['before', 'after']
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
$('#test').click();
|
|
30
|
+
|
|
31
|
+
expect($('.dt-datetime-hours tbody tr:first-child td:last-child').text()).toBe('before');
|
|
32
|
+
expect($('.dt-datetime-hours tbody tr:last-child td:last-child').text()).toBe('after');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
describe('dateTime - i18n - hours', function () {
|
|
2
|
+
dt.libs({
|
|
3
|
+
js: ['jquery', 'datatables', 'moment', 'datetime'],
|
|
4
|
+
css: ['datatables', 'datetime']
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
describe('Functional tests', function () {
|
|
8
|
+
dt.html('input');
|
|
9
|
+
it('Default', function () {
|
|
10
|
+
let el = new DateTime(document.getElementById('test'), {
|
|
11
|
+
format: 'HH:mm'
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
$('#test').click();
|
|
15
|
+
|
|
16
|
+
expect($('.dt-datetime-hours thead').text()).toBe('Hour');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
dt.html('input');
|
|
20
|
+
it('Change', function () {
|
|
21
|
+
let el = new DateTime(document.getElementById('test'), {
|
|
22
|
+
format: 'HH:mm',
|
|
23
|
+
i18n: {
|
|
24
|
+
hours: 'test'
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
$('#test').click();
|
|
29
|
+
|
|
30
|
+
expect($('.dt-datetime-hours thead').text()).toBe('test');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|