@@ -102,6 +102,83 @@ describe('<Select />', () => {
102
102
expect ( wrapper . find ( Option ) . find ( '.pf-c-select__menu-item-description' ) . text ( ) ) . toEqual ( 'some description' ) ;
103
103
} ) ;
104
104
105
+ it ( 'should render groups and dividers' , async ( ) => {
106
+ const onSubmit = jest . fn ( ) ;
107
+
108
+ const wrapper = mount (
109
+ < FormRenderer
110
+ onSubmit = { ( values ) => onSubmit ( values ) }
111
+ FormTemplate = { FormTemplate }
112
+ componentMapper = { componentMapper }
113
+ schema = { {
114
+ fields : [
115
+ {
116
+ component : 'select' ,
117
+ name : 'select-with-categories' ,
118
+ label : 'With categories' ,
119
+ options : [
120
+ {
121
+ label : 'Category 1' ,
122
+ options : [
123
+ { label : 'value 1' , value : '111' } ,
124
+ { label : 'value 2' , value : '222' } ,
125
+ ] ,
126
+ } ,
127
+ { divider : true } ,
128
+ { label : 'independent 1' , value : '1112333' } ,
129
+ { divider : true } ,
130
+ {
131
+ label : 'Category 2' ,
132
+ options : [
133
+ { label : 'value 3' , value : '333' } ,
134
+ { label : 'value 4' , value : '444' } ,
135
+ ] ,
136
+ } ,
137
+ { divider : true } ,
138
+ { label : 'independent 2' , value : '11111' } ,
139
+ ] ,
140
+ } ,
141
+ ] ,
142
+ } }
143
+ />
144
+ ) ;
145
+
146
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
147
+
148
+ expect ( wrapper . find ( '.pf-c-select__menu-group-title' ) ) . toHaveLength ( 2 ) ;
149
+
150
+ expect ( wrapper . find ( '.pf-c-select__menu-group-title' ) . first ( ) . text ( ) ) . toEqual ( 'Category 1' ) ;
151
+ expect ( wrapper . find ( '.pf-c-select__menu-group-title' ) . last ( ) . text ( ) ) . toEqual ( 'Category 2' ) ;
152
+
153
+ expect ( wrapper . find ( '.pf-c-divider' ) ) . toHaveLength ( 3 ) ;
154
+
155
+ expect ( wrapper . find ( '.pf-c-select__menu-item' ) ) . toHaveLength ( 6 ) ;
156
+ expect ( wrapper . find ( '.pf-c-select__menu-item' ) . map ( ( opt ) => opt . text ( ) ) ) . toEqual ( [
157
+ 'value 1' ,
158
+ 'value 2' ,
159
+ 'independent 1' ,
160
+ 'value 3' ,
161
+ 'value 4' ,
162
+ 'independent 2' ,
163
+ ] ) ;
164
+
165
+ await act ( async ( ) => {
166
+ wrapper . find ( 'button.pf-c-select__menu-item' ) . first ( ) . simulate ( 'click' ) ;
167
+ } ) ;
168
+ wrapper . update ( ) ;
169
+
170
+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
171
+
172
+ expect ( wrapper . find ( '.pf-c-select__menu-item' ) . first ( ) . find ( '.pf-c-select__menu-item-icon' ) ) . toHaveLength ( 1 ) ; // first option is checked
173
+
174
+ await act ( async ( ) => {
175
+ wrapper . find ( 'form' ) . first ( ) . simulate ( 'submit' ) ;
176
+ } ) ;
177
+ wrapper . update ( ) ;
178
+
179
+ expect ( onSubmit ) . toHaveBeenCalledWith ( { 'select-with-categories' : '111' } ) ;
180
+ } ) ;
181
+
105
182
it ( 'should return single simple value' , async ( ) => {
106
183
const wrapper = mount ( < Select { ...initialProps } /> ) ;
107
184
wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
0 commit comments