Skip to content

Commit 3e19a58

Browse files
committed
more test case
1 parent 2e598cd commit 3e19a58

File tree

3 files changed

+185
-96
lines changed

3 files changed

+185
-96
lines changed

tests/cursor.test.tsx

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import React from 'react';
2+
import KeyCode from 'rc-util/lib/KeyCode';
3+
import { mount } from './util/wrapper';
4+
import InputNumber from '../src';
5+
6+
describe.skip('InputNumber.Cursor', () => {
7+
// https://github.com/react-component/input-number/issues/235
8+
// TODO: handle this
9+
describe('cursor position', () => {
10+
it('w', () => {});
11+
// const setUpCursorTest = (
12+
// initialValue,
13+
// changedValue,
14+
// keyCodeValue,
15+
// selectionStart,
16+
// selectionEnd,
17+
// ) => {
18+
// class Demo extends React.Component {
19+
// onChange = (value) => {
20+
// this.setState({ value });
21+
// };
22+
// render() {
23+
// return <InputNumber ref="inputNum" value={initialValue} onChange={this.onChange} />;
24+
// }
25+
// }
26+
// example = ReactDOM.render(<Demo />, container);
27+
// inputNumber = example.refs.inputNum;
28+
// inputNumber.input.selectionStart = selectionStart;
29+
// inputNumber.input.selectionEnd = selectionEnd || selectionStart;
30+
// inputElement = ReactDOM.findDOMNode(inputNumber.input);
31+
// Simulate.focus(inputElement);
32+
// Simulate.keyDown(inputElement, { keyCode: keyCodeValue });
33+
// Simulate.change(inputElement, { target: { value: changedValue } });
34+
// };
35+
// it('should be maintained on delete with identical consecutive digits', () => {
36+
// setUpCursorTest(99999, '9999', keyCode.DELETE, 3);
37+
// expect(inputNumber.input.selectionStart).to.be(3);
38+
// });
39+
// it('should be maintained on delete with unidentical consecutive digits', () => {
40+
// setUpCursorTest(12345, '1235', keyCode.DELETE, 3);
41+
// expect(inputNumber.input.selectionStart).to.be(3);
42+
// });
43+
// it('should be one step earlier on backspace with identical consecutive digits', () => {
44+
// setUpCursorTest(99999, '9999', keyCode.BACKSPACE, 3);
45+
// expect(inputNumber.input.selectionStart).to.be(2);
46+
// });
47+
// it('should be one step earlier on backspace with unidentical consecutive digits', () => {
48+
// setUpCursorTest(12345, '1245', keyCode.BACKSPACE, 3);
49+
// expect(inputNumber.input.selectionStart).to.be(2);
50+
// });
51+
// it('should be at the start of selection on delete with identical consecutive digits', () => {
52+
// setUpCursorTest(99999, '999', keyCode.DELETE, 1, 3);
53+
// expect(inputNumber.input.selectionStart).to.be(1);
54+
// });
55+
// it('should be at the start of selection on delete with unidentical consecutive digits', () => {
56+
// // eslint-disable-line
57+
// setUpCursorTest(12345, '145', keyCode.DELETE, 1, 3);
58+
// expect(inputNumber.input.selectionStart).to.be(1);
59+
// });
60+
// it('should be at the start of selection on backspace with identical consecutive digits', () => {
61+
// // eslint-disable-line
62+
// setUpCursorTest(99999, '999', keyCode.BACKSPACE, 1, 3);
63+
// expect(inputNumber.input.selectionStart).to.be(1);
64+
// });
65+
// it('should be at the start of selection on backspace with unidentical consecutive digits', () => {
66+
// // eslint-disable-line
67+
// setUpCursorTest(12345, '145', keyCode.BACKSPACE, 1, 3);
68+
// expect(inputNumber.input.selectionStart).to.be(1);
69+
// });
70+
// it('should be one step later on new digit with identical consecutive digits', () => {
71+
// setUpCursorTest(99999, '999999', keyCode.NINE, 3);
72+
// expect(inputNumber.input.selectionStart).to.be(4);
73+
// });
74+
// it('should be one step later on new digit with unidentical consecutive digits', () => {
75+
// setUpCursorTest(12345, '123945', keyCode.NINE, 3);
76+
// expect(inputNumber.input.selectionStart).to.be(4);
77+
// });
78+
// it('should be one step later than the start of selection on new digit with identical consecutive digits', () => {
79+
// // eslint-disable-line
80+
// setUpCursorTest(99999, '9999', keyCode.NINE, 1, 3);
81+
// expect(inputNumber.input.selectionStart).to.be(2);
82+
// });
83+
// it('should be one step later than the start of selection on new digit with unidentical consecutive digits', () => {
84+
// // eslint-disable-line
85+
// setUpCursorTest(12345, '1945', keyCode.NINE, 1, 3);
86+
// expect(inputNumber.input.selectionStart).to.be(2);
87+
// });
88+
});
89+
90+
// https://github.com/ant-design/ant-design/issues/28366
91+
// describe('cursor position when last string exists', () => {
92+
// // const setUpCursorTest = (initValue, prependValue) => {
93+
// // class Demo extends React.Component {
94+
// // state = {
95+
// // value: initValue,
96+
// // };
97+
98+
// // onChange = value => {
99+
// // this.setState({ value });
100+
// // };
101+
102+
// // render() {
103+
// // return (
104+
// // <InputNumber
105+
// // ref="inputNum"
106+
// // value={this.state.value}
107+
// // onChange={this.onChange}
108+
// // formatter={value => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
109+
// // parser={value => value.replace(/\$\s?|(,*)/g, '')}
110+
// // />
111+
// // );
112+
// // }
113+
// // }
114+
// // example = ReactDOM.render(<Demo />, container);
115+
// // inputNumber = example.refs.inputNum;
116+
// // inputNumber.input.selectionStart = 0;
117+
// // inputNumber.input.selectionEnd = 0;
118+
// // inputElement = ReactDOM.findDOMNode(inputNumber.input);
119+
// // Simulate.focus(inputElement);
120+
// // for (let i = 0; i < prependValue.length; i += 1) {
121+
// // Simulate.keyDown(inputElement, { keyCode: keyCode.ONE });
122+
// // }
123+
// // Simulate.change(inputElement, { target: { value: prependValue + initValue } });
124+
// // };
125+
126+
// // it('shold fix caret position on case 1', () => {
127+
// // // '$ 1'
128+
// // setUpCursorTest('', '1');
129+
// // expect(inputNumber.input.selectionStart).to.be(3);
130+
// // });
131+
// // it('shold fix caret position on case 2', () => {
132+
// // // '$ 111'
133+
// // setUpCursorTest('', '111');
134+
// // expect(inputNumber.input.selectionStart).to.be(5);
135+
// // });
136+
// // it('shold fix caret position on case 3', () => {
137+
// // // '$ 111'
138+
// // setUpCursorTest('1', '11');
139+
// // expect(inputNumber.input.selectionStart).to.be(4);
140+
// // });
141+
// // it('shold fix caret position on case 4', () => {
142+
// // // '$ 123,456'
143+
// // setUpCursorTest('456', '123');
144+
// // expect(inputNumber.input.selectionStart).to.be(6);
145+
// // });
146+
// });
147+
});

