@@ -12,8 +12,8 @@ import {
1212} from '../common/controllers/key-bindings.js' ;
1313import { defineComponents } from '../common/definitions/defineComponents.js' ;
1414import {
15- FormAssociatedTestBed ,
1615 type ValidationContainerTestsParams ,
16+ createFormAssociatedTestBed ,
1717 isFocused ,
1818 runValidationContainerTests ,
1919 simulateInput ,
@@ -902,8 +902,8 @@ describe('Date Time Input component', () => {
902902
903903 describe ( 'Form integration' , ( ) => {
904904 const today = CalendarDay . today ;
905- const spec = new FormAssociatedTestBed < IgcDateTimeInputComponent > (
906- html `< igc-date-time-input name ="dt "> </ igc-date-time-input > `
905+ const spec = createFormAssociatedTestBed < IgcDateTimeInputComponent > (
906+ html `< igc-date-time-input name ="date-time "> </ igc-date-time-input > `
907907 ) ;
908908
909909 beforeEach ( async ( ) => {
@@ -914,83 +914,68 @@ describe('Date Time Input component', () => {
914914 expect ( spec . element . form ) . to . equal ( spec . form ) ;
915915 } ) ;
916916
917- it ( 'is not associated on submit if no value' , async ( ) => {
918- expect ( spec . submit ( ) ?. get ( spec . element . name ) ) . to . be . null ;
917+ it ( 'is not associated on submit if no value' , ( ) => {
918+ spec . assertSubmitHasValue ( null ) ;
919919 } ) ;
920920
921- it ( 'is associated on submit' , async ( ) => {
922- spec . element . value = today . native ;
923- await elementUpdated ( spec . element ) ;
924-
925- expect ( spec . submit ( ) ?. get ( spec . element . name ) ) . to . equal (
926- spec . element . value . toISOString ( )
927- ) ;
921+ it ( 'is associated on submit' , ( ) => {
922+ spec . setProperties ( { value : today . native } ) ;
923+ spec . assertSubmitHasValue ( today . native . toISOString ( ) ) ;
928924 } ) ;
929925
930- it ( 'is correctly reset on form reset' , async ( ) => {
931- spec . element . value = today . native ;
932- await elementUpdated ( spec . element ) ;
926+ it ( 'is correctly reset on form reset' , ( ) => {
927+ spec . setProperties ( { value : today . native } ) ;
933928
934929 spec . reset ( ) ;
935930 expect ( spec . element . value ) . to . be . null ;
936931 } ) ;
937932
938933 it ( 'is correctly reset to the new default value after setAttribute() call' , ( ) => {
939- spec . element . setAttribute ( ' value' , today . native . toISOString ( ) ) ;
940- spec . element . value = today . add ( 'day' , 180 ) . native ;
934+ spec . setAttributes ( { value : today . native . toISOString ( ) } ) ;
935+ spec . setProperties ( { value : today . add ( 'day' , 180 ) . native } ) ;
941936
942937 spec . reset ( ) ;
943938
944- expect ( toCalendarDay ( spec . element . value ) . equalTo ( today ) ) . to . be . true ;
945- expect ( spec . submit ( ) ?. get ( spec . element . name ) ) . to . equal (
946- today . native . toISOString ( )
947- ) ;
939+ expect ( toCalendarDay ( spec . element . value ! ) . equalTo ( today ) ) . to . be . true ;
940+ spec . assertSubmitHasValue ( today . native . toISOString ( ) ) ;
948941 } ) ;
949942
950- it ( 'reflects disabled ancestor state' , async ( ) => {
943+ it ( 'reflects disabled ancestor state' , ( ) => {
951944 spec . setAncestorDisabledState ( true ) ;
952945 expect ( spec . element . disabled ) . to . be . true ;
953946
954947 spec . setAncestorDisabledState ( false ) ;
955948 expect ( spec . element . disabled ) . to . be . false ;
956949 } ) ;
957950
958- it ( 'fulfils required constraint' , async ( ) => {
959- spec . element . required = true ;
960- await elementUpdated ( spec . element ) ;
961- spec . submitFails ( ) ;
951+ it ( 'fulfils required constraint' , ( ) => {
952+ spec . setProperties ( { required : true } ) ;
953+ spec . assertSubmitFails ( ) ;
962954
963- spec . element . value = new Date ( Date . now ( ) ) ;
964- await elementUpdated ( spec . element ) ;
965- spec . submitValidates ( ) ;
955+ spec . setProperties ( { value : new Date ( ) } ) ;
956+ spec . assertSubmitPasses ( ) ;
966957 } ) ;
967958
968- it ( 'fulfils min value constraint' , async ( ) => {
969- spec . element . min = new Date ( 2025 , 0 , 1 ) ;
970- await elementUpdated ( spec . element ) ;
971- spec . submitFails ( ) ;
959+ it ( 'fulfils min value constraint' , ( ) => {
960+ spec . setProperties ( { min : new Date ( 2026 , 0 , 1 ) } ) ;
961+ spec . assertSubmitFails ( ) ;
972962
973- spec . element . value = new Date ( 2022 , 0 , 1 ) ;
974- await elementUpdated ( spec . element ) ;
975- spec . submitFails ( ) ;
963+ spec . setProperties ( { value : new Date ( 2022 , 0 , 1 ) } ) ;
964+ spec . assertSubmitFails ( ) ;
976965
977- spec . element . value = new Date ( 2025 , 0 , 2 ) ;
978- await elementUpdated ( spec . element ) ;
979- spec . submitValidates ( ) ;
966+ spec . setProperties ( { value : new Date ( 2026 , 0 , 2 ) } ) ;
967+ spec . assertSubmitPasses ( ) ;
980968 } ) ;
981969
982- it ( 'fulfils max value constraint' , async ( ) => {
983- spec . element . max = new Date ( 2020 , 0 , 1 ) ;
984- spec . element . value = new Date ( Date . now ( ) ) ;
985- await elementUpdated ( spec . element ) ;
986- spec . submitFails ( ) ;
970+ it ( 'fulfils max value constraint' , ( ) => {
971+ spec . setProperties ( { max : new Date ( 2020 , 0 , 1 ) , value : new Date ( ) } ) ;
972+ spec . assertSubmitFails ( ) ;
987973
988- spec . element . value = new Date ( 2020 , 0 , 1 ) ;
989- await elementUpdated ( spec . element ) ;
990- spec . submitValidates ( ) ;
974+ spec . setProperties ( { value : new Date ( 2020 , 0 , 1 ) } ) ;
975+ spec . assertSubmitPasses ( ) ;
991976 } ) ;
992977
993- it ( 'fulfils custom constraint' , async ( ) => {
978+ it ( 'fulfils custom constraint' , ( ) => {
994979 spec . element . setCustomValidity ( 'invalid' ) ;
995980 spec . submitFails ( ) ;
996981
@@ -999,6 +984,106 @@ describe('Date Time Input component', () => {
999984 } ) ;
1000985 } ) ;
1001986
987+ describe ( 'defaultValue' , ( ) => {
988+ const today = CalendarDay . today ;
989+
990+ describe ( 'Form integration' , ( ) => {
991+ const spec = createFormAssociatedTestBed < IgcDateTimeInputComponent > ( html `
992+ < igc-date-time-input
993+ name ="date-time "
994+ .defaultValue =${ today . native }
995+ > </ igc-date-time-input >
996+ ` ) ;
997+
998+ beforeEach ( async ( ) => {
999+ await spec . setup ( IgcDateTimeInputComponent . tagName ) ;
1000+ } ) ;
1001+
1002+ it ( 'correct initial state' , ( ) => {
1003+ spec . assertIsPristine ( ) ;
1004+ expect ( spec . element . value ?. toISOString ( ) ) . to . equal (
1005+ today . native . toISOString ( )
1006+ ) ;
1007+ } ) ;
1008+
1009+ it ( 'is correctly submitted' , ( ) => {
1010+ spec . assertSubmitHasValue ( today . native . toISOString ( ) ) ;
1011+ } ) ;
1012+
1013+ it ( 'is correctly reset' , ( ) => {
1014+ spec . setProperties ( { value : today . add ( 'day' , 1 ) . native } ) ;
1015+ spec . reset ( ) ;
1016+
1017+ expect ( spec . element . value ?. toISOString ( ) ) . to . equal (
1018+ today . native . toISOString ( )
1019+ ) ;
1020+ } ) ;
1021+ } ) ;
1022+
1023+ describe ( 'Validation' , ( ) => {
1024+ const spec = createFormAssociatedTestBed < IgcDateTimeInputComponent > ( html `
1025+ < igc-date-time-input
1026+ name ="date-time "
1027+ required
1028+ .defaultValue =${ null }
1029+ > </ igc-date-time-input >
1030+ ` ) ;
1031+
1032+ beforeEach ( async ( ) => {
1033+ await spec . setup ( IgcDateTimeInputComponent . tagName ) ;
1034+ } ) ;
1035+
1036+ it ( 'fails required validation' , ( ) => {
1037+ spec . assertIsPristine ( ) ;
1038+ spec . assertSubmitFails ( ) ;
1039+ } ) ;
1040+
1041+ it ( 'passes required validation when updating defaultValue' , ( ) => {
1042+ spec . setProperties ( { defaultValue : today . native } ) ;
1043+ spec . assertIsPristine ( ) ;
1044+
1045+ spec . assertSubmitPasses ( ) ;
1046+ } ) ;
1047+
1048+ it ( 'fails min validation' , ( ) => {
1049+ spec . setProperties ( {
1050+ min : today . native ,
1051+ defaultValue : today . add ( 'day' , - 1 ) . native ,
1052+ } ) ;
1053+
1054+ spec . assertIsPristine ( ) ;
1055+ spec . assertSubmitFails ( ) ;
1056+ } ) ;
1057+
1058+ it ( 'passes min validation' , ( ) => {
1059+ spec . setProperties ( { min : today . native , defaultValue : today . native } ) ;
1060+
1061+ spec . assertIsPristine ( ) ;
1062+ spec . assertSubmitPasses ( ) ;
1063+ } ) ;
1064+
1065+ it ( 'fails max validation' , ( ) => {
1066+ spec . setProperties ( {
1067+ max : today . native ,
1068+ defaultValue : today . native ,
1069+ } ) ;
1070+
1071+ spec . assertIsPristine ( ) ;
1072+ spec . assertSubmitFails ( ) ;
1073+ } ) ;
1074+
1075+ it ( 'passes max validation' , ( ) => {
1076+ spec . setProperties ( {
1077+ max : today . native ,
1078+ defaultValue : today . add ( 'day' , - 1 ) . native ,
1079+ } ) ;
1080+
1081+ spec . assertIsPristine ( ) ;
1082+ spec . assertSubmitPasses ( ) ;
1083+ } ) ;
1084+ } ) ;
1085+ } ) ;
1086+
10021087 describe ( 'Validation message slots' , ( ) => {
10031088 it ( '' , async ( ) => {
10041089 const now = CalendarDay . today ;
0 commit comments