@@ -74,4 +74,70 @@ describe('InputNumber.Decimal', () => {
7474 expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toEqual ( '1,1' ) ;
7575 expect ( onChange ) . toHaveBeenCalledWith ( 1.1 ) ;
7676 } ) ;
77+
78+ describe ( 'precision' , ( ) => {
79+ it ( 'decimal step should not display complete precision' , ( ) => {
80+ const wrapper = mount ( < InputNumber step = { 0.01 } value = { 2.1 } /> ) ;
81+ expect ( wrapper . findInput ( ) . props ( ) . value ) . toEqual ( '2.10' ) ;
82+ } ) ;
83+
84+ it ( 'string step should display complete precision' , ( ) => {
85+ const wrapper = mount ( < InputNumber step = "1.000" value = { 2.1 } /> ) ;
86+ expect ( wrapper . findInput ( ) . props ( ) . value ) . toEqual ( '2.100' ) ;
87+ } ) ;
88+
89+ it ( 'prop precision is specified' , ( ) => {
90+ const onChange = jest . fn ( ) ;
91+ const wrapper = mount ( < InputNumber onChange = { onChange } precision = { 2 } defaultValue = { 2 } /> ) ;
92+ expect ( wrapper . findInput ( ) . props ( ) . value ) . toEqual ( '2.00' ) ;
93+
94+ wrapper . changeValue ( '3.456' ) ;
95+ wrapper . blurInput ( ) ;
96+ expect ( onChange ) . toHaveBeenCalledWith ( 3.46 ) ;
97+ expect ( wrapper . findInput ( ) . props ( ) . value ) . toEqual ( '3.46' ) ;
98+
99+ onChange . mockReset ( ) ;
100+ wrapper . changeValue ( '3.465' ) ;
101+ wrapper . blurInput ( ) ;
102+ expect ( onChange ) . toHaveBeenCalledWith ( 3.47 ) ;
103+ expect ( wrapper . findInput ( ) . props ( ) . value ) . toEqual ( '3.47' ) ;
104+
105+ onChange . mockReset ( ) ;
106+ wrapper . changeValue ( '3.455' ) ;
107+ wrapper . blurInput ( ) ;
108+ expect ( onChange ) . toHaveBeenCalledWith ( 3.46 ) ;
109+ expect ( wrapper . findInput ( ) . props ( ) . value ) . toEqual ( '3.46' ) ;
110+
111+ onChange . mockReset ( ) ;
112+ wrapper . changeValue ( '1' ) ;
113+ wrapper . blurInput ( ) ;
114+ expect ( onChange ) . toHaveBeenCalledWith ( 1 ) ;
115+ expect ( wrapper . findInput ( ) . props ( ) . value ) . toEqual ( '1.00' ) ;
116+ } ) ;
117+
118+ // it('should not trigger onChange when blur InputNumber with precision', () => {
119+ // class Demo extends React.Component {
120+ // onChange = () => {
121+ // onChangeCallCount += 1;
122+ // };
123+
124+ // render() {
125+ // return (
126+ // <InputNumber
127+ // ref="inputNum"
128+ // mergedPPrecision={2}
129+ // defaultValue={2}
130+ // onChange={this.onChange}
131+ // />
132+ // );
133+ // }
134+ // }
135+ // example = ReactDOM.render(<Demo />, container);
136+ // inputNumber = example.refs.inputNum;
137+ // inputElement = ReactDOM.findDOMNode(inputNumber.input);
138+ // Simulate.focus(inputElement);
139+ // Simulate.blur(inputElement);
140+ // expect(onChangeCallCount).to.be(0);
141+ // });
142+ } ) ;
77143} ) ;
0 commit comments