tests/github.test.tsx

Lines changed: 8 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -418,102 +418,15 @@ describe('InputNumber.Github', () => {
418418
};
419419

420420
const wrapper = mount(<Demo />);
421-
wrapper.find('input').last().simulate('change', { target: { value: '1.23' } });
422-
wrapper.find('input').first().simulate('change', { target: { value: '0' } });
421+
wrapper
422+
.find('input')
423+
.last()
424+
.simulate('change', { target: { value: '1.23' } });
425+
wrapper
426+
.find('input')
427+
.first()
428+
.simulate('change', { target: { value: '0' } });
423429

424430
expect(wrapper.find('input').last().props().value).toEqual('1');
425431
});
426-
427-
// // https://github.com/react-component/input-number/issues/235
428-
// describe('cursor position', () => {
429-
// const setUpCursorTest = (
430-
// initialValue,
431-
// changedValue,
432-
// keyCodeValue,
433-
// selectionStart,
434-
// selectionEnd,
435-
// ) => {
436-
// class Demo extends React.Component {
437-
// onChange = (value) => {
438-
// this.setState({ value });
439-
// };
440-
// render() {
441-
// return <InputNumber ref="inputNum" value={initialValue} onChange={this.onChange} />;
442-
// }
443-
// }
444-
// example = ReactDOM.render(<Demo />, container);
445-
// inputNumber = example.refs.inputNum;
446-
// inputNumber.input.selectionStart = selectionStart;
447-
// inputNumber.input.selectionEnd = selectionEnd || selectionStart;
448-
// inputElement = ReactDOM.findDOMNode(inputNumber.input);
449-
// Simulate.focus(inputElement);
450-
// Simulate.keyDown(inputElement, { keyCode: keyCodeValue });
451-
// Simulate.change(inputElement, { target: { value: changedValue } });
452-
// };
453-
454-
// it('should be maintained on delete with identical consecutive digits', () => {
455-
// setUpCursorTest(99999, '9999', keyCode.DELETE, 3);
456-
// expect(inputNumber.input.selectionStart).to.be(3);
457-
// });
458-
459-
// it('should be maintained on delete with unidentical consecutive digits', () => {
460-
// setUpCursorTest(12345, '1235', keyCode.DELETE, 3);
461-
// expect(inputNumber.input.selectionStart).to.be(3);
462-
// });
463-
464-
// it('should be one step earlier on backspace with identical consecutive digits', () => {
465-
// setUpCursorTest(99999, '9999', keyCode.BACKSPACE, 3);
466-
// expect(inputNumber.input.selectionStart).to.be(2);
467-
// });
468-
469-
// it('should be one step earlier on backspace with unidentical consecutive digits', () => {
470-
// setUpCursorTest(12345, '1245', keyCode.BACKSPACE, 3);
471-
// expect(inputNumber.input.selectionStart).to.be(2);
472-
// });
473-
474-
// it('should be at the start of selection on delete with identical consecutive digits', () => {
475-
// setUpCursorTest(99999, '999', keyCode.DELETE, 1, 3);
476-
// expect(inputNumber.input.selectionStart).to.be(1);
477-
// });
478-
479-
// it('should be at the start of selection on delete with unidentical consecutive digits', () => {
480-
// // eslint-disable-line
481-
// setUpCursorTest(12345, '145', keyCode.DELETE, 1, 3);
482-
// expect(inputNumber.input.selectionStart).to.be(1);
483-
// });
484-
485-
// it('should be at the start of selection on backspace with identical consecutive digits', () => {
486-
// // eslint-disable-line
487-
// setUpCursorTest(99999, '999', keyCode.BACKSPACE, 1, 3);
488-
// expect(inputNumber.input.selectionStart).to.be(1);
489-
// });
490-
491-
// it('should be at the start of selection on backspace with unidentical consecutive digits', () => {
492-
// // eslint-disable-line
493-
// setUpCursorTest(12345, '145', keyCode.BACKSPACE, 1, 3);
494-
// expect(inputNumber.input.selectionStart).to.be(1);
495-
// });
496-
497-
// it('should be one step later on new digit with identical consecutive digits', () => {
498-
// setUpCursorTest(99999, '999999', keyCode.NINE, 3);
499-
// expect(inputNumber.input.selectionStart).to.be(4);
500-
// });
501-
502-
// it('should be one step later on new digit with unidentical consecutive digits', () => {
503-
// setUpCursorTest(12345, '123945', keyCode.NINE, 3);
504-
// expect(inputNumber.input.selectionStart).to.be(4);
505-
// });
506-
507-
// it('should be one step later than the start of selection on new digit with identical consecutive digits', () => {
508-
// // eslint-disable-line
509-
// setUpCursorTest(99999, '9999', keyCode.NINE, 1, 3);
510-
// expect(inputNumber.input.selectionStart).to.be(2);
511-
// });
512-
513-
// it('should be one step laterthan the start of selection on new digit with unidentical consecutive digits', () => {
514-
// // eslint-disable-line
515-
// setUpCursorTest(12345, '1945', keyCode.NINE, 1, 3);
516-
// expect(inputNumber.input.selectionStart).to.be(2);
517-
// });
518-
// });
519432
});

