@@ -37,6 +37,31 @@ const mock_fetch_i18n = () =>
3737 } ) ,
3838 } ) ;
3939
40+ const select_date = ( el , date ) => {
41+ // Attention! Just select today.
42+ // Scrolling calendar pages forward and backwards is not supported yet.
43+ el . click ( ) ;
44+
45+ const day = date . getDate ( ) . toString ( ) ;
46+ const month = date . getMonth ( ) . toString ( ) ; // remember, month-count starts from 0
47+ const year = date . getFullYear ( ) . toString ( ) ;
48+
49+ const cur_year = document . querySelector ( '.pika-lendar .pika-select-year option[selected="selected"]' ) ; // prettier-ignore
50+ expect ( cur_year . textContent ) . toBe ( year ) ;
51+
52+ const cur_month = document . querySelector ( '.pika-lendar .pika-select-month option[selected="selected"]' ) ; // prettier-ignore
53+ expect ( cur_month . value ) . toBe ( month ) ;
54+
55+ const cur_day = document . querySelector ( ".pika-lendar td.is-today button" ) ; // prettier-ignore
56+ expect ( cur_day . getAttribute ( "data-pika-day" ) ) . toBe ( day ) ;
57+
58+ const cur_wkday = document . querySelector ( ".pika-lendar th:first-child abbr" ) ; // prettier-ignore
59+ expect ( cur_wkday . textContent ) . toBe ( "Sun" ) ;
60+
61+ // select current day.
62+ cur_day . dispatchEvent ( new Event ( "mousedown" ) ) ;
63+ } ;
64+
4065describe ( "pat-date-picker" , function ( ) {
4166 afterEach ( function ( ) {
4267 document . body . innerHTML = "" ;
@@ -57,28 +82,10 @@ describe("pat-date-picker", function () {
5782 expect ( el . getAttribute ( "type" ) ) . toBe ( "date" ) ;
5883 expect ( el . style . display ) . toBe ( "none" ) ;
5984
60- display_el . click ( ) ;
61-
6285 const date = new Date ( ) ;
63- const day = date . getDate ( ) . toString ( ) ;
64- const month = date . getMonth ( ) . toString ( ) ; // remember, month-count starts from 0
65- const year = date . getFullYear ( ) . toString ( ) ;
6686 const isodate = utils . localized_isodate ( date ) ;
87+ select_date ( display_el , date ) ;
6788
68- const cur_year = document . querySelector ( '.pika-lendar .pika-select-year option[selected="selected"]' ) ; // prettier-ignore
69- expect ( cur_year . textContent ) . toBe ( year ) ;
70-
71- const cur_month = document . querySelector ( '.pika-lendar .pika-select-month option[selected="selected"]' ) ; // prettier-ignore
72- expect ( cur_month . value ) . toBe ( month ) ;
73-
74- const cur_day = document . querySelector ( ".pika-lendar td.is-today button" ) ; // prettier-ignore
75- expect ( cur_day . getAttribute ( "data-pika-day" ) ) . toBe ( day ) ;
76-
77- const cur_wkday = document . querySelector ( ".pika-lendar th:first-child abbr" ) ; // prettier-ignore
78- expect ( cur_wkday . textContent ) . toBe ( "Sun" ) ;
79-
80- // select current day.
81- cur_day . dispatchEvent ( new Event ( "mousedown" ) ) ;
8289 // <time> element should contains the current date in iso format
8390 expect ( display_el . textContent ) . toBe ( isodate ) ;
8491 // input element contains iso date
@@ -618,4 +625,41 @@ describe("pat-date-picker", function () {
618625 // There should be a error message from pat-validation.
619626 expect ( form . querySelectorAll ( "em.warning" ) . length ) . toBe ( 1 ) ;
620627 } ) ;
628+
629+ it ( "15 - Placeholder support." , async ( ) => {
630+ document . body . innerHTML = `
631+ <input
632+ type="date"
633+ class="pat-date-picker"
634+ placeholder="Select a date"
635+ />` ;
636+ const el = document . querySelector ( "input[type=date]" ) ;
637+ new pattern ( el ) ;
638+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
639+
640+ const display_el = document . querySelector ( "time" ) ;
641+ expect ( display_el ) . toBeTruthy ( ) ;
642+ expect ( display_el . textContent ) . toBe ( "Select a date" ) ;
643+ expect ( el . value ) . toBe ( "" ) ;
644+
645+ const date = new Date ( ) ;
646+ const isodate = utils . localized_isodate ( date ) ;
647+ select_date ( display_el , date ) ;
648+
649+ // <time> element should contains the current date in iso format
650+ expect ( display_el . textContent ) . toBe ( isodate ) ;
651+ // input element contains iso date
652+ expect ( el . value ) . toBe ( isodate ) ;
653+
654+ // Clear button is availale
655+ let clear_button = display_el . querySelector ( ".cancel-button" ) ;
656+ expect ( clear_button ) . toBeTruthy ( ) ;
657+
658+ clear_button . click ( ) ;
659+
660+ // <time> element should contain the placeholder again
661+ expect ( display_el . textContent ) . toBe ( "Select a date" ) ;
662+ // input element should be empty
663+ expect ( el . value ) . toBe ( "" ) ;
664+ } ) ;
621665} ) ;
0 commit comments