@@ -2011,6 +2011,78 @@ public void CanBindTimeStepTextboxNullableTimeOnly()
20112011 Assert . Equal ( string . Empty , mirrorValue . GetAttribute ( "value" ) ) ;
20122012 }
20132013
2014+ [ Fact ]
2015+ public void CanBindDateTimeLocalDefaultStepTextboxDateTime ( )
2016+ {
2017+ // This test differs from the other "step"-related test in that the DOM element has no "step" attribute
2018+ // and hence defaults to step=60, and for this the framework has explicit logic to strip off the "seconds"
2019+ // part of the bound value (otherwise the browser reports it as invalid - issue #41731)
2020+
2021+ var target = Browser . Exists ( By . Id ( "datetime-local-default-step-textbox-datetime" ) ) ;
2022+ var boundValue = Browser . Exists ( By . Id ( "datetime-local-default-step-textbox-datetime-value" ) ) ;
2023+ var expected = DateTime . Now . Date . Add ( new TimeSpan ( 8 , 5 , 0 ) ) ; // Notice the "seconds" part is zero here, even though the original data has seconds=30
2024+ Assert . Equal ( expected , DateTime . Parse ( target . GetAttribute ( "value" ) , CultureInfo . InvariantCulture ) ) ;
2025+
2026+ // Clear textbox; value updates to 00:00 because that's the default
2027+ target . Clear ( ) ;
2028+ expected = default ;
2029+ Browser . Equal ( default , ( ) => DateTime . Parse ( target . GetAttribute ( "value" ) , CultureInfo . InvariantCulture ) ) ;
2030+ Assert . Equal ( default , DateTime . Parse ( boundValue . Text , CultureInfo . InvariantCulture ) ) ;
2031+
2032+ // We have to do it this way because the browser gets in the way when sending keys to the input element directly.
2033+ ApplyInputValue ( "#datetime-local-default-step-textbox-datetime" , "2000-01-02T04:05" ) ;
2034+ expected = new DateTime ( 2000 , 1 , 2 , 04 , 05 , 0 ) ;
2035+ Browser . Equal ( expected , ( ) => DateTime . Parse ( boundValue . Text , CultureInfo . InvariantCulture ) ) ;
2036+ }
2037+
2038+ [ Fact ]
2039+ public void CanBindTimeDefaultStepTextboxDateTime ( )
2040+ {
2041+ // This test differs from the other "step"-related test in that the DOM element has no "step" attribute
2042+ // and hence defaults to step=60, and for this the framework has explicit logic to strip off the "seconds"
2043+ // part of the bound value (otherwise the browser reports it as invalid - issue #41731)
2044+
2045+ var target = Browser . Exists ( By . Id ( "time-default-step-textbox-datetime" ) ) ;
2046+ var boundValue = Browser . Exists ( By . Id ( "time-default-step-textbox-datetime-value" ) ) ;
2047+ var expected = DateTime . Now . Date . Add ( new TimeSpan ( 8 , 5 , 0 ) ) ; // Notice the "seconds" part is zero here, even though the original data has seconds=30
2048+ Assert . Equal ( expected , DateTime . Parse ( target . GetAttribute ( "value" ) , CultureInfo . InvariantCulture ) ) ;
2049+
2050+ // Clear textbox; value updates to 00:00 because that's the default
2051+ target . Clear ( ) ;
2052+ expected = default ;
2053+ Browser . Equal ( DateTime . Now . Date , ( ) => DateTime . Parse ( target . GetAttribute ( "value" ) , CultureInfo . InvariantCulture ) ) ;
2054+ Assert . Equal ( default , DateTime . Parse ( boundValue . Text , CultureInfo . InvariantCulture ) ) ;
2055+
2056+ // We have to do it this way because the browser gets in the way when sending keys to the input element directly.
2057+ ApplyInputValue ( "#time-default-step-textbox-datetime" , "04:05" ) ;
2058+ expected = DateTime . Now . Date . Add ( new TimeSpan ( 4 , 5 , 0 ) ) ;
2059+ Browser . Equal ( expected , ( ) => DateTime . Parse ( boundValue . Text , CultureInfo . InvariantCulture ) ) ;
2060+ }
2061+
2062+ [ Fact ]
2063+ public void CanBindTimeDefaultStepTextboxTimeOnly ( )
2064+ {
2065+ // This test differs from the other "step"-related test in that the DOM element has no "step" attribute
2066+ // and hence defaults to step=60, and for this the framework has explicit logic to strip off the "seconds"
2067+ // part of the bound value (otherwise the browser reports it as invalid - issue #41731)
2068+
2069+ var target = Browser . Exists ( By . Id ( "time-default-step-textbox-timeonly" ) ) ;
2070+ var boundValue = Browser . Exists ( By . Id ( "time-default-step-textbox-timeonly-value" ) ) ;
2071+ var expected = new TimeOnly ( 8 , 5 , 0 ) ; // Notice the "seconds" part is zero here, even though the original data has seconds=30
2072+ Assert . Equal ( expected , TimeOnly . Parse ( target . GetAttribute ( "value" ) , CultureInfo . InvariantCulture ) ) ;
2073+
2074+ // Clear textbox; value updates to 00:00 because that's the default
2075+ target . Clear ( ) ;
2076+ expected = default ;
2077+ Browser . Equal ( default , ( ) => TimeOnly . Parse ( target . GetAttribute ( "value" ) , CultureInfo . InvariantCulture ) ) ;
2078+ Assert . Equal ( default , TimeOnly . Parse ( boundValue . Text , CultureInfo . InvariantCulture ) ) ;
2079+
2080+ // We have to do it this way because the browser gets in the way when sending keys to the input element directly.
2081+ ApplyInputValue ( "#time-default-step-textbox-timeonly" , "04:05" ) ;
2082+ expected = new TimeOnly ( 4 , 5 , 0 ) ;
2083+ Browser . Equal ( expected , ( ) => TimeOnly . Parse ( boundValue . Text , CultureInfo . InvariantCulture ) ) ;
2084+ }
2085+
20142086 // Applies an input through javascript to datetime-local/month/time controls.
20152087 private void ApplyInputValue ( string cssSelector , string value )
20162088 {
0 commit comments