@mui/x-date-pickers 6.1.0 → 6.2.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.
- package/AdapterDayjs/AdapterDayjs.d.ts +114 -0
- package/AdapterDayjs/AdapterDayjs.js +387 -0
- package/AdapterDayjs/index.d.ts +1 -28
- package/AdapterDayjs/index.js +1 -102
- package/CHANGELOG.md +53 -1
- package/DateCalendar/DateCalendar.types.d.ts +1 -1
- package/DateCalendar/DayCalendar.d.ts +1 -1
- package/DateField/DateField.js +6 -0
- package/DateField/useDateField.js +3 -1
- package/DatePicker/DatePicker.js +6 -0
- package/DateTimeField/DateTimeField.js +6 -0
- package/DateTimeField/useDateTimeField.js +3 -1
- package/DateTimePicker/DateTimePicker.js +6 -0
- package/DateTimePicker/shared.js +3 -1
- package/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/MobileDatePicker/MobileDatePicker.js +6 -0
- package/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/MobileTimePicker/MobileTimePicker.js +6 -0
- package/README.md +1 -0
- package/TimeClock/TimeClock.types.d.ts +1 -1
- package/TimeField/TimeField.js +6 -0
- package/TimeField/useTimeField.js +3 -1
- package/TimePicker/TimePicker.js +6 -0
- package/index.js +1 -1
- package/internals/components/PickersModalDialog.d.ts +1 -1
- package/internals/components/PickersPopper.d.ts +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +1 -1
- package/internals/hooks/useField/useField.types.d.ts +6 -0
- package/internals/hooks/useField/useField.utils.d.ts +1 -1
- package/internals/hooks/useField/useField.utils.js +16 -4
- package/internals/hooks/useField/useFieldState.js +3 -2
- package/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +1 -1
- package/internals/hooks/usePicker/index.d.ts +1 -1
- package/internals/hooks/usePicker/usePicker.types.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerValue.d.ts +3 -179
- package/internals/hooks/usePicker/usePickerValue.js +187 -153
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +233 -0
- package/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/internals/hooks/usePicker/usePickerViews.d.ts +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/models/props/basePickerProps.d.ts +6 -0
- package/legacy/AdapterDayjs/AdapterDayjs.js +403 -0
- package/legacy/AdapterDayjs/index.js +1 -119
- package/legacy/DateField/DateField.js +6 -0
- package/legacy/DateField/useDateField.js +3 -1
- package/legacy/DatePicker/DatePicker.js +6 -0
- package/legacy/DateTimeField/DateTimeField.js +6 -0
- package/legacy/DateTimeField/useDateTimeField.js +3 -1
- package/legacy/DateTimePicker/DateTimePicker.js +6 -0
- package/legacy/DateTimePicker/shared.js +3 -1
- package/legacy/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/legacy/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/legacy/MobileDatePicker/MobileDatePicker.js +6 -0
- package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/legacy/MobileTimePicker/MobileTimePicker.js +6 -0
- package/legacy/TimeField/TimeField.js +6 -0
- package/legacy/TimeField/useTimeField.js +3 -1
- package/legacy/TimePicker/TimePicker.js +6 -0
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/legacy/internals/hooks/useField/useField.utils.js +24 -9
- package/legacy/internals/hooks/useField/useFieldState.js +5 -3
- package/legacy/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/legacy/internals/hooks/usePicker/usePickerValue.js +184 -153
- package/legacy/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/legacy/tests/describeGregorianAdapter/index.js +1 -0
- package/legacy/tests/describeGregorianAdapter/testCalculations.js +273 -0
- package/legacy/tests/describeGregorianAdapter/testFormat.js +26 -0
- package/legacy/tests/describeGregorianAdapter/testLocalization.js +15 -0
- package/legacy/tests/describeValidation/describeValidation.js +2 -1
- package/legacy/tests/describeValidation/testMinutesViewValidation.js +201 -0
- package/legacy/tests/describeValue/testPickerActionBar.js +52 -3
- package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/models/adapters.d.ts +21 -20
- package/modern/AdapterDayjs/AdapterDayjs.js +386 -0
- package/modern/AdapterDayjs/index.js +1 -101
- package/modern/DateField/DateField.js +6 -0
- package/modern/DateField/useDateField.js +3 -1
- package/modern/DatePicker/DatePicker.js +6 -0
- package/modern/DateTimeField/DateTimeField.js +6 -0
- package/modern/DateTimeField/useDateTimeField.js +3 -1
- package/modern/DateTimePicker/DateTimePicker.js +6 -0
- package/modern/DateTimePicker/shared.js +3 -1
- package/modern/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/modern/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +6 -0
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/modern/MobileTimePicker/MobileTimePicker.js +6 -0
- package/modern/TimeField/TimeField.js +6 -0
- package/modern/TimeField/useTimeField.js +3 -1
- package/modern/TimePicker/TimePicker.js +6 -0
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/modern/internals/hooks/useField/useField.utils.js +16 -4
- package/modern/internals/hooks/useField/useFieldState.js +3 -2
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/modern/internals/hooks/usePicker/usePickerValue.js +187 -153
- package/modern/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/modern/tests/describeGregorianAdapter/index.js +1 -0
- package/modern/tests/describeGregorianAdapter/testCalculations.js +272 -0
- package/modern/tests/describeGregorianAdapter/testFormat.js +27 -0
- package/modern/tests/describeGregorianAdapter/testLocalization.js +16 -0
- package/modern/tests/describeValidation/describeValidation.js +2 -1
- package/modern/tests/describeValidation/testMinutesViewValidation.js +200 -0
- package/modern/tests/describeValue/testPickerActionBar.js +52 -3
- package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/node/AdapterDayjs/AdapterDayjs.js +395 -0
- package/node/AdapterDayjs/index.js +6 -104
- package/node/DateField/DateField.js +6 -0
- package/node/DateField/useDateField.js +3 -1
- package/node/DatePicker/DatePicker.js +6 -0
- package/node/DateTimeField/DateTimeField.js +6 -0
- package/node/DateTimeField/useDateTimeField.js +3 -1
- package/node/DateTimePicker/DateTimePicker.js +6 -0
- package/node/DateTimePicker/shared.js +3 -1
- package/node/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/node/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/node/MobileDatePicker/MobileDatePicker.js +6 -0
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/node/MobileTimePicker/MobileTimePicker.js +6 -0
- package/node/TimeField/TimeField.js +6 -0
- package/node/TimeField/useTimeField.js +3 -1
- package/node/TimePicker/TimePicker.js +6 -0
- package/node/index.js +1 -1
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/node/internals/hooks/useField/useField.utils.js +16 -4
- package/node/internals/hooks/useField/useFieldState.js +3 -2
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/node/internals/hooks/usePicker/usePickerValue.js +187 -152
- package/node/internals/hooks/usePicker/usePickerValue.types.js +5 -0
- package/node/tests/describeGregorianAdapter/describeGregorianAdapter.js +29 -0
- package/node/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +5 -0
- package/node/tests/describeGregorianAdapter/index.js +18 -0
- package/node/tests/describeGregorianAdapter/testCalculations.js +279 -0
- package/node/tests/describeGregorianAdapter/testFormat.js +34 -0
- package/node/tests/describeGregorianAdapter/testLocalization.js +23 -0
- package/node/tests/describeValidation/describeValidation.js +2 -1
- package/node/tests/describeValidation/testMinutesViewValidation.js +210 -0
- package/node/tests/describeValue/testPickerActionBar.js +52 -3
- package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/package.json +9 -9
- package/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/tests/describeGregorianAdapter/index.js +1 -0
- package/tests/describeGregorianAdapter/testCalculations.js +272 -0
- package/tests/describeGregorianAdapter/testFormat.js +27 -0
- package/tests/describeGregorianAdapter/testLocalization.js +16 -0
- package/tests/describeValidation/describeValidation.js +2 -1
- package/tests/describeValidation/testMinutesViewValidation.js +200 -0
- package/tests/describeValue/testPickerActionBar.js +52 -3
- package/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
export var testCalculations = function testCalculations(_ref) {
|
|
3
|
+
var adapter = _ref.adapter,
|
|
4
|
+
testDate = _ref.testDate,
|
|
5
|
+
testDateISO = _ref.testDateISO,
|
|
6
|
+
formatDateTime = _ref.formatDateTime;
|
|
7
|
+
it('Method: date', function () {
|
|
8
|
+
// ISO string
|
|
9
|
+
expect(adapter.isEqual(testDate, adapter.date(testDateISO))).to.equal(true);
|
|
10
|
+
|
|
11
|
+
// Native Date
|
|
12
|
+
expect(adapter.isEqual(testDate, adapter.date(new Date(testDateISO)))).to.equal(true);
|
|
13
|
+
|
|
14
|
+
// Parse already date-specific object
|
|
15
|
+
expect(adapter.isEqual(testDate, adapter.date(adapter.date(testDateISO)))).to.equal(true);
|
|
16
|
+
|
|
17
|
+
// Parse null inputs
|
|
18
|
+
expect(adapter.date(null)).to.equal(null);
|
|
19
|
+
|
|
20
|
+
// Undefined
|
|
21
|
+
expect(!!adapter.date(undefined)).to.equal(true);
|
|
22
|
+
});
|
|
23
|
+
it('Method: isValid', function () {
|
|
24
|
+
var invalidDate = adapter.date('2018-42-30T11:60:00.000Z');
|
|
25
|
+
expect(adapter.isValid(testDate)).to.equal(true);
|
|
26
|
+
expect(adapter.isValid(invalidDate)).to.equal(false);
|
|
27
|
+
expect(adapter.isValid(undefined)).to.equal(true);
|
|
28
|
+
expect(adapter.isValid(null)).to.equal(false);
|
|
29
|
+
expect(adapter.isValid('2018-42-30T11:60:00.000Z')).to.equal(false);
|
|
30
|
+
});
|
|
31
|
+
it('Method: addYears', function () {
|
|
32
|
+
expect(adapter.format(adapter.addYears(testDate, 2), 'year')).to.equal('2020');
|
|
33
|
+
expect(adapter.format(adapter.addYears(testDate, -2), 'year')).to.equal('2016');
|
|
34
|
+
});
|
|
35
|
+
it('Method: addMonths', function () {
|
|
36
|
+
expect(adapter.format(adapter.addMonths(testDate, 2), 'monthAndYear')).to.equal('December 2018');
|
|
37
|
+
expect(adapter.format(adapter.addMonths(testDate, -2), 'monthAndYear')).to.equal('August 2018');
|
|
38
|
+
});
|
|
39
|
+
it('Method: addWeeks', function () {
|
|
40
|
+
expect(adapter.getDiff(adapter.addWeeks(testDate, 1), testDate, 'weeks')).to.equal(1);
|
|
41
|
+
expect(adapter.getDiff(adapter.addWeeks(testDate, -1), testDate, 'weeks')).to.equal(-1);
|
|
42
|
+
});
|
|
43
|
+
it('Method: addDays', function () {
|
|
44
|
+
expect(adapter.format(adapter.addDays(testDate, 1), 'dayOfMonth')).to.equal('31');
|
|
45
|
+
expect(adapter.format(adapter.addDays(testDate, -1), 'dayOfMonth')).to.equal('29');
|
|
46
|
+
});
|
|
47
|
+
it('Method: addHours', function () {
|
|
48
|
+
expect(adapter.format(adapter.addHours(testDate, 65), 'hours24h')).to.equal('04');
|
|
49
|
+
expect(adapter.format(adapter.addHours(testDate, -5), 'hours24h')).to.equal('06');
|
|
50
|
+
});
|
|
51
|
+
it('Method: addMinutes', function () {
|
|
52
|
+
expect(adapter.format(adapter.addMinutes(testDate, 65), 'minutes')).to.equal('49');
|
|
53
|
+
expect(adapter.format(adapter.addMinutes(testDate, -5), 'minutes')).to.equal('39');
|
|
54
|
+
});
|
|
55
|
+
it('Method: addSeconds', function () {
|
|
56
|
+
expect(adapter.format(adapter.addSeconds(testDate, 65), 'seconds')).to.equal('05');
|
|
57
|
+
expect(adapter.format(adapter.addSeconds(testDate, -5), 'seconds')).to.equal('55');
|
|
58
|
+
});
|
|
59
|
+
it('Method: startOfYear', function () {
|
|
60
|
+
expect(adapter.formatByString(adapter.startOfYear(testDate), formatDateTime)).to.equal('2018-01-01 00:00:00');
|
|
61
|
+
});
|
|
62
|
+
it('Method: startOfMonth', function () {
|
|
63
|
+
expect(adapter.formatByString(adapter.startOfMonth(testDate), formatDateTime)).to.equal('2018-10-01 00:00:00');
|
|
64
|
+
});
|
|
65
|
+
it('Method: startOfWeek', function () {
|
|
66
|
+
expect(adapter.formatByString(adapter.startOfWeek(testDate), formatDateTime)).to.equal(adapter.lib === 'luxon' ? '2018-10-29 00:00:00' : '2018-10-28 00:00:00');
|
|
67
|
+
|
|
68
|
+
// Non ISO
|
|
69
|
+
expect(adapter.formatByString(adapter.startOfWeek(adapter.date('2018-10-28T00:00:00.000Z')), formatDateTime)).to.equal(adapter.lib === 'luxon' ? '2018-10-22 00:00:00' : '2018-10-28 00:00:00');
|
|
70
|
+
});
|
|
71
|
+
it('Method: startOfDay', function () {
|
|
72
|
+
expect(adapter.formatByString(adapter.startOfDay(testDate), formatDateTime)).to.equal('2018-10-30 00:00:00');
|
|
73
|
+
});
|
|
74
|
+
it('Method: endOfYear', function () {
|
|
75
|
+
expect(adapter.formatByString(adapter.endOfYear(testDate), formatDateTime)).to.equal('2018-12-31 23:59:59');
|
|
76
|
+
});
|
|
77
|
+
it('Method: endOfMonth', function () {
|
|
78
|
+
expect(adapter.formatByString(adapter.endOfMonth(testDate), formatDateTime)).to.equal('2018-10-31 23:59:59');
|
|
79
|
+
});
|
|
80
|
+
it('Method: endOfWeek', function () {
|
|
81
|
+
expect(adapter.formatByString(adapter.endOfWeek(testDate), formatDateTime)).to.equal(adapter.lib === 'luxon' ? '2018-11-04 23:59:59' : '2018-11-03 23:59:59');
|
|
82
|
+
|
|
83
|
+
// Non ISO
|
|
84
|
+
expect(adapter.formatByString(adapter.endOfWeek(adapter.date('2018-10-28T00:00:00.000Z')), formatDateTime)).to.equal(adapter.lib === 'luxon' ? '2018-10-28 23:59:59' : '2018-11-03 23:59:59');
|
|
85
|
+
});
|
|
86
|
+
it('Method: endOfDay', function () {
|
|
87
|
+
expect(adapter.formatByString(adapter.endOfDay(testDate), formatDateTime)).to.equal('2018-10-30 23:59:59');
|
|
88
|
+
});
|
|
89
|
+
it('Method:getPreviousMonth', function () {
|
|
90
|
+
expect(adapter.formatByString(adapter.getPreviousMonth(testDate), formatDateTime)).to.equal('2018-09-30 11:44:00');
|
|
91
|
+
});
|
|
92
|
+
it('Method:getMonthArray', function () {
|
|
93
|
+
expect(adapter.getMonthArray(testDate).map(function (date) {
|
|
94
|
+
return adapter.formatByString(date, formatDateTime);
|
|
95
|
+
})).to.deep.equal(['2018-01-01 00:00:00', '2018-02-01 00:00:00', '2018-03-01 00:00:00', '2018-04-01 00:00:00', '2018-05-01 00:00:00', '2018-06-01 00:00:00', '2018-07-01 00:00:00', '2018-08-01 00:00:00', '2018-09-01 00:00:00', '2018-10-01 00:00:00', '2018-11-01 00:00:00', '2018-12-01 00:00:00']);
|
|
96
|
+
});
|
|
97
|
+
it('Method:getNextMonth', function () {
|
|
98
|
+
expect(adapter.formatByString(adapter.getNextMonth(testDate), formatDateTime)).to.equal('2018-11-30 11:44:00');
|
|
99
|
+
});
|
|
100
|
+
it('Method:getHours', function () {
|
|
101
|
+
expect(adapter.getHours(testDate)).to.equal(new Date(testDateISO).getHours());
|
|
102
|
+
});
|
|
103
|
+
it('Method:getMinutes', function () {
|
|
104
|
+
expect(adapter.getMinutes(testDate)).to.equal(44);
|
|
105
|
+
});
|
|
106
|
+
it('Method:getSeconds', function () {
|
|
107
|
+
expect(adapter.getSeconds(testDate)).to.equal(0);
|
|
108
|
+
});
|
|
109
|
+
it('Method:getDate', function () {
|
|
110
|
+
expect(adapter.getDate(testDate)).to.equal(30);
|
|
111
|
+
});
|
|
112
|
+
it('Method:getYear', function () {
|
|
113
|
+
expect(adapter.getYear(testDate)).to.equal(2018);
|
|
114
|
+
});
|
|
115
|
+
it('Method:getMonth', function () {
|
|
116
|
+
expect(adapter.getMonth(testDate)).to.equal(9);
|
|
117
|
+
});
|
|
118
|
+
it('Method:getDaysInMonth', function () {
|
|
119
|
+
expect(adapter.getDaysInMonth(testDate)).to.equal(31);
|
|
120
|
+
});
|
|
121
|
+
it('Method:setMonth', function () {
|
|
122
|
+
var updatedTime = adapter.formatByString(adapter.setMonth(testDate, 4), formatDateTime);
|
|
123
|
+
expect(updatedTime).to.equal('2018-05-30 11:44:00');
|
|
124
|
+
});
|
|
125
|
+
it('Method:setHours', function () {
|
|
126
|
+
var updatedTime = adapter.formatByString(adapter.setHours(testDate, 0), formatDateTime);
|
|
127
|
+
expect(updatedTime).to.equal('2018-10-30 00:44:00');
|
|
128
|
+
});
|
|
129
|
+
it('Method:setMinutes', function () {
|
|
130
|
+
var updatedTime = adapter.formatByString(adapter.setMinutes(testDate, 12), formatDateTime);
|
|
131
|
+
expect(updatedTime).to.equal('2018-10-30 11:12:00');
|
|
132
|
+
});
|
|
133
|
+
it('Method:setMinutes', function () {
|
|
134
|
+
var updatedTime = adapter.formatByString(adapter.setMinutes(testDate, 12), formatDateTime);
|
|
135
|
+
expect(updatedTime).to.equal('2018-10-30 11:12:00');
|
|
136
|
+
});
|
|
137
|
+
it('Method:setYear', function () {
|
|
138
|
+
var updatedTime = adapter.formatByString(adapter.setYear(testDate, 2011), formatDateTime);
|
|
139
|
+
expect(updatedTime).to.equal('2011-10-30 11:44:00');
|
|
140
|
+
});
|
|
141
|
+
it('Method:setDate', function () {
|
|
142
|
+
var updatedTime = adapter.formatByString(adapter.setDate(testDate, 15), formatDateTime);
|
|
143
|
+
expect(updatedTime).to.equal('2018-10-15 11:44:00');
|
|
144
|
+
});
|
|
145
|
+
it('Method:setSeconds', function () {
|
|
146
|
+
var updatedValue = adapter.formatByString(adapter.setSeconds(testDate, 11), formatDateTime);
|
|
147
|
+
expect(updatedValue).to.equal('2018-10-30 11:44:11');
|
|
148
|
+
});
|
|
149
|
+
it('Method:isAfter', function () {
|
|
150
|
+
expect(adapter.isAfter(adapter.date(), testDate)).to.equal(true);
|
|
151
|
+
expect(adapter.isAfter(testDate, adapter.date())).to.equal(false);
|
|
152
|
+
});
|
|
153
|
+
it('Method:isBefore', function () {
|
|
154
|
+
expect(adapter.isBefore(testDate, adapter.date())).to.equal(true);
|
|
155
|
+
expect(adapter.isBefore(adapter.date(), testDate)).to.equal(false);
|
|
156
|
+
});
|
|
157
|
+
it('Method:isAfterDay', function () {
|
|
158
|
+
var nextDay = adapter.addDays(testDate, 1);
|
|
159
|
+
expect(adapter.isAfterDay(nextDay, testDate)).to.equal(true);
|
|
160
|
+
expect(adapter.isAfterDay(testDate, nextDay)).to.equal(false);
|
|
161
|
+
});
|
|
162
|
+
it('Method:isBeforeDay', function () {
|
|
163
|
+
var previousDay = adapter.addDays(testDate, -1);
|
|
164
|
+
expect(adapter.isBeforeDay(testDate, previousDay)).to.equal(false);
|
|
165
|
+
expect(adapter.isBeforeDay(previousDay, testDate)).to.equal(true);
|
|
166
|
+
});
|
|
167
|
+
it('Method:isAfterYear', function () {
|
|
168
|
+
var nextYear = adapter.setYear(testDate, 2019);
|
|
169
|
+
expect(adapter.isAfterYear(nextYear, testDate)).to.equal(true);
|
|
170
|
+
expect(adapter.isAfterYear(testDate, nextYear)).to.equal(false);
|
|
171
|
+
});
|
|
172
|
+
it('Method:isBeforeYear', function () {
|
|
173
|
+
var previousYear = adapter.setYear(testDate, 2017);
|
|
174
|
+
expect(adapter.isBeforeYear(testDate, previousYear)).to.equal(false);
|
|
175
|
+
expect(adapter.isBeforeYear(previousYear, testDate)).to.equal(true);
|
|
176
|
+
});
|
|
177
|
+
it('Method:getWeekArray', function () {
|
|
178
|
+
var weekArray = adapter.getWeekArray(testDate);
|
|
179
|
+
expect(weekArray).to.have.length(5);
|
|
180
|
+
weekArray.forEach(function (week) {
|
|
181
|
+
expect(week).to.have.length(7);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
it('Method:getYearRange', function () {
|
|
185
|
+
var yearRange = adapter.getYearRange(testDate, adapter.setYear(testDate, 2124));
|
|
186
|
+
expect(yearRange).to.have.length(107);
|
|
187
|
+
expect(adapter.getYear(yearRange[yearRange.length - 1])).to.equal(2124);
|
|
188
|
+
var emptyYearRange = adapter.getYearRange(testDate, adapter.setYear(testDate, adapter.getYear(testDate) - 1));
|
|
189
|
+
expect(emptyYearRange).to.have.length(0);
|
|
190
|
+
});
|
|
191
|
+
it('Method: getDiff', function () {
|
|
192
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-10-29T11:44:00.000Z'))).to.equal(86400000);
|
|
193
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-10-31T11:44:00.000Z'))).to.equal(-86400000);
|
|
194
|
+
expect(adapter.getDiff(testDate, '2018-10-31T11:44:00.000Z')).to.equal(-86400000);
|
|
195
|
+
|
|
196
|
+
// With units
|
|
197
|
+
expect(adapter.getDiff(testDate, adapter.date('2017-09-29T11:44:00.000Z'), 'years')).to.equal(1);
|
|
198
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-08-29T11:44:00.000Z'), 'months')).to.equal(2);
|
|
199
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-05-29T11:44:00.000Z'), 'quarters')).to.equal(1);
|
|
200
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-09-29T11:44:00.000Z'), 'days')).to.equal(31);
|
|
201
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-09-29T11:44:00.000Z'), 'weeks')).to.equal(4);
|
|
202
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-09-29T11:44:00.000Z'), 'hours')).to.equal(744);
|
|
203
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-09-29T11:44:00.000Z'), 'minutes')).to.equal(44640);
|
|
204
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-10-30T10:44:00.000Z'), 'seconds')).to.equal(3600);
|
|
205
|
+
expect(adapter.getDiff(testDate, adapter.date('2018-10-30T10:44:00.000Z'), 'milliseconds')).to.equal(3600000);
|
|
206
|
+
});
|
|
207
|
+
it('Method: mergeDateAndTime', function () {
|
|
208
|
+
var mergedDate = adapter.mergeDateAndTime(testDate, adapter.date('2018-01-01T14:15:16.000Z'));
|
|
209
|
+
expect(adapter.toJsDate(mergedDate).toISOString()).to.equal('2018-10-30T14:15:16.000Z');
|
|
210
|
+
});
|
|
211
|
+
it('Method: isEqual', function () {
|
|
212
|
+
expect(adapter.isEqual(adapter.date(null), null)).to.equal(true);
|
|
213
|
+
expect(adapter.isEqual(testDate, adapter.date(testDateISO))).to.equal(true);
|
|
214
|
+
expect(adapter.isEqual(null, adapter.date(testDateISO))).to.equal(false);
|
|
215
|
+
});
|
|
216
|
+
it('Method: parseISO', function () {
|
|
217
|
+
var parsedDate = adapter.parseISO(testDateISO);
|
|
218
|
+
var outputtedISO = adapter.toISO(parsedDate);
|
|
219
|
+
if (adapter.lib === 'date-fns') {
|
|
220
|
+
// date-fns never suppress useless milliseconds in the end
|
|
221
|
+
expect(outputtedISO).to.equal(testDateISO.replace('.000Z', 'Z'));
|
|
222
|
+
} else if (adapter.lib === 'luxon') {
|
|
223
|
+
// luxon does not shorthand +00:00 to Z, which is also valid ISO string
|
|
224
|
+
expect(outputtedISO).to.equal(testDateISO.replace('Z', '+00:00'));
|
|
225
|
+
} else {
|
|
226
|
+
expect(outputtedISO).to.equal(testDateISO);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
it('Method: parse', function () {
|
|
230
|
+
var parsedDate = adapter.parse('2018-10-30 11:44:00', formatDateTime);
|
|
231
|
+
expect(adapter.isEqual(parsedDate, testDate)).to.equal(true);
|
|
232
|
+
expect(adapter.parse('', formatDateTime)).to.equal(null);
|
|
233
|
+
|
|
234
|
+
// Invalid input
|
|
235
|
+
var invalidateParsedDate = adapter.parse('99-99-9999', formatDateTime);
|
|
236
|
+
expect(adapter.isValid(invalidateParsedDate)).to.equal(false);
|
|
237
|
+
});
|
|
238
|
+
it('Method: isNull', function () {
|
|
239
|
+
expect(adapter.isNull(null)).to.equal(true);
|
|
240
|
+
expect(adapter.isNull(testDate)).to.equal(false);
|
|
241
|
+
});
|
|
242
|
+
it('Method: isSameDay', function () {
|
|
243
|
+
expect(adapter.isSameDay(testDate, adapter.date('2018-10-30T00:00:00.000Z'))).to.equal(true);
|
|
244
|
+
expect(adapter.isSameDay(testDate, adapter.date('2019-10-30T00:00:00.000Z'))).to.equal(false);
|
|
245
|
+
});
|
|
246
|
+
it('Method: isSameMonth', function () {
|
|
247
|
+
expect(adapter.isSameMonth(testDate, adapter.date('2018-10-01T00:00:00.000Z'))).to.equal(true);
|
|
248
|
+
expect(adapter.isSameMonth(testDate, adapter.date('2019-10-01T00:00:00.000Z'))).to.equal(false);
|
|
249
|
+
});
|
|
250
|
+
it('Method: isSameYear', function () {
|
|
251
|
+
expect(adapter.isSameYear(testDate, adapter.date('2018-10-01T00:00:00.000Z'))).to.equal(true);
|
|
252
|
+
expect(adapter.isSameYear(testDate, adapter.date('2019-10-01T00:00:00.000Z'))).to.equal(false);
|
|
253
|
+
});
|
|
254
|
+
it('Method: isSameHour', function () {
|
|
255
|
+
expect(adapter.isSameHour(testDate, adapter.date(testDateISO))).to.equal(true);
|
|
256
|
+
expect(adapter.isSameHour(testDate, adapter.addDays(adapter.date(testDateISO), 5))).to.equal(false);
|
|
257
|
+
});
|
|
258
|
+
it('Method: getCurrentLocaleCode', function () {
|
|
259
|
+
// Returns the default location
|
|
260
|
+
expect(adapter.getCurrentLocaleCode()).to.match(/en/);
|
|
261
|
+
});
|
|
262
|
+
it('Method: toJsDate', function () {
|
|
263
|
+
expect(adapter.toJsDate(testDate)).to.be.instanceOf(Date);
|
|
264
|
+
});
|
|
265
|
+
it('Method: isWithinRange', function () {
|
|
266
|
+
expect(adapter.isWithinRange(adapter.date('2019-10-01T00:00:00.000Z'), [adapter.date('2019-09-01T00:00:00.000Z'), adapter.date('2019-11-01T00:00:00.000Z')])).to.equal(true);
|
|
267
|
+
expect(adapter.isWithinRange(adapter.date('2019-12-01T00:00:00.000Z'), [adapter.date('2019-09-01T00:00:00.000Z'), adapter.date('2019-11-01T00:00:00.000Z')])).to.equal(false);
|
|
268
|
+
|
|
269
|
+
// Should use inclusivity of range
|
|
270
|
+
expect(adapter.isWithinRange(adapter.date('2019-09-01T00:00:00.000Z'), [adapter.date('2019-09-01T00:00:00.000Z'), adapter.date('2019-12-01T00:00:00.000Z')])).to.equal(true);
|
|
271
|
+
expect(adapter.isWithinRange(adapter.date('2019-12-01T00:00:00.000Z'), [adapter.date('2019-09-01T00:00:00.000Z'), adapter.date('2019-12-01T00:00:00.000Z')])).to.equal(true);
|
|
272
|
+
});
|
|
273
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
export var testFormat = function testFormat(_ref) {
|
|
3
|
+
var adapter = _ref.adapter;
|
|
4
|
+
var expectDate = function expectDate(format, expected) {
|
|
5
|
+
var date = adapter.date('2020-01-01T23:44:00.000Z');
|
|
6
|
+
var result = adapter.format(date, format);
|
|
7
|
+
expect(result).to.equal(expected);
|
|
8
|
+
};
|
|
9
|
+
it('should correctly format standalone hardcoded formats', function () {
|
|
10
|
+
expectDate('normalDate', '1 January');
|
|
11
|
+
expectDate('normalDateWithWeekday', 'Wed, Jan 1');
|
|
12
|
+
expectDate('shortDate', 'Jan 1');
|
|
13
|
+
expectDate('year', '2020');
|
|
14
|
+
expectDate('month', 'January');
|
|
15
|
+
expectDate('monthAndDate', 'January 1');
|
|
16
|
+
expectDate('weekday', 'Wednesday');
|
|
17
|
+
expectDate('weekdayShort', 'Wed');
|
|
18
|
+
expectDate('dayOfMonth', '1');
|
|
19
|
+
expectDate('fullTime12h', '11:44 PM');
|
|
20
|
+
expectDate('fullTime24h', '23:44');
|
|
21
|
+
expectDate('hours12h', '11');
|
|
22
|
+
expectDate('hours24h', '23');
|
|
23
|
+
expectDate('minutes', '44');
|
|
24
|
+
expectDate('seconds', '00');
|
|
25
|
+
});
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
export var testLocalization = function testLocalization(_ref) {
|
|
3
|
+
var adapter = _ref.adapter;
|
|
4
|
+
it('Method: formatNumber', function () {
|
|
5
|
+
expect(adapter.formatNumber('1')).to.equal('1');
|
|
6
|
+
});
|
|
7
|
+
it('Method: getMeridiemText', function () {
|
|
8
|
+
expect(adapter.getMeridiemText('am')).to.equal('AM');
|
|
9
|
+
expect(adapter.getMeridiemText('pm')).to.equal('PM');
|
|
10
|
+
});
|
|
11
|
+
it('Method: getFormatHelperText', function () {
|
|
12
|
+
expect(adapter.getFormatHelperText(adapter.formats.keyboardDate)).to.equal('mm/dd/yyyy');
|
|
13
|
+
expect(adapter.getFormatHelperText(adapter.formats.keyboardDateTime12h)).to.equal('mm/dd/yyyy hh:mm (a|p)m');
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -6,7 +6,8 @@ import { testDayViewValidation } from './testDayViewValidation';
|
|
|
6
6
|
import { testMonthViewValidation } from './testMonthViewValidation';
|
|
7
7
|
import { testTextFieldValidation } from './testTextFieldValidation';
|
|
8
8
|
import { testYearViewValidation } from './testYearViewValidation';
|
|
9
|
-
|
|
9
|
+
import { testMinutesViewValidation } from './testMinutesViewValidation';
|
|
10
|
+
var TEST_SUITES = [testYearViewValidation, testMonthViewValidation, testDayViewValidation, testMinutesViewValidation, testTextFieldValidation];
|
|
10
11
|
function innerDescribeValidation(ElementToTest, getOptions) {
|
|
11
12
|
var _getOptions = getOptions(),
|
|
12
13
|
_getOptions$after = _getOptions.after,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { screen } from '@mui/monorepo/test/utils';
|
|
5
|
+
import { adapterToUse } from 'test/utils/pickers-utils';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
var toMinutesLabel = function toMinutesLabel(minutes) {
|
|
8
|
+
return "".concat(Number(minutes) < 10 ? "0".concat(minutes) : minutes, " minutes");
|
|
9
|
+
};
|
|
10
|
+
export var testMinutesViewValidation = function testMinutesViewValidation(ElementToTest, getOption) {
|
|
11
|
+
var _getOption = getOption(),
|
|
12
|
+
componentFamily = _getOption.componentFamily,
|
|
13
|
+
views = _getOption.views,
|
|
14
|
+
render = _getOption.render,
|
|
15
|
+
clock = _getOption.clock,
|
|
16
|
+
withDate = _getOption.withDate,
|
|
17
|
+
withTime = _getOption.withTime,
|
|
18
|
+
variant = _getOption.variant;
|
|
19
|
+
if (!views.includes('minutes') || !variant || componentFamily !== 'picker' || variant === 'desktop') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
describe('minutes view:', function () {
|
|
23
|
+
var defaultProps = _extends({
|
|
24
|
+
onChange: function onChange() {},
|
|
25
|
+
open: true,
|
|
26
|
+
view: 'minutes',
|
|
27
|
+
openTo: 'minutes',
|
|
28
|
+
reduceAnimations: true
|
|
29
|
+
}, componentFamily.includes('legacy-') ? {
|
|
30
|
+
componentsProps: {
|
|
31
|
+
toolbar: {
|
|
32
|
+
hidden: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} : {
|
|
36
|
+
slotProps: {
|
|
37
|
+
toolbar: {
|
|
38
|
+
hidden: true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
it('should apply shouldDisableTime', function test() {
|
|
43
|
+
render( /*#__PURE__*/_jsx(ElementToTest, _extends({}, defaultProps, {
|
|
44
|
+
value: adapterToUse.date(new Date(2018, 2, 12, 8, 15, 0)),
|
|
45
|
+
shouldDisableTime: function shouldDisableTime(date) {
|
|
46
|
+
return adapterToUse.isAfter(date, adapterToUse.date(new Date(2018, 2, 12, 8, 20, 0)));
|
|
47
|
+
}
|
|
48
|
+
})));
|
|
49
|
+
expect(screen.getByRole('option', {
|
|
50
|
+
name: toMinutesLabel('10')
|
|
51
|
+
})).not.to.have.attribute('aria-disabled');
|
|
52
|
+
expect(screen.getByRole('option', {
|
|
53
|
+
name: toMinutesLabel('15')
|
|
54
|
+
})).not.to.have.attribute('aria-disabled');
|
|
55
|
+
expect(screen.getByRole('option', {
|
|
56
|
+
name: toMinutesLabel('20')
|
|
57
|
+
})).not.to.have.attribute('aria-disabled');
|
|
58
|
+
expect(screen.getByRole('option', {
|
|
59
|
+
name: toMinutesLabel('25')
|
|
60
|
+
})).to.have.attribute('aria-disabled');
|
|
61
|
+
expect(screen.getByRole('option', {
|
|
62
|
+
name: toMinutesLabel('30')
|
|
63
|
+
})).to.have.attribute('aria-disabled');
|
|
64
|
+
expect(screen.getByRole('option', {
|
|
65
|
+
name: toMinutesLabel('55')
|
|
66
|
+
})).to.have.attribute('aria-disabled');
|
|
67
|
+
});
|
|
68
|
+
it('should apply disablePast', function test() {
|
|
69
|
+
var now;
|
|
70
|
+
function WithFakeTimer(props) {
|
|
71
|
+
now = adapterToUse.date(new Date());
|
|
72
|
+
return /*#__PURE__*/_jsx(ElementToTest, _extends({
|
|
73
|
+
value: now
|
|
74
|
+
}, props));
|
|
75
|
+
}
|
|
76
|
+
var _render = render( /*#__PURE__*/_jsx(WithFakeTimer, _extends({}, defaultProps, {
|
|
77
|
+
disablePast: true
|
|
78
|
+
}))),
|
|
79
|
+
setProps = _render.setProps;
|
|
80
|
+
var tomorrow = adapterToUse.addDays(now, 1);
|
|
81
|
+
var currentMinutes = adapterToUse.getMinutes(now);
|
|
82
|
+
var closestNowMinutesOptionValue = Math.floor(currentMinutes / 5) * 5;
|
|
83
|
+
var previousMinutesOptionValue = Math.floor(currentMinutes / 5) * 5 - 5;
|
|
84
|
+
var nextMinutesOptionValue = Math.floor(currentMinutes / 5) * 5 + 5;
|
|
85
|
+
expect(screen.getByRole('option', {
|
|
86
|
+
name: toMinutesLabel(previousMinutesOptionValue)
|
|
87
|
+
})).to.have.attribute('aria-disabled');
|
|
88
|
+
if (currentMinutes <= closestNowMinutesOptionValue) {
|
|
89
|
+
expect(screen.getByRole('option', {
|
|
90
|
+
name: toMinutesLabel(closestNowMinutesOptionValue)
|
|
91
|
+
})).not.to.have.attribute('aria-disabled');
|
|
92
|
+
} else {
|
|
93
|
+
expect(screen.getByRole('option', {
|
|
94
|
+
name: toMinutesLabel(closestNowMinutesOptionValue)
|
|
95
|
+
})).to.have.attribute('aria-disabled');
|
|
96
|
+
}
|
|
97
|
+
expect(screen.getByRole('option', {
|
|
98
|
+
name: toMinutesLabel(nextMinutesOptionValue)
|
|
99
|
+
})).not.to.have.attribute('aria-disabled');
|
|
100
|
+
|
|
101
|
+
// following validation is relevant only for DateTimePicker
|
|
102
|
+
if (!withDate || !withTime) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
setProps({
|
|
106
|
+
value: tomorrow
|
|
107
|
+
});
|
|
108
|
+
clock.runToLast();
|
|
109
|
+
expect(screen.getByRole('option', {
|
|
110
|
+
name: toMinutesLabel(previousMinutesOptionValue)
|
|
111
|
+
})).not.to.have.attribute('aria-disabled');
|
|
112
|
+
expect(screen.getByRole('option', {
|
|
113
|
+
name: toMinutesLabel(closestNowMinutesOptionValue)
|
|
114
|
+
})).not.to.have.attribute('aria-disabled');
|
|
115
|
+
});
|
|
116
|
+
it('should apply disableFuture', function test() {
|
|
117
|
+
var now;
|
|
118
|
+
function WithFakeTimer(props) {
|
|
119
|
+
now = adapterToUse.date(new Date());
|
|
120
|
+
return /*#__PURE__*/_jsx(ElementToTest, _extends({
|
|
121
|
+
value: now
|
|
122
|
+
}, props));
|
|
123
|
+
}
|
|
124
|
+
var _render2 = render( /*#__PURE__*/_jsx(WithFakeTimer, _extends({}, defaultProps, {
|
|
125
|
+
disableFuture: true
|
|
126
|
+
}))),
|
|
127
|
+
setProps = _render2.setProps;
|
|
128
|
+
var yesterday = adapterToUse.addDays(now, -1);
|
|
129
|
+
var currentMinutes = adapterToUse.getMinutes(now);
|
|
130
|
+
var closestNowMinutesOptionValue = Math.floor(currentMinutes / 5) * 5;
|
|
131
|
+
var previousMinutesOptionValue = Math.floor(currentMinutes / 5) * 5 - 5;
|
|
132
|
+
var nextMinutesOptionValue = Math.floor(currentMinutes / 5) * 5 + 5;
|
|
133
|
+
expect(screen.getByRole('option', {
|
|
134
|
+
name: toMinutesLabel(previousMinutesOptionValue)
|
|
135
|
+
})).not.to.have.attribute('aria-disabled');
|
|
136
|
+
if (currentMinutes < closestNowMinutesOptionValue) {
|
|
137
|
+
expect(screen.getByRole('option', {
|
|
138
|
+
name: toMinutesLabel(closestNowMinutesOptionValue)
|
|
139
|
+
})).to.have.attribute('aria-disabled');
|
|
140
|
+
} else {
|
|
141
|
+
expect(screen.getByRole('option', {
|
|
142
|
+
name: toMinutesLabel(closestNowMinutesOptionValue)
|
|
143
|
+
})).not.to.have.attribute('aria-disabled');
|
|
144
|
+
}
|
|
145
|
+
expect(screen.getByRole('option', {
|
|
146
|
+
name: toMinutesLabel(nextMinutesOptionValue)
|
|
147
|
+
})).to.have.attribute('aria-disabled');
|
|
148
|
+
|
|
149
|
+
// following validation is relevant only for DateTimePicker
|
|
150
|
+
if (!withDate || !withTime) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
setProps({
|
|
154
|
+
value: yesterday
|
|
155
|
+
});
|
|
156
|
+
clock.runToLast();
|
|
157
|
+
expect(screen.getByRole('option', {
|
|
158
|
+
name: toMinutesLabel(previousMinutesOptionValue)
|
|
159
|
+
})).not.to.have.attribute('aria-disabled');
|
|
160
|
+
expect(screen.getByRole('option', {
|
|
161
|
+
name: toMinutesLabel(closestNowMinutesOptionValue)
|
|
162
|
+
})).not.to.have.attribute('aria-disabled');
|
|
163
|
+
});
|
|
164
|
+
it('should apply maxTime', function test() {
|
|
165
|
+
render( /*#__PURE__*/_jsx(ElementToTest, _extends({}, defaultProps, {
|
|
166
|
+
value: adapterToUse.date(new Date(2019, 5, 15, 11, 15, 0)),
|
|
167
|
+
maxTime: adapterToUse.date(new Date(2019, 5, 15, 11, 20, 0))
|
|
168
|
+
})));
|
|
169
|
+
expect(screen.getByRole('option', {
|
|
170
|
+
name: toMinutesLabel('10')
|
|
171
|
+
})).not.to.have.attribute('aria-disabled');
|
|
172
|
+
expect(screen.getByRole('option', {
|
|
173
|
+
name: toMinutesLabel('15')
|
|
174
|
+
})).not.to.have.attribute('aria-disabled');
|
|
175
|
+
expect(screen.getByRole('option', {
|
|
176
|
+
name: toMinutesLabel('20')
|
|
177
|
+
})).not.to.have.attribute('aria-disabled');
|
|
178
|
+
expect(screen.getByRole('option', {
|
|
179
|
+
name: toMinutesLabel('25')
|
|
180
|
+
})).to.have.attribute('aria-disabled');
|
|
181
|
+
});
|
|
182
|
+
it('should apply minTime', function test() {
|
|
183
|
+
render( /*#__PURE__*/_jsx(ElementToTest, _extends({}, defaultProps, {
|
|
184
|
+
value: adapterToUse.date(new Date(2019, 5, 15, 11, 15, 0)),
|
|
185
|
+
minTime: adapterToUse.date(new Date(2019, 5, 15, 11, 10, 0))
|
|
186
|
+
})));
|
|
187
|
+
expect(screen.getByRole('option', {
|
|
188
|
+
name: toMinutesLabel('0')
|
|
189
|
+
})).to.have.attribute('aria-disabled');
|
|
190
|
+
expect(screen.getByRole('option', {
|
|
191
|
+
name: toMinutesLabel('5')
|
|
192
|
+
})).to.have.attribute('aria-disabled');
|
|
193
|
+
expect(screen.getByRole('option', {
|
|
194
|
+
name: toMinutesLabel('10')
|
|
195
|
+
})).not.to.have.attribute('aria-disabled');
|
|
196
|
+
expect(screen.getByRole('option', {
|
|
197
|
+
name: toMinutesLabel('15')
|
|
198
|
+
})).not.to.have.attribute('aria-disabled');
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
};
|
|
@@ -72,7 +72,8 @@ export var testPickerActionBar = function testPickerActionBar(ElementToTest, get
|
|
|
72
72
|
actionBar: {
|
|
73
73
|
actions: ['clear']
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
},
|
|
76
|
+
value: emptyValue
|
|
76
77
|
}));
|
|
77
78
|
|
|
78
79
|
// Clear the date
|
|
@@ -92,7 +93,7 @@ export var testPickerActionBar = function testPickerActionBar(ElementToTest, get
|
|
|
92
93
|
onAccept: onAccept,
|
|
93
94
|
onClose: onClose,
|
|
94
95
|
open: true,
|
|
95
|
-
|
|
96
|
+
value: values[0],
|
|
96
97
|
componentsProps: {
|
|
97
98
|
actionBar: {
|
|
98
99
|
actions: ['cancel']
|
|
@@ -128,7 +129,7 @@ export var testPickerActionBar = function testPickerActionBar(ElementToTest, get
|
|
|
128
129
|
onAccept: onAccept,
|
|
129
130
|
onClose: onClose,
|
|
130
131
|
open: true,
|
|
131
|
-
|
|
132
|
+
value: values[0],
|
|
132
133
|
componentsProps: {
|
|
133
134
|
actionBar: {
|
|
134
135
|
actions: ['cancel']
|
|
@@ -174,6 +175,54 @@ export var testPickerActionBar = function testPickerActionBar(ElementToTest, get
|
|
|
174
175
|
expect(onAccept.callCount).to.equal(1);
|
|
175
176
|
expect(onClose.callCount).to.equal(1);
|
|
176
177
|
});
|
|
178
|
+
it('should call onChange, onClose and onAccept when validating the default value', function () {
|
|
179
|
+
var onChange = spy();
|
|
180
|
+
var onAccept = spy();
|
|
181
|
+
var onClose = spy();
|
|
182
|
+
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
183
|
+
onChange: onChange,
|
|
184
|
+
onAccept: onAccept,
|
|
185
|
+
onClose: onClose,
|
|
186
|
+
open: true,
|
|
187
|
+
defaultValue: values[0],
|
|
188
|
+
componentsProps: {
|
|
189
|
+
actionBar: {
|
|
190
|
+
actions: ['accept']
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
closeOnSelect: false
|
|
194
|
+
}));
|
|
195
|
+
|
|
196
|
+
// Accept the modifications
|
|
197
|
+
userEvent.mousePress(screen.getByText(/ok/i));
|
|
198
|
+
expect(onChange.callCount).to.equal(1);
|
|
199
|
+
expect(onAccept.callCount).to.equal(1);
|
|
200
|
+
expect(onClose.callCount).to.equal(1);
|
|
201
|
+
});
|
|
202
|
+
it('should call onClose but not onAccept when validating an already validated value', function () {
|
|
203
|
+
var onChange = spy();
|
|
204
|
+
var onAccept = spy();
|
|
205
|
+
var onClose = spy();
|
|
206
|
+
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
207
|
+
onChange: onChange,
|
|
208
|
+
onAccept: onAccept,
|
|
209
|
+
onClose: onClose,
|
|
210
|
+
open: true,
|
|
211
|
+
value: values[0],
|
|
212
|
+
componentsProps: {
|
|
213
|
+
actionBar: {
|
|
214
|
+
actions: ['accept']
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
closeOnSelect: false
|
|
218
|
+
}));
|
|
219
|
+
|
|
220
|
+
// Accept the modifications
|
|
221
|
+
userEvent.mousePress(screen.getByText(/ok/i));
|
|
222
|
+
expect(onChange.callCount).to.equal(0);
|
|
223
|
+
expect(onAccept.callCount).to.equal(0);
|
|
224
|
+
expect(onClose.callCount).to.equal(1);
|
|
225
|
+
});
|
|
177
226
|
});
|
|
178
227
|
});
|
|
179
228
|
};
|
|
@@ -147,7 +147,7 @@ export var testPickerOpenCloseLifeCycle = function testPickerOpenCloseLifeCycle(
|
|
|
147
147
|
onAccept: onAccept,
|
|
148
148
|
onClose: onClose,
|
|
149
149
|
open: true,
|
|
150
|
-
|
|
150
|
+
value: values[0],
|
|
151
151
|
closeOnSelect: true
|
|
152
152
|
}));
|
|
153
153
|
|
|
@@ -252,10 +252,10 @@ export var testPickerOpenCloseLifeCycle = function testPickerOpenCloseLifeCycle(
|
|
|
252
252
|
}
|
|
253
253
|
expect(onClose.callCount).to.equal(1);
|
|
254
254
|
});
|
|
255
|
-
it('should call onClose when clicking outside of the picker without prior change', function () {
|
|
255
|
+
it('should call onClose when clicking outside of the picker without prior change', function test() {
|
|
256
256
|
// TODO: Fix this test and enable it on mobile and date-range
|
|
257
257
|
if (pickerParams.variant === 'mobile' || pickerParams.type === 'date-range') {
|
|
258
|
-
|
|
258
|
+
this.skip();
|
|
259
259
|
}
|
|
260
260
|
var onChange = spy();
|
|
261
261
|
var onAccept = spy();
|
|
@@ -264,7 +264,7 @@ export var testPickerOpenCloseLifeCycle = function testPickerOpenCloseLifeCycle(
|
|
|
264
264
|
onChange: onChange,
|
|
265
265
|
onAccept: onAccept,
|
|
266
266
|
onClose: onClose,
|
|
267
|
-
|
|
267
|
+
value: values[0],
|
|
268
268
|
open: true,
|
|
269
269
|
closeOnSelect: false
|
|
270
270
|
}));
|
|
@@ -275,10 +275,10 @@ export var testPickerOpenCloseLifeCycle = function testPickerOpenCloseLifeCycle(
|
|
|
275
275
|
expect(onAccept.callCount).to.equal(0);
|
|
276
276
|
expect(onClose.callCount).to.equal(1);
|
|
277
277
|
});
|
|
278
|
-
it('should call onClose and onAccept with the live value when clicking outside of the picker', function () {
|
|
278
|
+
it('should call onClose and onAccept with the live value when clicking outside of the picker', function test() {
|
|
279
279
|
// TODO: Fix this test and enable it on mobile and date-range
|
|
280
280
|
if (pickerParams.variant === 'mobile' || pickerParams.type === 'date-range') {
|
|
281
|
-
|
|
281
|
+
this.skip();
|
|
282
282
|
}
|
|
283
283
|
var onChange = spy();
|
|
284
284
|
var onAccept = spy();
|