@@ -62,30 +62,37 @@ test.describe('gcds-date-input', () => {
6262 expect ( value ) . toEqual ( '1234-03' ) ;
6363 } ) ;
6464
65- test ( 'Format: iso - value' , async ( { page } ) => {
66- const element = page . locator ( 'gcds-date-input' ) ;
67-
68- // Wait for element to attach and become visible, allowing up to 10s
69- await element . waitFor ( { state : 'attached' } ) ;
70- await element . waitFor ( { state : 'visible' } ) ;
71- await element . waitFor ( { timeout : 10000 } ) ;
72-
73- await element . evaluate (
74- ( el : HTMLGcdsDateInputElement ) => ( el . format = 'iso' ) ,
75- ) ;
76-
77- await page . waitForChanges ( ) ;
78-
79- await element . locator ( 'input[name="year"]' ) . fill ( '1234' ) ;
80- await element . locator ( 'input[name="month"]' ) . fill ( '03' ) ;
81- await element . locator ( 'input[name="day"]' ) . fill ( '11' ) ;
82-
83- const value = await element . evaluate (
84- ( el : HTMLGcdsDateInputElement ) => el . value ,
85- ) ;
86-
87- expect ( value ) . toEqual ( '1234-03-11' ) ;
88- } ) ;
65+ for ( const { year, month, day, expected } of [
66+ { year : '2023' , month : '3' , day : '1' , expected : '2023-03-01' } ,
67+ { year : '2021' , month : '05' , day : '2' , expected : '2021-05-02' } ,
68+ { year : '1600' , month : '2' , day : '11' , expected : '1600-02-11' } ,
69+ { year : '1234' , month : '03' , day : '11' , expected : '1234-03-11' } ,
70+ ] ) {
71+ test ( `Format: iso - value - ${ year } -${ month } -${ day } ` , async ( { page } ) => {
72+ const element = page . locator ( 'gcds-date-input' ) ;
73+
74+ // Wait for element to attach and become visible, allowing up to 10s
75+ await element . waitFor ( { state : 'attached' } ) ;
76+ await element . waitFor ( { state : 'visible' } ) ;
77+ await element . waitFor ( { timeout : 10000 } ) ;
78+
79+ await element . evaluate (
80+ ( el : HTMLGcdsDateInputElement ) => ( el . format = 'iso' ) ,
81+ ) ;
82+
83+ await page . waitForChanges ( ) ;
84+
85+ await element . locator ( 'input[name="year"]' ) . fill ( year ) ;
86+ await element . locator ( 'input[name="month"]' ) . fill ( month ) ;
87+ await element . locator ( 'input[name="day"]' ) . fill ( day ) ;
88+
89+ const value = await element . evaluate (
90+ ( el : HTMLGcdsDateInputElement ) => el . value ,
91+ ) ;
92+
93+ expect ( value ) . toEqual ( expected ) ;
94+ } ) ;
95+ }
8996 /**
9097 * Invalid value
9198 */
@@ -471,7 +478,7 @@ test.describe('gcds-date-input', () => {
471478 el => ( el as HTMLGcdsDateInputElement ) . errorMessage ,
472479 ) ;
473480
474- expect ( errorMessage ) . toEqual ( dateInputErrorMessage . en . invalidday ) ;
481+ expect ( errorMessage ) . toEqual ( dateInputErrorMessage . en . missingmonthinput ) ;
475482 } ) ;
476483 test ( 'Validation - Custom validation' , async ( { page } ) => {
477484 const element = page . locator ( 'gcds-date-input' ) ;
@@ -770,6 +777,19 @@ test.describe('gcds-date-input a11y tests', () => {
770777 * ISO format
771778 */
772779 test ( 'ISO format' , async ( { page } ) => {
780+ const element = page . locator ( 'gcds-date-input' ) ;
781+
782+ // Wait for element to attach and become visible, allowing up to 10s
783+ await element . waitFor ( { state : 'attached' } ) ;
784+ await element . waitFor ( { state : 'visible' } ) ;
785+ await element . waitFor ( { timeout : 10000 } ) ;
786+
787+ await element . evaluate (
788+ ( el : HTMLGcdsDateInputElement ) => ( el . format = 'iso' ) ,
789+ ) ;
790+
791+ await page . waitForChanges ( ) ;
792+
773793 const results = await new AxeBuilder ( { page } )
774794 . include ( 'gcds-date-input' )
775795 . analyze ( ) ;
0 commit comments