Skip to content

Commit

Permalink
fix(DatePicker2): after entering a customized date format and pressin…
Browse files Browse the repository at this point in the history
…g Enter, the value should not change
  • Loading branch information
GCHHCG committed Sep 26, 2024
1 parent bd75ca8 commit eca2d43
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions components/date-picker2/__tests__/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,30 +528,6 @@ describe('Picker', () => {
wrapper.unmount();
});

it('pressing enter should correctly display the formatted value', () => {
function App() {
const [value, setValue] = useState('');
return (
<DatePicker
defaultVisible
value={value}
format={'DD/MM/YYYY'}
outputFormat="YYYY-MM-DD"
onChange={v => {
setValue(v),
assert(
v === dayjs('12/02/2020', 'DD/MM/YYYY').format('YYYY-MM-DD')
);
}}
/>
);
}
wrapper = mount(<App />);
changeInput('12/02/2020');
findInput().simulate('keydown', { keyCode: KEYCODE.ENTER });
assert(getStrValue(wrapper) === '12/02/2020');
});

it('outputFormat', () => {
wrapper = mount(
<DatePicker
Expand Down Expand Up @@ -1256,6 +1232,31 @@ describe('Picker', () => {
findInput(0).simulate('keydown', { keyCode: KEYCODE.SPACE });
assert(getStrValue(wrapper).join(',') === '2020-11-11 ,');
})

// fix https://github.com/alibaba-fusion/next/issues/4896
it('After entering a customized date format and pressing Enter, the value should not change', () => {
function App() {
const [value, setValue] = useState('');
return (
<DatePicker
defaultVisible
value={value}
format={'DD/MM/YYYY'}
outputFormat="YYYY-MM-DD"
onChange={v => {
setValue(v),
assert(
v === dayjs('12/02/2020', 'DD/MM/YYYY').format('YYYY-MM-DD')
);
}}
/>
);
}
wrapper = mount(<App />);
changeInput('12/02/2020');
findInput().simulate('keydown', { keyCode: KEYCODE.ENTER });
assert(getStrValue(wrapper) === '12/02/2020');
});
});
});

Expand Down

0 comments on commit eca2d43

Please sign in to comment.