Skip to content

Commit 253c966

Browse files
Work on tests
1 parent 52da400 commit 253c966

File tree

17 files changed

+110
-91
lines changed

17 files changed

+110
-91
lines changed

packages/x-date-pickers-pro/src/DesktopDateRangePicker/tests/describes.DesktopDateRangePicker.test.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('<DesktopDateRangePicker /> - Describes', () => {
2929
componentFamily: 'picker',
3030
views: ['day'],
3131
variant: 'desktop',
32+
fieldType: 'single-input',
3233
}));
3334

3435
describeConformance(<DesktopDateRangePicker />, () => ({
@@ -53,6 +54,7 @@ describe('<DesktopDateRangePicker /> - Describes', () => {
5354
type: 'date-range',
5455
variant: 'desktop',
5556
initialFocus: 'start',
57+
fieldType: 'multi-input',
5658
clock,
5759
values: [
5860
// initial start and end dates
@@ -109,7 +111,7 @@ describe('<DesktopDateRangePicker /> - Describes', () => {
109111
type: 'date-range',
110112
variant: 'desktop',
111113
initialFocus: 'start',
112-
isSingleInput: true,
114+
fieldType: 'single-input',
113115
defaultProps: {
114116
slots: { field: SingleInputDateRangeField },
115117
},

packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/tests/describes.DesktopDateTimeRangePicker.test.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('<DesktopDateTimeRangePicker /> - Describes', () => {
2929
views: ['day', 'hours', 'minutes'],
3030
componentFamily: 'picker',
3131
variant: 'desktop',
32+
fieldType: 'single-input',
3233
}));
3334

3435
describeConformance(<DesktopDateTimeRangePicker />, () => ({
@@ -53,6 +54,7 @@ describe('<DesktopDateTimeRangePicker /> - Describes', () => {
5354
type: 'date-time-range',
5455
variant: 'desktop',
5556
initialFocus: 'start',
57+
fieldType: 'multi-input',
5658
clock,
5759
values: [
5860
// initial start and end dates

packages/x-date-pickers-pro/src/MobileDateRangePicker/tests/describes.MobileDateRangePicker.test.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('<MobileDateRangePicker /> - Describes', () => {
3030
componentFamily: 'picker',
3131
views: ['day'],
3232
variant: 'mobile',
33+
fieldType: 'single-input',
3334
}));
3435

3536
describeConformance(<MobileDateRangePicker />, () => ({
@@ -54,6 +55,7 @@ describe('<MobileDateRangePicker /> - Describes', () => {
5455
type: 'date-range',
5556
variant: 'mobile',
5657
initialFocus: 'start',
58+
fieldType: 'multi-input',
5759
clock,
5860
values: [
5961
// initial start and end dates
@@ -86,7 +88,7 @@ describe('<MobileDateRangePicker /> - Describes', () => {
8688
}
8789

8890
if (!isOpened) {
89-
openPicker({ type: 'date-range', initialFocus: 'start' });
91+
openPicker({ type: 'date-range', initialFocus: 'start', fieldType: 'multi-input' });
9092
}
9193

9294
fireEvent.click(
@@ -112,7 +114,7 @@ describe('<MobileDateRangePicker /> - Describes', () => {
112114
type: 'date-range',
113115
variant: 'mobile',
114116
initialFocus: 'start',
115-
isSingleInput: true,
117+
fieldType: 'multi-input',
116118
defaultProps: {
117119
slots: { field: SingleInputDateRangeField },
118120
},

packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/tests/describes.MobileDateTimeRangePicker.test.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('<MobileDateTimeRangePicker /> - Describes', () => {
3030
views: ['day', 'hours', 'minutes'],
3131
componentFamily: 'picker',
3232
variant: 'mobile',
33+
fieldType: 'single-input',
3334
}));
3435

3536
describeConformance(<MobileDateTimeRangePicker />, () => ({
@@ -54,6 +55,7 @@ describe('<MobileDateTimeRangePicker /> - Describes', () => {
5455
type: 'date-time-range',
5556
variant: 'mobile',
5657
initialFocus: 'start',
58+
fieldType: 'multi-input',
5759
clock,
5860
values: [
5961
// initial start and end dates
@@ -89,6 +91,7 @@ describe('<MobileDateTimeRangePicker /> - Describes', () => {
8991
openPicker({
9092
type: 'date-time-range',
9193
initialFocus: setEndDate ? 'end' : 'start',
94+
fieldType: 'multi-input',
9295
});
9396
}
9497
let newValue: PickerNonNullableRangeValue;
@@ -157,6 +160,7 @@ describe('<MobileDateTimeRangePicker /> - Describes', () => {
157160
type: 'date-time-range',
158161
variant: 'mobile',
159162
initialFocus: 'start',
163+
fieldType: 'single-input',
160164
clock,
161165
values: [
162166
// initial start and end dates

packages/x-date-pickers-pro/src/MultiInputDateRangeField/tests/describes.MultiInputDateRangeField.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('<MultiInputDateRangeField />', () => {
2424
render,
2525
clock,
2626
componentFamily: 'field',
27+
fieldType: 'multi-input',
2728
views: ['year', 'month', 'day'],
2829
setValue: (value, { setEndDate } = {}) => {
2930
setValueOnFieldInput(adapterToUse.format(value, 'keyboardDate'), setEndDate ? 1 : 0);

packages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/tests/describes.MultiInputDateTimeRangeField.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('<MultiInputDateTimeRangeField />', () => {
2424
render,
2525
clock,
2626
componentFamily: 'field',
27+
fieldType: 'multi-input',
2728
views: ['year', 'month', 'day', 'hours', 'minutes'],
2829
setValue: (value, { setEndDate } = {}) => {
2930
setValueOnFieldInput(adapterToUse.format(value, 'keyboardDateTime12h'), setEndDate ? 1 : 0);

packages/x-date-pickers-pro/src/MultiInputTimeRangeField/tests/describes.MultiInputTimeRangeField.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('<MultiInputTimeRangeField />', () => {
2525
clock,
2626
componentFamily: 'field',
2727
views: ['hours', 'minutes'],
28+
fieldType: 'multi-input',
2829
setValue: (value, { setEndDate } = {}) => {
2930
setValueOnFieldInput(
3031
adapterToUse.format(

packages/x-date-pickers-pro/src/SingleInputDateRangeField/tests/describes.SingleInputDateRangeField.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ describe('<SingleInputDateRangeField /> - Describes', () => {
2121
clock,
2222
componentFamily: 'field',
2323
views: ['year', 'month', 'day'],
24-
isSingleInput: true,
24+
fieldType: 'single-input',
2525
}));
2626
});

packages/x-date-pickers-pro/src/SingleInputDateTimeRangeField/tests/describes.SingleInputDateTimeRangeField.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ describe('<SingleInputDateTimeRangeField /> - Describes', () => {
2020
clock,
2121
componentFamily: 'field',
2222
views: ['year', 'month', 'day', 'hours', 'minutes', 'seconds'],
23-
isSingleInput: true,
23+
fieldType: 'single-input',
2424
}));
2525
});

packages/x-date-pickers-pro/src/SingleInputTimeRangeField/tests/describes.SingleInputTimeRangeField.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ describe('<SingleInputTimeRangeField /> - Describes', () => {
2020
clock,
2121
componentFamily: 'field',
2222
views: ['hours', 'minutes', 'seconds'],
23-
isSingleInput: true,
23+
fieldType: 'single-input',
2424
}));
2525
});

packages/x-date-pickers-pro/src/StaticDateRangePicker/StaticDateRangePicker.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('<StaticDateRangePicker />', () => {
3434
componentFamily: 'static-picker',
3535
views: ['day'],
3636
variant: 'mobile',
37+
fieldType: 'no-input',
3738
}));
3839

3940
it('allows disabling dates', () => {

test/utils/pickers/describeRangeValidation/describeRangeValidation.types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ interface DescribeRangeValidationKeyboardOptions {
1313
export interface DescribeRangeValidationInputOptions
1414
extends DescribeValidationInputOptions,
1515
DescribeRangeValidationKeyboardOptions {
16-
isSingleInput?: boolean;
16+
fieldType: 'single-input' | 'multi-input' | 'no-input';
1717
}
1818

1919
export interface DescribeRangeValidationOptions
2020
extends DescribeValidationOptions,
2121
DescribeRangeValidationKeyboardOptions {
22-
isSingleInput?: boolean;
22+
fieldType: 'single-input' | 'multi-input' | 'no-input';
2323
}
2424

2525
export type DescribeRangeValidationTestSuite = (

test/utils/pickers/describeRangeValidation/testTextFieldKeyboardRangeValidation.tsx

+28-24
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { act } from '@mui/internal-test-utils/createRenderer';
66
import { describeSkipIf, testSkipIf } from 'test/utils/skipIf';
77
import { DescribeRangeValidationTestSuite } from './describeRangeValidation.types';
88

9-
const testInvalidStatus = (expectedAnswer: boolean[], isSingleInput?: boolean) => {
10-
const answers = isSingleInput ? [expectedAnswer[0] || expectedAnswer[1]] : expectedAnswer;
9+
const testInvalidStatus = (
10+
expectedAnswer: boolean[],
11+
fieldType: 'single-input' | 'multi-input' | 'no-input',
12+
) => {
13+
const answers =
14+
fieldType === 'multi-input' ? expectedAnswer : [expectedAnswer[0] || expectedAnswer[1]];
1115

1216
const fieldInputRoots = getAllFieldInputRoot();
1317
answers.forEach((answer, index) => {
@@ -21,7 +25,7 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
2125
ElementToTest,
2226
getOptions,
2327
) => {
24-
const { componentFamily, render, isSingleInput, withDate, withTime, setValue } = getOptions();
28+
const { componentFamily, render, fieldType, withDate, withTime, setValue } = getOptions();
2529

2630
describeSkipIf(componentFamily !== 'field' || !setValue)('text field keyboard:', () => {
2731
// eslint-disable-next-line @typescript-eslint/no-shadow
@@ -42,7 +46,7 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
4246
});
4347
expect(onErrorMock.callCount).to.equal(1);
4448
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['invalidRange', 'invalidRange']);
45-
testInvalidStatus([true, true], isSingleInput);
49+
testInvalidStatus([true, true], fieldType);
4650
});
4751

4852
testSkipIf(!withDate)('should apply shouldDisableDate', () => {
@@ -62,15 +66,15 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
6266
});
6367

6468
expect(onErrorMock.callCount).to.equal(0);
65-
testInvalidStatus([false, false], isSingleInput);
69+
testInvalidStatus([false, false], fieldType);
6670

6771
act(() => {
6872
setValue(adapterToUse.date('2018-03-13'), { setEndDate: true });
6973
});
7074

7175
expect(onErrorMock.callCount).to.equal(1);
7276
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'shouldDisableDate']);
73-
testInvalidStatus([false, true], isSingleInput);
77+
testInvalidStatus([false, true], fieldType);
7478

7579
act(() => {
7680
setValue(adapterToUse.date('2018-03-12'));
@@ -81,15 +85,15 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
8185
'shouldDisableDate',
8286
'shouldDisableDate',
8387
]);
84-
testInvalidStatus([true, true], isSingleInput);
88+
testInvalidStatus([true, true], fieldType);
8589

8690
setProps({
8791
shouldDisableDate: (date) => adapterToUse.isBefore(date, adapterToUse.date('2018-03-13')),
8892
});
8993

9094
expect(onErrorMock.callCount).to.equal(3);
9195
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['shouldDisableDate', null]);
92-
testInvalidStatus([true, false], isSingleInput);
96+
testInvalidStatus([true, false], fieldType);
9397
});
9498

9599
it('should apply disablePast', () => {
@@ -114,22 +118,22 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
114118

115119
expect(onErrorMock.callCount).to.equal(1);
116120
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['disablePast', null]);
117-
testInvalidStatus([true, false], isSingleInput);
121+
testInvalidStatus([true, false], fieldType);
118122

119123
act(() => {
120124
setValue(past, { setEndDate: true });
121125
});
122126

123127
expect(onErrorMock.callCount).to.equal(2);
124128
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['disablePast', 'disablePast']);
125-
testInvalidStatus([true, true], isSingleInput);
129+
testInvalidStatus([true, true], fieldType);
126130

127131
act(() => {
128132
setValue(now);
129133
});
130134
expect(onErrorMock.callCount).to.equal(3);
131135
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'disablePast']);
132-
testInvalidStatus([false, true], isSingleInput);
136+
testInvalidStatus([false, true], fieldType);
133137
});
134138

135139
it('should apply disableFuture', () => {
@@ -155,23 +159,23 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
155159

156160
expect(onErrorMock.callCount).to.equal(1);
157161
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'disableFuture']);
158-
testInvalidStatus([false, true], isSingleInput);
162+
testInvalidStatus([false, true], fieldType);
159163

160164
act(() => {
161165
setValue(future);
162166
});
163167

164168
expect(onErrorMock.callCount).to.equal(2);
165169
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['disableFuture', 'disableFuture']);
166-
testInvalidStatus([true, true], isSingleInput);
170+
testInvalidStatus([true, true], fieldType);
167171

168172
act(() => {
169173
setValue(now);
170174
});
171175

172176
expect(onErrorMock.callCount).to.equal(3);
173177
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'disableFuture']);
174-
testInvalidStatus([false, true], isSingleInput);
178+
testInvalidStatus([false, true], fieldType);
175179
});
176180

177181
testSkipIf(!withDate)('should apply minDate', () => {
@@ -188,23 +192,23 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
188192

189193
expect(onErrorMock.callCount).to.equal(2);
190194
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['minDate', 'minDate']);
191-
testInvalidStatus([true, true], isSingleInput);
195+
testInvalidStatus([true, true], fieldType);
192196

193197
act(() => {
194198
setValue(adapterToUse.date('2018-03-15'));
195199
});
196200

197201
expect(onErrorMock.callCount).to.equal(3);
198202
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'minDate']);
199-
testInvalidStatus([false, true], isSingleInput);
203+
testInvalidStatus([false, true], fieldType);
200204

201205
act(() => {
202206
setValue(adapterToUse.date('2018-03-16'), { setEndDate: true });
203207
});
204208

205209
expect(onErrorMock.callCount).to.equal(4);
206210
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
207-
testInvalidStatus([false, false], isSingleInput);
211+
testInvalidStatus([false, false], fieldType);
208212
});
209213

210214
testSkipIf(!withDate)('should apply maxDate', () => {
@@ -221,15 +225,15 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
221225

222226
expect(onErrorMock.callCount).to.equal(1);
223227
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'maxDate']);
224-
testInvalidStatus([false, true], isSingleInput);
228+
testInvalidStatus([false, true], fieldType);
225229

226230
act(() => {
227231
setValue(adapterToUse.date('2018-03-16'));
228232
});
229233

230234
expect(onErrorMock.callCount).to.equal(2);
231235
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['maxDate', 'maxDate']);
232-
testInvalidStatus([true, true], isSingleInput);
236+
testInvalidStatus([true, true], fieldType);
233237
});
234238

235239
testSkipIf(!withTime)('should apply minTime', () => {
@@ -249,23 +253,23 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
249253

250254
expect(onErrorMock.callCount).to.equal(2);
251255
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['minTime', 'minTime']);
252-
testInvalidStatus([true, true], isSingleInput);
256+
testInvalidStatus([true, true], fieldType);
253257

254258
act(() => {
255259
setValue(adapterToUse.date('2018-03-10T12:10:00'), { setEndDate: true });
256260
});
257261

258262
expect(onErrorMock.callCount).to.equal(3);
259263
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['minTime', null]);
260-
testInvalidStatus([true, false], isSingleInput);
264+
testInvalidStatus([true, false], fieldType);
261265

262266
act(() => {
263267
setValue(adapterToUse.date('2018-03-10T12:05:00'));
264268
});
265269

266270
expect(onErrorMock.callCount).to.equal(4);
267271
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
268-
testInvalidStatus([false, false], isSingleInput);
272+
testInvalidStatus([false, false], fieldType);
269273
});
270274

271275
testSkipIf(!withTime)('should apply maxTime', () => {
@@ -285,15 +289,15 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
285289

286290
expect(onErrorMock.callCount).to.equal(1);
287291
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'maxTime']);
288-
testInvalidStatus([false, true], isSingleInput);
292+
testInvalidStatus([false, true], fieldType);
289293

290294
act(() => {
291295
setValue(adapterToUse.date('2018-03-10T12:05:00'));
292296
});
293297

294298
expect(onErrorMock.callCount).to.equal(2);
295299
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['maxTime', 'maxTime']);
296-
testInvalidStatus([true, true], isSingleInput);
300+
testInvalidStatus([true, true], fieldType);
297301
});
298302
});
299303
};

0 commit comments

Comments
 (0)