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