-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(InputItem): Adjust the caret position of the formatted value (#2854)
* Fix(InputItem): Adjust the caret position of the formatted value (#2840 #1553 #1208 #1162 #1165 #810) * refactor: remove onChange in the event loop, refactor adjustCaretPosition * Fix(InputItem): caret position problem when using android phone keyboard
- Loading branch information
Showing
2 changed files
with
74 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
// import React from 'react'; | ||
// import InputItem from '../index'; | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import InputItem from '../index'; | ||
|
||
describe('InputItem', () => { | ||
// No need to render Snapshot again, because of `./demo.test.js` | ||
it('trigger event correctly', () => { | ||
// todos: write test! | ||
expect(true).toBe(true); | ||
|
||
it('format bankCard correctly', () => { | ||
const bankCard = mount(( | ||
<InputItem | ||
type="bankCard" | ||
>银行卡</InputItem> | ||
)); | ||
bankCard.find('input').simulate('change', { target: { value: '1a23 4-5.6 7w890' } }); | ||
expect(bankCard.state('value')).toBe('1234 5678 90'); | ||
}); | ||
|
||
it('format phone correctly', () => { | ||
const phone = mount(( | ||
<InputItem | ||
type="phone" | ||
>手机号码</InputItem> | ||
)); | ||
phone.find('input').simulate('change', { target: { value: '1a23 4-5.6 7w890a123123' } }); | ||
expect(phone.state('value')).toBe('123 4567 8901'); | ||
}); | ||
|
||
it('format number correctly', () => { | ||
const number = mount(( | ||
<InputItem | ||
type="number" | ||
>数字</InputItem> | ||
)); | ||
number.find('input').simulate('change', { target: { value: '1a23 4-5.6 7w890' } }); | ||
expect(number.state('value')).toBe('1234567890'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters