1
1
import React from 'react' ;
2
2
import { mount } from 'enzyme' ;
3
- import { components } from 'react-select' ;
4
- import ReactSelect from 'react-select' ;
5
3
import isEqual from 'lodash/isEqual' ;
6
4
7
5
import Select from '../../common/select/select' ;
@@ -13,7 +11,7 @@ describe('<Select />', () => {
13
11
beforeEach ( ( ) => {
14
12
initialProps = {
15
13
onChange,
16
- menuIsOpen : true ,
14
+ name : 'test-select' ,
17
15
id : 'select' ,
18
16
options : [
19
17
{
@@ -34,11 +32,8 @@ describe('<Select />', () => {
34
32
35
33
it ( 'should return single simple value' , async ( ) => {
36
34
const wrapper = mount ( < Select { ...initialProps } /> ) ;
37
- const option = wrapper
38
- . find ( '.ddorg__pf4-component-mapper__select__menu--option' )
39
- . first ( )
40
- . find ( 'div' )
41
- . last ( ) ;
35
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
36
+ const option = wrapper . find ( 'button.pf-c-select__menu-item' ) . first ( ) ;
42
37
43
38
await act ( async ( ) => {
44
39
option . simulate ( 'click' ) ;
@@ -49,11 +44,8 @@ describe('<Select />', () => {
49
44
50
45
it ( 'should return single object value' , async ( ) => {
51
46
const wrapper = mount ( < Select { ...initialProps } simpleValue = { false } /> ) ;
52
- const option = wrapper
53
- . find ( '.ddorg__pf4-component-mapper__select__menu--option' )
54
- . first ( )
55
- . find ( 'div' )
56
- . last ( ) ;
47
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
48
+ const option = wrapper . find ( 'button.pf-c-select__menu-item' ) . first ( ) ;
57
49
58
50
await act ( async ( ) => {
59
51
option . simulate ( 'click' ) ;
@@ -67,26 +59,19 @@ describe('<Select />', () => {
67
59
// simulate first return value in state
68
60
const value = [ 1 ] ;
69
61
const wrapper = mount ( < Select { ...initialProps } value = { value } isMulti onChange = { onChange } closeMenuOnSelect = { false } /> ) ;
62
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
70
63
/**
71
64
* select first option
72
65
*/
73
- const option1 = wrapper
74
- . find ( '.ddorg__pf4-component-mapper__select__menu--option' )
75
- . first ( )
76
- . find ( 'div' )
77
- . last ( ) ;
66
+ const option1 = wrapper . find ( 'button.pf-c-select__menu-item' ) . first ( ) ;
78
67
79
68
await act ( async ( ) => {
80
69
option1 . simulate ( 'click' ) ;
81
70
} ) ;
82
71
/**
83
72
* select second option
84
73
*/
85
- const option2 = wrapper
86
- . find ( '.ddorg__pf4-component-mapper__select__menu--option' )
87
- . last ( )
88
- . find ( 'div' )
89
- . last ( ) ;
74
+ const option2 = wrapper . find ( 'button.pf-c-select__menu-item' ) . last ( ) ;
90
75
await act ( async ( ) => {
91
76
option2 . simulate ( 'click' ) ;
92
77
} ) ;
@@ -101,26 +86,19 @@ describe('<Select />', () => {
101
86
// simulate first return value in state
102
87
const value = [ { ...initialProps . options [ 0 ] } ] ;
103
88
const wrapper = mount ( < Select { ...initialProps } value = { value } simpleValue = { false } isMulti onChange = { onChange } closeMenuOnSelect = { false } /> ) ;
89
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
104
90
/**
105
91
* select first option
106
92
*/
107
- const option1 = wrapper
108
- . find ( '.ddorg__pf4-component-mapper__select__menu--option' )
109
- . first ( )
110
- . find ( 'div' )
111
- . last ( ) ;
93
+ const option1 = wrapper . find ( 'button.pf-c-select__menu-item' ) . first ( ) ;
112
94
113
95
await act ( async ( ) => {
114
96
option1 . simulate ( 'click' ) ;
115
97
} ) ;
116
98
/**
117
99
* select second option
118
100
*/
119
- const option2 = wrapper
120
- . find ( '.ddorg__pf4-component-mapper__select__menu--option' )
121
- . last ( )
122
- . find ( 'div' )
123
- . last ( ) ;
101
+ const option2 = wrapper . find ( 'button.pf-c-select__menu-item' ) . last ( ) ;
124
102
await act ( async ( ) => {
125
103
option2 . simulate ( 'click' ) ;
126
104
} ) ;
@@ -130,16 +108,28 @@ describe('<Select />', () => {
130
108
} ) ;
131
109
132
110
it ( 'should expand and close multi value chips' , async ( ) => {
133
- const value = [ 1 , 2 ] ;
134
- const wrapper = mount ( < Select { ...initialProps } value = { value } isMulti closeMenuOnSelect = { false } /> ) ;
111
+ const value = [ 1 , 2 , 3 , 4 ] ;
112
+ const options = [
113
+ ...initialProps . options ,
114
+ {
115
+ label : '3' ,
116
+ value : 3
117
+ } ,
118
+ {
119
+ label : '4' ,
120
+ value : 4
121
+ }
122
+ ] ;
123
+ const wrapper = mount ( < Select { ...initialProps } options = { options } value = { value } isMulti closeMenuOnSelect = { false } /> ) ;
135
124
136
- expect ( wrapper . find ( '.ddorg__pf4-component-mapper__select__multivalue--container' ) ) . toHaveLength ( 1 ) ;
137
- const expandButton = wrapper . find ( 'button.pf-c-button.pf-m-plain.ddorg__pf4-component-mapper__select__value--container-chipgroup' ) ;
125
+ expect ( wrapper . find ( '.pf-c-chip-group' ) ) . toHaveLength ( 1 ) ;
126
+ expect ( wrapper . find ( 'div.pf-c-chip' ) ) . toHaveLength ( 3 ) ;
127
+ const expandButton = wrapper . find ( 'button.pf-c-chip.pf-m-overflow' ) . last ( ) ;
138
128
await act ( async ( ) => {
139
129
expandButton . simulate ( 'click' ) ;
140
130
} ) ;
141
131
wrapper . update ( ) ;
142
- expect ( wrapper . find ( '.ddorg__pf4-component-mapper__select__multivalue--container ' ) ) . toHaveLength ( 2 ) ;
132
+ expect ( wrapper . find ( 'div.pf-c-chip ' ) ) . toHaveLength ( 4 ) ;
143
133
} ) ;
144
134
145
135
it ( 'should call on change when removing chip' , async ( ) => {
@@ -148,7 +138,7 @@ describe('<Select />', () => {
148
138
149
139
await act ( async ( ) => {
150
140
wrapper
151
- . find ( components . MultiValueRemove )
141
+ . find ( 'button.pf-c-button.pf-m-plain' )
152
142
. first ( )
153
143
. simulate ( 'click' ) ;
154
144
} ) ;
@@ -180,33 +170,31 @@ describe('<Select />', () => {
180
170
{ label : 'b' , value : 2 }
181
171
] ,
182
172
placeholder : 'Choose...' ,
183
- selectVariant : 'default' ,
184
173
showLessLabel : 'Show less' ,
185
174
showMoreLabel : 'more' ,
186
175
simpleValue : true ,
187
176
updatingMessage : 'Loading data...' ,
188
177
menuIsPortal : false ,
189
178
value : [ 1 , 2 ] ,
190
- loadingMessage : 'Loading...'
179
+ loadingMessage : 'Loading...' ,
180
+ noOptionsMessage : 'No options' ,
181
+ noResultsMessage : 'No results found'
191
182
} ) ;
192
183
} ) ;
193
184
194
185
it ( 'should load single select Async options correctly' , async ( ) => {
195
- const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' } ] ) ) ;
186
+ const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' , value : '3' } ] ) ) ;
196
187
197
188
let wrapper ;
198
189
199
190
await act ( async ( ) => {
200
191
wrapper = mount ( < Select { ...initialProps } options = { undefined } loadOptions = { asyncLoading } /> ) ;
201
192
} ) ;
202
193
wrapper . update ( ) ;
194
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
203
195
204
- expect (
205
- wrapper
206
- . find ( ReactSelect )
207
- . first ( )
208
- . instance ( ) . props . options
209
- ) . toEqual ( [ { label : 'label' } ] ) ;
196
+ expect ( wrapper . find ( 'button.pf-c-select__menu-item' ) ) . toHaveLength ( 1 ) ;
197
+ expect ( wrapper . find ( 'button.pf-c-select__menu-item' ) . text ( ) ) . toEqual ( 'label' ) ;
210
198
} ) ;
211
199
212
200
it ( 'should load multi select Async options correctly and set initial value to undefined' , async ( ) => {
@@ -229,12 +217,9 @@ describe('<Select />', () => {
229
217
} ) ;
230
218
231
219
wrapper . update ( ) ;
232
- expect (
233
- wrapper
234
- . find ( ReactSelect )
235
- . first ( )
236
- . instance ( ) . props . options
237
- ) . toEqual ( [ { label : 'label' , value : '123' } ] ) ;
220
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
221
+ expect ( wrapper . find ( 'button.pf-c-select__menu-item' ) ) . toHaveLength ( 1 ) ;
222
+ expect ( wrapper . find ( 'button.pf-c-select__menu-item' ) . text ( ) ) . toEqual ( 'label' ) ;
238
223
expect ( onChange ) . toHaveBeenCalledWith ( undefined ) ;
239
224
} ) ;
240
225
@@ -258,12 +243,9 @@ describe('<Select />', () => {
258
243
} ) ;
259
244
260
245
wrapper . update ( ) ;
261
- expect (
262
- wrapper
263
- . find ( ReactSelect )
264
- . first ( )
265
- . instance ( ) . props . options
266
- ) . toEqual ( [ { label : 'label' , value : '123' } ] ) ;
246
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
247
+ expect ( wrapper . find ( 'button.pf-c-select__menu-item' ) ) . toHaveLength ( 1 ) ;
248
+ expect ( wrapper . find ( 'button.pf-c-select__menu-item' ) . text ( ) ) . toEqual ( 'label' ) ;
267
249
expect ( onChange ) . toHaveBeenCalledWith ( [ '123' ] ) ;
268
250
} ) ;
269
251
@@ -286,26 +268,24 @@ describe('<Select />', () => {
286
268
} ) ;
287
269
288
270
wrapper . update ( ) ;
289
- expect (
290
- wrapper
291
- . find ( ReactSelect )
292
- . first ( )
293
- . instance ( ) . props . options
294
- ) . toEqual ( [ { label : 'label' , value : '123' } ] ) ;
271
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
272
+ expect ( wrapper . find ( 'button.pf-c-select__menu-item' ) ) . toHaveLength ( 1 ) ;
273
+ expect ( wrapper . find ( 'button.pf-c-select__menu-item' ) . text ( ) ) . toEqual ( 'label' ) ;
295
274
expect ( onChange ) . toHaveBeenCalledWith ( [ { label : 'label' , value : '123' } ] ) ;
296
275
} ) ;
297
276
298
277
it ( 'should load Async options after filtering' , async ( ) => {
299
- const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' } ] ) ) ;
278
+ const asyncLoading = jest . fn ( ) . mockReturnValue ( Promise . resolve ( [ { label : 'label' , value : 1 } ] ) ) ;
300
279
let wrapper ;
301
280
await act ( async ( ) => {
302
281
wrapper = mount ( < Select { ...initialProps } isSearchable = { true } options = { undefined } loadOptions = { asyncLoading } /> ) ;
303
282
} ) ;
304
283
305
284
wrapper . update ( ) ;
306
285
expect ( asyncLoading . mock . calls ) . toHaveLength ( 1 ) ;
286
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
307
287
308
- const search = wrapper . find ( ReactSelect ) . find ( 'input' ) ;
288
+ const search = wrapper . find ( 'input' ) ;
309
289
310
290
await act ( async ( ) => {
311
291
search . instance ( ) . value = 'foo' ;
@@ -339,15 +319,15 @@ describe('<Select />', () => {
339
319
wrapper = mount ( < Wrapper { ...initialProps } /> ) ;
340
320
} ) ;
341
321
342
- let innerSelectProps = wrapper . find ( ReactSelect ) . props ( ) . options ;
322
+ let innerSelectProps = wrapper . find ( 'InternalSelect' ) . props ( ) . options ;
343
323
344
324
expect ( isEqual ( innerSelectProps , initialProps . options ) ) . toEqual ( true ) ;
345
325
346
326
await act ( async ( ) => {
347
327
wrapper . setProps ( { options : NEW_OPTIONS } ) ;
348
328
} ) ;
349
329
wrapper . update ( ) ;
350
- innerSelectProps = wrapper . find ( ReactSelect ) . props ( ) . options ;
330
+ innerSelectProps = wrapper . find ( 'InternalSelect' ) . props ( ) . options ;
351
331
352
332
expect ( innerSelectProps ) . toEqual ( NEW_OPTIONS ) ;
353
333
} ) ;
@@ -359,7 +339,7 @@ describe('<Select />', () => {
359
339
} ) ;
360
340
361
341
wrapper . update ( ) ;
362
- let innerSelectProps = wrapper . find ( ReactSelect ) . props ( ) . options ;
342
+ let innerSelectProps = wrapper . find ( 'InternalSelect' ) . props ( ) . options ;
363
343
364
344
expect ( isEqual ( innerSelectProps , initialProps . options ) ) . toEqual ( true ) ;
365
345
@@ -368,7 +348,7 @@ describe('<Select />', () => {
368
348
} ) ;
369
349
370
350
wrapper . update ( ) ;
371
- innerSelectProps = wrapper . find ( ReactSelect ) . props ( ) . options ;
351
+ innerSelectProps = wrapper . find ( 'InternalSelect' ) . props ( ) . options ;
372
352
373
353
expect ( isEqual ( innerSelectProps , NEW_OPTIONS ) ) . toEqual ( true ) ;
374
354
} ) ;
0 commit comments