@@ -12,6 +12,11 @@ const options = [
12
12
{ value : 'baz' , label : 'Baz' } ,
13
13
] ;
14
14
const stringOptions = [ 'foo' , 'bar' , 'baz' ] ;
15
+ const numberOptions = [
16
+ { value : 0 , label : 'Foo' } ,
17
+ { value : 1 , label : 'Bar' } ,
18
+ { value : 2 , label : 'Baz' } ,
19
+ ] ;
15
20
16
21
class SelectController extends React . Component {
17
22
state = {
@@ -134,6 +139,18 @@ describe('Select widget', () => {
134
139
expect ( getByText ( 'baz' ) ) . toBeInTheDocument ( ) ;
135
140
} ) ;
136
141
142
+ it ( 'should call onChange with correct selectedItem when value is number 0' , ( ) => {
143
+ const field = fromJS ( { options : numberOptions } ) ;
144
+ const { getByText, input, onChangeSpy } = setup ( { field } ) ;
145
+
146
+ fireEvent . focus ( input ) ;
147
+ fireEvent . keyDown ( input , { key : 'ArrowDown' } ) ;
148
+ fireEvent . click ( getByText ( 'Foo' ) ) ;
149
+
150
+ expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
151
+ expect ( onChangeSpy ) . toHaveBeenCalledWith ( numberOptions [ 0 ] . value ) ;
152
+ } ) ;
153
+
137
154
describe ( 'with multiple' , ( ) => {
138
155
it ( 'should call onChange with correct selectedItem' , ( ) => {
139
156
const field = fromJS ( { options, multiple : true } ) ;
@@ -248,6 +265,22 @@ describe('Select widget', () => {
248
265
expect ( getByText ( 'bar' ) ) . toBeInTheDocument ( ) ;
249
266
expect ( getByText ( 'baz' ) ) . toBeInTheDocument ( ) ;
250
267
} ) ;
268
+
269
+ it ( 'should call onChange with correct selectedItem when values are numbers including 0' , ( ) => {
270
+ const field = fromJS ( { options : numberOptions , multiple : true } ) ;
271
+ const { getByText, input, onChangeSpy } = setup ( { field } ) ;
272
+
273
+ fireEvent . keyDown ( input , { key : 'ArrowDown' } ) ;
274
+ fireEvent . click ( getByText ( 'Foo' ) ) ;
275
+ fireEvent . keyDown ( input , { key : 'ArrowDown' } ) ;
276
+ fireEvent . click ( getByText ( 'Baz' ) ) ;
277
+
278
+ expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
279
+ expect ( onChangeSpy ) . toHaveBeenCalledWith ( fromJS ( [ numberOptions [ 0 ] . value ] ) ) ;
280
+ expect ( onChangeSpy ) . toHaveBeenCalledWith (
281
+ fromJS ( [ numberOptions [ 0 ] . value , numberOptions [ 2 ] . value ] ) ,
282
+ ) ;
283
+ } ) ;
251
284
} ) ;
252
285
describe ( 'validation' , ( ) => {
253
286
function validate ( setupOpts ) {
0 commit comments