@@ -871,6 +871,189 @@ public void DatePicker_Multiple_Emits_IEnumerableDateOnlyAndTimeOnlyNullable()
871871 Assert. All ( timeList , t => Assert . Equal ( new TimeOnly ( 0 , 0 , 0 ) , t . Value ) ) ;
872872 }
873873
874+ [ Fact ]
875+ public void DatePicker_WithoutOkButton_TimeChange_ImmediatelyCommits ( )
876+ {
877+ using var ctx = new TestContext ( ) ;
878+ ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
879+ ctx. JSInterop . SetupModule ( "_content/Radzen.Blazor/Radzen.Blazor.js" ) ;
880+
881+ var changeCount = 0 ;
882+ DateTime? lastChangeValue = null ;
883+ DateTime? lastValueChanged = null ;
884+
885+ var component = ctx . RenderComponent < RadzenDatePicker < DateTime > > ( parameters =>
886+ {
887+ parameters . Add ( p => p . ShowTime , true ) ;
888+ parameters . Add ( p => p . ShowTimeOkButton , false ) ;
889+ parameters . Add ( p => p . Value , new DateTime ( 2024 , 6 , 15 , 10 , 30 , 0 ) ) ;
890+ parameters . Add ( p => p . Change , args => { changeCount ++ ; lastChangeValue = args ; } ) ;
891+ parameters . Add ( p => p . ValueChanged , args => { lastValueChanged = args ; } ) ;
892+ } ) ;
893+
894+ component. Find ( ".rz-hour-picker .rz-numeric-up" ) . Click ( ) ;
895+
896+ Assert. Equal ( 1 , changeCount ) ;
897+ Assert. NotNull ( lastChangeValue ) ;
898+ Assert. Equal ( 11 , lastChangeValue . Value . Hour ) ;
899+ Assert. NotNull ( lastValueChanged ) ;
900+ Assert. Equal ( 11 , lastValueChanged . Value . Hour ) ;
901+ }
902+
903+ [ Fact ]
904+ public void DatePicker_WithoutOkButton_DayClick_ImmediatelyCommits( )
905+ {
906+ using var ctx = new TestContext( ) ;
907+ ctx. JSInterop . Mode = JSRuntimeMode . Loose ;
908+ ctx. JSInterop . SetupModule ( "_content/Radzen.Blazor/Radzen.Blazor.js" ) ;
909+
910+ var changeRaised = false;
911+ DateTime? lastValueChanged = null ;
912+
913+ var component = ctx . RenderComponent < RadzenDatePicker < DateTime > > ( parameters =>
914+ {
915+ parameters . Add ( p => p . ShowTime , true ) ;
916+ parameters . Add ( p => p . ShowTimeOkButton , false ) ;
917+ parameters . Add ( p => p . Value , new DateTime ( 2024 , 6 , 15 , 10 , 30 , 0 ) ) ;
918+ parameters . Add ( p => p . Change , args => { changeRaised = true ; } ) ;
919+ parameters . Add ( p => p . ValueChanged , args => { lastValueChanged = args ; } ) ;
920+ } ) ;
921+
922+ component. FindAll ( "td:not(.rz-calendar-other-month) span" ) . First ( e => e . TextContent == "20" ) . ParentElement . Click ( ) ;
923+
924+ Assert. True ( changeRaised ) ;
925+ Assert. NotNull ( lastValueChanged ) ;
926+ Assert. Equal ( 20 , lastValueChanged . Value . Day ) ;
927+ Assert. Equal ( 10 , lastValueChanged . Value . Hour ) ;
928+ }
929+
930+ [ Fact ]
931+ public void DatePicker_WithOkButton_TimeChange_RevertsOnClose( )
932+ {
933+ using var ctx = new TestContext( ) ;
934+ ctx. JSInterop . Mode = JSRuntimeMode . Loose ;
935+ ctx. JSInterop . SetupModule ( "_content/Radzen.Blazor/Radzen.Blazor.js" ) ;
936+
937+ var initialDate = new DateTime ( 2024 , 6 , 15 , 10 , 30 , 0 ) ;
938+ var valueChangedCount = 0 ;
939+
940+ var component = ctx. RenderComponent< RadzenDatePicker< DateTime>> ( parameters =>
941+ {
942+ parameters . Add ( p => p . ShowTime , true ) ;
943+ parameters . Add ( p => p . ShowTimeOkButton , true ) ;
944+ parameters . Add ( p => p . Value , initialDate ) ;
945+ parameters . Add ( p => p . ValueChanged , args => { valueChangedCount ++ ; } ) ;
946+ } ) ;
947+
948+ var hourInput = component. Find ( ".rz-hour-picker input" ) ;
949+ Assert. Equal ( "10" , hourInput . GetAttribute ( "value" ) ) ;
950+
951+ component. Find ( ".rz-hour-picker .rz-numeric-up" ) . Click ( ) ;
952+
953+ hourInput = component. Find ( ".rz-hour-picker input" ) ;
954+ Assert. Equal ( "11" , hourInput . GetAttribute ( "value" ) ) ;
955+ Assert. Equal ( 0 , valueChangedCount ) ;
956+
957+ component. InvokeAsync ( ( ) => component . Instance . Close ( ) ) ;
958+
959+ hourInput = component. Find ( ".rz-hour-picker input" ) ;
960+ Assert. Equal ( "10" , hourInput . GetAttribute ( "value" ) ) ;
961+
962+ var input = component. Find ( ".rz-inputtext" ) ;
963+ Assert. Contains ( "10" , input . GetAttribute ( "value" ) ) ;
964+ }
965+
966+ [ Fact ]
967+ public void DatePicker_WithOkButton_TimeChange_CommitsOnOk( )
968+ {
969+ using var ctx = new TestContext( ) ;
970+ ctx. JSInterop . Mode = JSRuntimeMode . Loose ;
971+ ctx. JSInterop . SetupModule ( "_content/Radzen.Blazor/Radzen.Blazor.js" ) ;
972+
973+ DateTime? lastValueChanged = null ;
974+ DateTime? lastChangeValue = null ;
975+
976+ var component = ctx . RenderComponent < RadzenDatePicker < DateTime > > ( parameters =>
977+ {
978+ parameters . Add ( p => p . ShowTime , true ) ;
979+ parameters . Add ( p => p . ShowTimeOkButton , true ) ;
980+ parameters . Add ( p => p . Value , new DateTime ( 2024 , 6 , 15 , 10 , 30 , 0 ) ) ;
981+ parameters . Add ( p => p . ValueChanged , args => { lastValueChanged = args ; } ) ;
982+ parameters . Add ( p => p . Change , args => { lastChangeValue = args ; } ) ;
983+ } ) ;
984+
985+ component. Find ( ".rz-hour-picker .rz-numeric-up" ) . Click ( ) ;
986+ component. FindAll ( ".rz-button-text" ) . First ( x => x . TextContent == "Ok" ) . Click ( ) ;
987+
988+ Assert. NotNull ( lastValueChanged ) ;
989+ Assert. Equal ( 11 , lastValueChanged . Value . Hour ) ;
990+ Assert. NotNull ( lastChangeValue ) ;
991+ Assert. Equal ( 11 , lastChangeValue . Value . Hour ) ;
992+ }
993+
994+ [ Fact ]
995+ public void DatePicker_WithOkButton_DayCommits_ThenTimeRevertsOnClose( )
996+ {
997+ using var ctx = new TestContext( ) ;
998+ ctx. JSInterop . Mode = JSRuntimeMode . Loose ;
999+ ctx. JSInterop . SetupModule ( "_content/Radzen.Blazor/Radzen.Blazor.js" ) ;
1000+
1001+ DateTime? lastValueChanged = null ;
1002+
1003+ var component = ctx . RenderComponent < RadzenDatePicker < DateTime > > ( parameters =>
1004+ {
1005+ parameters . Add ( p => p . ShowTime , true ) ;
1006+ parameters . Add ( p => p . ShowTimeOkButton , true ) ;
1007+ parameters . Add ( p => p . Value , new DateTime ( 2024 , 6 , 15 , 10 , 30 , 0 ) ) ;
1008+ parameters . Add ( p => p . ValueChanged , args => { lastValueChanged = args ; } ) ;
1009+ } ) ;
1010+
1011+ component. FindAll ( "td:not(.rz-calendar-other-month) span" ) . First ( e => e . TextContent == "20" ) . ParentElement . Click ( ) ;
1012+
1013+ Assert. NotNull ( lastValueChanged ) ;
1014+ Assert. Equal ( 20 , lastValueChanged . Value . Day ) ;
1015+ Assert. Equal ( 10 , lastValueChanged . Value . Hour ) ;
1016+
1017+ component. Find ( ".rz-hour-picker .rz-numeric-up" ) . Click ( ) ;
1018+
1019+ component. InvokeAsync ( ( ) => component . Instance . Close ( ) ) ;
1020+
1021+ var input = component. Find ( ".rz-inputtext" ) ;
1022+ Assert. Contains ( "10" , input . GetAttribute ( "value" ) ) ;
1023+ Assert. Contains ( "20" , input . GetAttribute ( "value" ) ) ;
1024+ }
1025+
1026+ [ Fact ]
1027+ public void DatePicker_WithOkButton_OnPopupClose_RevertsTimeChange( )
1028+ {
1029+ using var ctx = new TestContext( ) ;
1030+ ctx. JSInterop . Mode = JSRuntimeMode . Loose ;
1031+ ctx. JSInterop . SetupModule ( "_content/Radzen.Blazor/Radzen.Blazor.js" ) ;
1032+
1033+ var initialDate = new DateTime ( 2024 , 6 , 15 , 10 , 30 , 0 ) ;
1034+ DateTime ? lastValueChanged = null ;
1035+ var valueChangedCount = 0 ;
1036+
1037+ var component = ctx . RenderComponent < RadzenDatePicker < DateTime > > ( parameters =>
1038+ {
1039+ parameters . Add ( p => p . ShowTime , true ) ;
1040+ parameters . Add ( p => p . ShowTimeOkButton , true ) ;
1041+ parameters . Add ( p => p . Value , initialDate ) ;
1042+ parameters . Add ( p => p . ValueChanged , args => { valueChangedCount ++ ; lastValueChanged = args ; } ) ;
1043+ } ) ;
1044+
1045+ component. Find ( ".rz-hour-picker .rz-numeric-up" ) . Click ( ) ;
1046+
1047+ var countBeforeClose = valueChangedCount;
1048+
1049+ component. InvokeAsync ( ( ) => component . Instance . OnPopupClose ( ) ) ;
1050+
1051+ Assert. Equal ( countBeforeClose , valueChangedCount ) ;
1052+
1053+ var input = component. Find ( "input" ) ;
1054+ Assert. Contains ( "10" , input . GetAttribute ( "value" ) ) ;
1055+ }
1056+
8741057 [ Fact ]
8751058 public void DatePicker_OkClick_Fires_OnOkButtonClick( )
8761059 {
0 commit comments