@@ -138,7 +138,7 @@ describe('<Select />', () => {
138138 } ) ;
139139 } ) ;
140140
141- it ( 'should load Async options correctly' , ( done ) => {
141+ it ( 'should load single select Async options correctly' , ( done ) => {
142142 const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' } ] ) ) ;
143143
144144 const wrapper = mount ( < Select { ...initialProps } options = { undefined } loadOptions = { asyncLoading } /> ) ;
@@ -150,6 +150,75 @@ describe('<Select />', () => {
150150 } ) ;
151151 } ) ;
152152
153+ it ( 'should load multi select Async options correctly and set initial value to undefined' , ( done ) => {
154+ const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' , value : '123' } ] ) ) ;
155+ const onChange = jest . fn ( ) ;
156+ const wrapper = mount (
157+ < Select
158+ { ...initialProps }
159+ value = { [ 'does not exists in options' ] }
160+ isMulti
161+ options = { undefined }
162+ loadOptions = { asyncLoading }
163+ onChange = { onChange }
164+ simpleValue
165+ />
166+ ) ;
167+
168+ setImmediate ( ( ) => {
169+ wrapper . update ( ) ;
170+ expect ( wrapper . find ( Select ) . first ( ) . instance ( ) . state . allOptions ) . toEqual ( [ { label : 'label' , value : '123' } ] ) ;
171+ expect ( onChange ) . toHaveBeenCalledWith ( undefined ) ;
172+ done ( ) ;
173+ } ) ;
174+ } ) ;
175+
176+ it ( 'should load multi select Async options correctly and set initial value to ["123"]' , ( done ) => {
177+ const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' , value : '123' } ] ) ) ;
178+ const onChange = jest . fn ( ) ;
179+ const wrapper = mount (
180+ < Select
181+ { ...initialProps }
182+ value = { [ '123' , 'Not in options' ] }
183+ isMulti
184+ options = { undefined }
185+ loadOptions = { asyncLoading }
186+ onChange = { onChange }
187+ simpleValue
188+ />
189+ ) ;
190+
191+ setImmediate ( ( ) => {
192+ wrapper . update ( ) ;
193+ expect ( wrapper . find ( Select ) . first ( ) . instance ( ) . state . allOptions ) . toEqual ( [ { label : 'label' , value : '123' } ] ) ;
194+ expect ( onChange ) . toHaveBeenCalledWith ( [ '123' ] ) ;
195+ done ( ) ;
196+ } ) ;
197+ } ) ;
198+
199+ it ( 'should load multi select Async options correctly and set initial value to ["123"] if initial value is an object' , ( done ) => {
200+ const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' , value : '123' } ] ) ) ;
201+ const onChange = jest . fn ( ) ;
202+ const wrapper = mount (
203+ < Select
204+ { ...initialProps }
205+ value = { [ { value : '123' , label : 'label' } , 'Not in options' ] }
206+ isMulti
207+ options = { undefined }
208+ loadOptions = { asyncLoading }
209+ onChange = { onChange }
210+ simpleValue
211+ />
212+ ) ;
213+
214+ setImmediate ( ( ) => {
215+ wrapper . update ( ) ;
216+ expect ( wrapper . find ( Select ) . first ( ) . instance ( ) . state . allOptions ) . toEqual ( [ { label : 'label' , value : '123' } ] ) ;
217+ expect ( onChange ) . toHaveBeenCalledWith ( [ { label : 'label' , value : '123' } ] ) ;
218+ done ( ) ;
219+ } ) ;
220+ } ) ;
221+
153222 it ( 'should load Async options after filtering' , ( done ) => {
154223 const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' } ] ) ) ;
155224
0 commit comments