Skip to content

Commit 78db2e3

Browse files
committed
test: Fill range test case
1 parent 623c0c1 commit 78db2e3

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

src/Picker.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import * as React from 'react';
1515
import classNames from 'classnames';
1616
import { AlignType } from 'rc-trigger/lib/interface';
17+
import { warning } from 'rc-util/lib/warning';
1718
import PickerPanel, {
1819
PickerPanelBaseProps,
1920
PickerPanelDateProps,
@@ -230,7 +231,16 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
230231
// Let popup panel handle keyboard
231232
return operationRef.current.onKeyDown(e);
232233
}
233-
return false;
234+
235+
/* istanbul ignore next */
236+
/* eslint-disable no-lone-blocks */
237+
{
238+
warning(
239+
false,
240+
'Picker not correct forward KeyDown operation. Please help to fire issue about this.',
241+
);
242+
return false;
243+
}
234244
};
235245

236246
// ============================= Text ==============================

src/RangePicker.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import classNames from 'classnames';
3+
import warning from 'rc-util/lib/warning';
34
import {
45
DisabledTimes,
56
PanelMode,
@@ -69,11 +70,6 @@ function canValueTrigger<DateType>(
6970
return true;
7071
}
7172

72-
// If another one is disabled, this can be trigger
73-
if (disabledList[(index + 1) % 2]) {
74-
return true;
75-
}
76-
7773
return false;
7874
}
7975

@@ -620,6 +616,21 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
620616
setSelectedValue(mergedValue);
621617
}, [mergedValue]);
622618

619+
// ============================ Warning ============================
620+
if (process.env.NODE_ENV !== 'production') {
621+
if (
622+
value &&
623+
Array.isArray(disabled) &&
624+
((getValue(disabled, 0) && !getValue(value, 0)) ||
625+
(getValue(disabled, 1) && !getValue(value, 1)))
626+
) {
627+
warning(
628+
false,
629+
'`disabled` should not set with empty `value`. You should set `allowEmpty` or `value` instead.',
630+
);
631+
}
632+
}
633+
623634
// ============================ Private ============================
624635
if (pickerRef) {
625636
pickerRef.current = {

tests/range.spec.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,16 @@ describe('Picker.Range', () => {
250250
);
251251
});
252252

253-
it('allowEmpty with disabled', () => {
254-
const onChange = jest.fn();
255-
const wrapper = mount(
256-
<MomentRangePicker
257-
disabled={[false, true]}
258-
allowEmpty={[false, true]}
259-
onChange={onChange}
260-
/>,
253+
it('null value with disabled', () => {
254+
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
255+
mount(
256+
<MomentRangePicker disabled={[false, true]} value={[null, null]} />,
261257
);
262258

263-
wrapper.openPicker();
264-
wrapper.selectCell(11);
265-
expect(onChange.mock.calls[0][1]).toEqual(['1990-09-11', '']);
259+
expect(errSpy).toHaveBeenCalledWith(
260+
'Warning: `disabled` should not set with empty `value`. You should set `allowEmpty` or `value` instead.',
261+
);
262+
errSpy.mockReset();
266263
});
267264
});
268265

@@ -569,6 +566,7 @@ describe('Picker.Range', () => {
569566

570567
// Select to active next
571568
wrapper.selectCell(11);
569+
jest.runAllTimers();
572570
expect(
573571
wrapper
574572
.find('.rc-picker-input')
@@ -619,4 +617,17 @@ describe('Picker.Range', () => {
619617
});
620618
});
621619
});
620+
621+
it('should close when user focus out', () => {
622+
const wrapper = mount(<MomentRangePicker />);
623+
wrapper.openPicker();
624+
wrapper.selectCell(11);
625+
expect(wrapper.isOpen()).toBeTruthy();
626+
627+
wrapper
628+
.find('input')
629+
.last()
630+
.simulate('blur');
631+
expect(wrapper.isOpen()).toBeFalsy();
632+
});
622633
});

0 commit comments

Comments
 (0)