158
158
} ) ;
159
159
} ) ;
160
160
161
+ describe ( '<select required>' , function ( ) {
162
+ var form ;
163
+ before ( function ( ) {
164
+ test = setup_test ( '<select required>' +
165
+ '<option value="">Select an option...</option>' +
166
+ '<option value="a">A</option>' +
167
+ '</select>' , { } ) ;
168
+ test . $select . parent ( ) . children ( ) . wrapAll ( "<form>" ) ;
169
+ form = test . $select . parent ( ) ;
170
+ form . append ( "<button>" ) ;
171
+ form . on ( 'submit' , function ( event ) {
172
+ event . preventDefault ( ) ;
173
+ assert . ok ( false , 'the form was submitted' ) ;
174
+ } ) ;
175
+ } ) ;
176
+ it ( 'should have isRequired property set to true' , function ( ) {
177
+ expect ( test . selectize . isRequired ) . to . be . equal ( true ) ;
178
+ } ) ;
179
+ it ( 'should have the required class' , function ( ) {
180
+ expect ( test . selectize . $control . hasClass ( 'required' ) ) . to . be . equal ( true ) ;
181
+ } ) ;
182
+ it ( 'should have the invalid class when validation fails' , function ( ) {
183
+ test . $select [ 0 ] . checkValidity ( ) ;
184
+ expect ( test . selectize . $control . hasClass ( 'invalid' ) ) . to . be . equal ( true ) ;
185
+ expect ( test . selectize . isInputFocused ) . to . be . equal ( false ) ;
186
+ } ) ;
187
+ it ( 'should gain focus when validation via a button fails' , function ( ) {
188
+ $ ( "form button" ) . click ( ) ;
189
+ expect ( test . selectize . $control . hasClass ( 'invalid' ) ) . to . be . equal ( true ) ;
190
+ expect ( test . selectize . isInputFocused ) . to . be . equal ( true ) ;
191
+ } ) ;
192
+ it ( 'should clear the invalid class after an item is selected' , function ( ) {
193
+ $ ( "form button" ) . click ( ) ;
194
+ test . selectize . addItem ( 'a' ) ;
195
+ expect ( test . selectize . $control . hasClass ( 'invalid' ) ) . to . be . equal ( false ) ;
196
+ } ) ;
197
+ it ( 'should pass validation if an element is selected' , function ( done ) {
198
+ test . selectize . addItem ( 'a' ) ;
199
+ form . off ( 'submit' ) . on ( 'submit' , function ( event ) {
200
+ event . preventDefault ( ) ;
201
+ done ( ) ;
202
+ } ) ;
203
+ $ ( "form button" ) . click ( ) ;
204
+ } ) ;
205
+ after ( function ( ) {
206
+ test . teardown ( ) ;
207
+ form . remove ( ) ;
208
+ } ) ;
209
+ } ) ;
210
+
161
211
} ) ;
162
212
163
213
} ) ( ) ;
0 commit comments