@@ -43,7 +43,7 @@ describe("pat-date-picker", function () {
43
43
jest . restoreAllMocks ( ) ;
44
44
} ) ;
45
45
46
- it ( "Default date picker." , async ( ) => {
46
+ it ( "1 - Default date picker." , async ( ) => {
47
47
document . body . innerHTML = '<input type="date" class="pat-date-picker"/>' ;
48
48
const el = document . querySelector ( "input[type=date]" ) ;
49
49
@@ -85,7 +85,7 @@ describe("pat-date-picker", function () {
85
85
expect ( el . value ) . toBe ( isodate ) ;
86
86
} ) ;
87
87
88
- it ( "Date picker starts at Monday." , async ( ) => {
88
+ it ( "2 - Date picker starts at Monday." , async ( ) => {
89
89
document . body . innerHTML =
90
90
'<input type="date" class="pat-date-picker" data-pat-date-picker="first-day: 1" />' ;
91
91
const el = document . querySelector ( "input[type=date]" ) ;
@@ -98,7 +98,7 @@ describe("pat-date-picker", function () {
98
98
expect ( first_day . textContent ) . toBe ( "Mon" ) ;
99
99
} ) ;
100
100
101
- it ( "Date picker with pre-set value." , async ( ) => {
101
+ it ( "3 - Date picker with pre-set value." , async ( ) => {
102
102
document . body . innerHTML =
103
103
'<input type="date" class="pat-date-picker" value="1900-01-01"/>' ;
104
104
const el = document . querySelector ( "input[type=date]" ) ;
@@ -120,7 +120,7 @@ describe("pat-date-picker", function () {
120
120
expect ( display_el . textContent ) . toBe ( "1900-01-01" ) ;
121
121
} ) ;
122
122
123
- it ( "Date picker with week numbers." , async ( ) => {
123
+ it ( "4 - Date picker with week numbers." , async ( ) => {
124
124
document . body . innerHTML =
125
125
'<input type="date" class="pat-date-picker" data-pat-date-picker="week-numbers: show" value="2017-09-18"/>' ;
126
126
const el = document . querySelector ( "input[type=date]" ) ;
@@ -133,7 +133,7 @@ describe("pat-date-picker", function () {
133
133
expect ( week_num . textContent ) . toBe ( "35" ) ;
134
134
} ) ;
135
135
136
- describe ( "Date picker with i18n" , function ( ) {
136
+ describe ( "5 - Date picker with i18n" , function ( ) {
137
137
describe ( "with proper json URL" , function ( ) {
138
138
it ( "properly localizes the months and weekdays" , async ( ) => {
139
139
global . fetch = jest . fn ( ) . mockImplementation ( mock_fetch_i18n ) ;
@@ -177,7 +177,7 @@ describe("pat-date-picker", function () {
177
177
} ) ;
178
178
} ) ;
179
179
180
- describe ( "Update one input depending on the other." , function ( ) {
180
+ describe ( "6 - Update one input depending on the other." , function ( ) {
181
181
it ( "Updates with default offset-days" , async ( ) => {
182
182
const wrapper = document . createElement ( "div" ) ;
183
183
wrapper . innerHTML = `
@@ -324,7 +324,7 @@ describe("pat-date-picker", function () {
324
324
} ) ;
325
325
} ) ;
326
326
327
- it ( "Formatted date." , async ( ) => {
327
+ it ( "7 - Formatted date." , async ( ) => {
328
328
document . body . innerHTML =
329
329
'<input type="date" class="pat-date-picker" value="2021-03-09" data-pat-date-picker="output-format: Do MMMM YYYY; locale: de"/>' ;
330
330
const el = document . querySelector ( "input[type=date]" ) ;
@@ -346,7 +346,7 @@ describe("pat-date-picker", function () {
346
346
expect ( el . value ) . toBe ( "2021-03-12" ) ;
347
347
} ) ;
348
348
349
- it ( "Styled behavior with clear button." , async ( ) => {
349
+ it ( "8 - Styled behavior with clear button." , async ( ) => {
350
350
document . body . innerHTML =
351
351
'<input type="date" class="pat-date-picker" value="2021-03-09"/>' ;
352
352
const el = document . querySelector ( "input[type=date]" ) ;
@@ -400,7 +400,7 @@ describe("pat-date-picker", function () {
400
400
expect ( clear_button ) . toBeFalsy ( ) ;
401
401
} ) ;
402
402
403
- it ( "Formatted date with clear button." , async ( ) => {
403
+ it ( "9 - Formatted date with clear button." , async ( ) => {
404
404
document . body . innerHTML =
405
405
'<input type="date" class="pat-date-picker" value="2021-03-09" data-pat-date-picker="output-format: DD.MM.YYYY"/>' ;
406
406
const el = document . querySelector ( "input[type=date]" ) ;
@@ -454,7 +454,7 @@ describe("pat-date-picker", function () {
454
454
expect ( clear_button ) . toBeFalsy ( ) ;
455
455
} ) ;
456
456
457
- it ( "Required formatted date - no clear button available." , async ( ) => {
457
+ it ( "10 - Required formatted date - no clear button available." , async ( ) => {
458
458
document . body . innerHTML =
459
459
'<input type="date" class="pat-date-picker" value="2021-03-01" required/>' ;
460
460
const el = document . querySelector ( "input[type=date]" ) ;
@@ -486,7 +486,7 @@ describe("pat-date-picker", function () {
486
486
expect ( clear_button ) . toBeFalsy ( ) ;
487
487
} ) ;
488
488
489
- it ( "Native behavior with fallback to pika" , async ( ) => {
489
+ it ( "11 - Native behavior with fallback to pika" , async ( ) => {
490
490
// We mocking as if we're not supporting input type date.
491
491
jest . spyOn ( utils , "checkInputSupport" ) . mockImplementation ( ( ) => false ) ;
492
492
@@ -528,7 +528,7 @@ describe("pat-date-picker", function () {
528
528
expect ( el . value ) . toBe ( isodate ) ;
529
529
} ) ;
530
530
531
- it ( "does not initialize the date picker in styled behavior when disabled" , async ( ) => {
531
+ it ( "12 - does not initialize the date picker in styled behavior when disabled" , async ( ) => {
532
532
document . body . innerHTML = `
533
533
<input
534
534
type="date"
@@ -559,7 +559,7 @@ describe("pat-date-picker", function () {
559
559
expect ( document . querySelector ( ".pika-lendar" ) ) . toBeFalsy ( ) ;
560
560
} ) ;
561
561
562
- it ( "works with pat-autosubmit" , async ( ) => {
562
+ it ( "13 - works with pat-autosubmit" , async ( ) => {
563
563
document . body . innerHTML = `
564
564
<form class="pat-autosubmit" onsubmit="return false;">
565
565
<input name="date" type="date" class="pat-date-picker"/>
@@ -581,4 +581,41 @@ describe("pat-date-picker", function () {
581
581
await utils . timeout ( 500 ) ; // wait for delay
582
582
expect ( handle_submit ) . toHaveBeenCalled ( ) ;
583
583
} ) ;
584
+
585
+ it ( "14 - Selecting nothing in styled behavior triggers pat-validation." , async ( ) => {
586
+ document . body . innerHTML = `
587
+ <form class="pat-validation" data-pat-validation="delay: 0">
588
+ <input
589
+ type="date"
590
+ name="date"
591
+ class="pat-date-picker"
592
+ required
593
+ />
594
+ </form>
595
+ ` ;
596
+ const form = document . querySelector ( "form" ) ;
597
+ const el = document . querySelector ( "input[type=date]" ) ;
598
+
599
+ const pattern_validation = ( await import ( "../validation/validation" ) ) . default ;
600
+
601
+ new pattern_validation ( form ) ;
602
+ new pattern ( el ) ;
603
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
604
+
605
+ // Open the date picker
606
+ document . querySelector ( "time" ) . click ( ) ;
607
+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
608
+
609
+ // Date picker is opened
610
+ expect ( document . querySelector ( ".pika-lendar" ) ) . toBeTruthy ( ) ;
611
+
612
+ // Close the date picker without selecting a date.
613
+ document . body . click ( ) ;
614
+
615
+ // Wait for validation to run.
616
+ await utils . timeout ( 1 ) ;
617
+
618
+ // There should be a error message from pat-validation.
619
+ expect ( form . querySelectorAll ( "em.warning" ) . length ) . toBe ( 1 ) ;
620
+ } ) ;
584
621
} ) ;
0 commit comments