@@ -300,5 +300,66 @@ describe("pat-autosuggest", function () {
300
300
301
301
expect ( spy ) . toHaveBeenCalled ( ) ;
302
302
} ) ;
303
+
304
+ it ( "4.2 - Works with pat-validate on an empty selection." , async function ( ) {
305
+ const pattern_validation = ( await import ( "../validation/validation" ) ) . default ; // prettier-ignore
306
+
307
+ document . body . innerHTML = `
308
+ <form class="pat-validation" data-pat-validation="delay: 0">
309
+ <input
310
+ name="words"
311
+ class="pat-autosuggest"
312
+ required
313
+ data-pat-autosuggest="words: apple, orange, pear" />
314
+ </form>
315
+ ` ;
316
+
317
+ const form = document . querySelector ( "form" ) ;
318
+ const input = document . querySelector ( "input" ) ;
319
+
320
+ new pattern_validation ( form ) ;
321
+ new pattern ( input ) ;
322
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
323
+
324
+ // Open the select2 dropdown
325
+ $ ( ".select2-input" ) . click ( ) ;
326
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
327
+
328
+ // Close it without selecting something.
329
+ $ ( input ) . select2 ( "close" ) ;
330
+
331
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
332
+
333
+ // There should be a error message from pat-validation.
334
+ expect ( form . querySelectorAll ( "em.warning" ) . length ) . toBe ( 1 ) ;
335
+ } ) ;
336
+
337
+ it ( "4.3 - Works with pat-validate when empty and focus moves away." , async function ( ) {
338
+ const pattern_validation = ( await import ( "../validation/validation" ) ) . default ; // prettier-ignore
339
+
340
+ document . body . innerHTML = `
341
+ <form class="pat-validation" data-pat-validation="delay: 0">
342
+ <input
343
+ name="words"
344
+ class="pat-autosuggest"
345
+ required
346
+ data-pat-autosuggest="words: apple, orange, pear" />
347
+ </form>
348
+ ` ;
349
+
350
+ const form = document . querySelector ( "form" ) ;
351
+ const input = document . querySelector ( "input" ) ;
352
+
353
+ new pattern_validation ( form ) ;
354
+ new pattern ( input ) ;
355
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
356
+
357
+ // Move focus away from select2
358
+ $ ( ".select2-input" ) [ 0 ] . dispatchEvent ( events . blur_event ( ) ) ;
359
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
360
+
361
+ // There should be a error message from pat-validation.
362
+ expect ( form . querySelectorAll ( "em.warning" ) . length ) . toBe ( 1 ) ;
363
+ } ) ;
303
364
} ) ;
304
365
} ) ;
0 commit comments