tests/props.test.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('InputNumber.Props', () => {
203203
});
204204

205205
it('invalidate defaultValue', () => {
206-
const wrapper = mount(<InputNumber defaultValue="light" />);
206+
const wrapper = mount(<InputNumber defaultValue="light" />);
207207
expect(wrapper.findInput().props().value).toEqual('light');
208208
});
209209
});
@@ -273,4 +273,33 @@ describe('InputNumber.Props', () => {
273273
expect(wrapper.exists('.rc-input-number-out-of-range')).toBeFalsy();
274274
});
275275
});
276+
277+
describe(`required prop`, () => {
278+
it(`should add required attr to the input tag when get passed as true`, () => {
279+
const wrapper = mount(<InputNumber required />);
280+
expect(wrapper.findInput().props().required).toBeTruthy();
281+
});
282+
283+
it(`should not add required attr to the input as default props when not being supplied`, () => {
284+
const wrapper = mount(<InputNumber />);
285+
expect(wrapper.findInput().props().required).toBeFalsy();
286+
});
287+
288+
it(`should not add required attr to the input tag when get passed as false`, () => {
289+
const wrapper = mount(<InputNumber required={false} />);
290+
expect(wrapper.findInput().props().required).toBeFalsy();
291+
});
292+
});
293+
294+
describe('Pattern prop', () => {
295+
it(`should render with a pattern attribute if the pattern prop is supplied`, () => {
296+
const wrapper = mount(<InputNumber pattern="\d*" />);
297+
expect(wrapper.findInput().props().pattern).toEqual('\\d*');
298+
});
299+
300+
it(`should render with no pattern attribute if the pattern prop is not supplied`, () => {
301+
const wrapper = mount(<InputNumber />);
302+
expect(wrapper.findInput().props().pattern).toBeFalsy();
303+
});
304+
});
276305
});

0 commit comments

Comments
 (0)