@@ -73,8 +73,6 @@ describe('Select.Tags', () => {
73
73
</ Select > ,
74
74
) ;
75
75
76
- ( wrapper . find ( 'input' ) . instance ( ) as any ) . focus = jest . fn ( ) ;
77
-
78
76
wrapper . find ( 'input' ) . simulate ( 'change' , { target : { value : '2,3,4' } } ) ;
79
77
80
78
expect ( handleChange ) . toHaveBeenCalledWith ( [ '2' , '3' , '4' ] , expect . anything ( ) ) ;
@@ -90,15 +88,13 @@ describe('Select.Tags', () => {
90
88
it ( "shounld't separate words when compositing" , ( ) => {
91
89
const handleChange = jest . fn ( ) ;
92
90
const handleSelect = jest . fn ( ) ;
93
- const option2 = < Option value = "2" > 2</ Option > ;
94
91
const wrapper = mount (
95
92
< Select mode = "tags" tokenSeparators = { [ ',' ] } onChange = { handleChange } onSelect = { handleSelect } >
96
93
< Option value = "1" > 1</ Option >
97
- { option2 }
94
+ < Option value = "2" > 2 </ Option >
98
95
</ Select > ,
99
96
) ;
100
97
101
- ( wrapper . find ( 'input' ) . instance ( ) as any ) . focus = jest . fn ( ) ;
102
98
wrapper . find ( 'input' ) . simulate ( 'compositionstart' ) ;
103
99
wrapper . find ( 'input' ) . simulate ( 'change' , { target : { value : '2,3,4' } } ) ;
104
100
expect ( handleChange ) . not . toHaveBeenCalled ( ) ;
@@ -115,6 +111,35 @@ describe('Select.Tags', () => {
115
111
expectOpen ( wrapper , false ) ;
116
112
} ) ;
117
113
114
+ it ( 'should work when menu is closed' , ( ) => {
115
+ const handleChange = jest . fn ( ) ;
116
+ const handleSelect = jest . fn ( ) ;
117
+ const wrapper = mount (
118
+ < Select
119
+ mode = "tags"
120
+ tokenSeparators = { [ ',' ] }
121
+ onChange = { handleChange }
122
+ onSelect = { handleSelect }
123
+ open = { false }
124
+ >
125
+ < Option value = "1" > 1</ Option >
126
+ < Option value = "2" > 2</ Option >
127
+ </ Select > ,
128
+ ) ;
129
+ wrapper . find ( 'input' ) . simulate ( 'compositionstart' ) ;
130
+ wrapper . find ( 'input' ) . simulate ( 'change' , { target : { value : 'Star Kirby' } } ) ;
131
+ wrapper . find ( 'input' ) . simulate ( 'keydown' , { which : KeyCode . ENTER } ) ;
132
+ expect ( handleChange ) . not . toHaveBeenCalled ( ) ;
133
+ handleChange . mockReset ( ) ;
134
+ wrapper . find ( 'input' ) . simulate ( 'compositionend' ) ;
135
+ wrapper . find ( 'input' ) . simulate ( 'keydown' , { which : KeyCode . ENTER } ) ;
136
+ expect ( handleChange ) . toHaveBeenCalledWith ( [ 'Star Kirby' ] , expect . anything ( ) ) ;
137
+ expect ( handleSelect ) . toHaveBeenCalledTimes ( 1 ) ;
138
+ expect ( findSelection ( wrapper ) . text ( ) ) . toEqual ( 'Star Kirby' ) ;
139
+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( '' ) ;
140
+ expectOpen ( wrapper , false ) ;
141
+ } ) ;
142
+
118
143
it ( 'paste content to split' , ( ) => {
119
144
const onChange = jest . fn ( ) ;
120
145
const wrapper = mount (
@@ -221,8 +246,6 @@ describe('Select.Tags', () => {
221
246
} ;
222
247
const wrapper = mount ( < Select mode = "tags" tokenSeparators = { [ ',' ] } tagRender = { tagRender } /> ) ;
223
248
224
- ( wrapper . find ( 'input' ) . instance ( ) as any ) . focus = jest . fn ( ) ;
225
-
226
249
wrapper . find ( 'input' ) . simulate ( 'change' , { target : { value : '1,A,42' } } ) ;
227
250
228
251
expect ( wrapper . find ( 'span.A' ) . length ) . toBe ( 1 ) ;
0 commit comments