11using System ;
22using System . Collections . Generic ;
33using System . Globalization ;
4+ using System . Text . RegularExpressions ;
45using DotVVM . Samples . Tests . Base ;
56using DotVVM . Testing . Abstractions ;
67using OpenQA . Selenium ;
@@ -125,6 +126,9 @@ private void CheckSelectAllOnFocus(IBrowserWrapper browser, string textBoxDataUi
125126 new object [ ] { "cs-CZ" , SamplesRouteUrls . ControlSamples_TextBox_TextBox_Format , "#czech" } ,
126127 new object [ ] { "en-US" , SamplesRouteUrls . ControlSamples_TextBox_TextBox_Format , "#english" } ,
127128 } ;
129+
130+ // different versions of localization libraries may produce different whitespace (no space before AM/PM, no-break spaces, ...)
131+ static bool EqualsIgnoreSpace ( string a , string b ) => Regex . Replace ( a , @"\s+" , "" ) == Regex . Replace ( b , @"\s+" , "" ) ;
128132
129133 [ Theory ]
130134 [ MemberData ( nameof ( TextBoxStringFormatChangedCommandData ) ) ]
@@ -145,13 +149,13 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
145149 AssertUI . Attribute ( dateTextBox , "value" , dateResult1 ) ;
146150
147151 var dateText = browser . First ( "#DateValueText" ) ;
148- AssertUI . InnerTextEquals ( dateText , new DateTime ( 2015 , 12 , 27 ) . ToString ( "G" , culture ) ) ;
152+ AssertUI . InnerText ( dateText , t => EqualsIgnoreSpace ( t , new DateTime ( 2015 , 12 , 27 ) . ToString ( "G" , culture ) ) ) ;
149153
150154 var nullableDateTextBox = browser . First ( "#nullableDateTextbox" ) ;
151- AssertUI . Attribute ( nullableDateTextBox , "value" , new DateTime ( 2015 , 12 , 27 ) . ToString ( "G" , culture ) ) ;
155+ AssertUI . Attribute ( nullableDateTextBox , "value" , t => EqualsIgnoreSpace ( t , new DateTime ( 2015 , 12 , 27 ) . ToString ( "G" , culture ) ) ) ;
152156
153157 var nullableDateText = browser . First ( "#nullableDateValueText" ) ;
154- AssertUI . InnerTextEquals ( nullableDateText , new DateTime ( 2015 , 12 , 27 ) . ToString ( "G" , culture ) ) ;
158+ AssertUI . InnerText ( nullableDateText , t => EqualsIgnoreSpace ( t , new DateTime ( 2015 , 12 , 27 ) . ToString ( "G" , culture ) ) ) ;
155159
156160 var numberTextbox = browser . First ( "#numberTextbox" ) ;
157161 AssertUI . Attribute ( numberTextbox , "value" , 123.1235 . ToString ( culture ) ) ;
@@ -171,7 +175,7 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
171175 dateTextBox . Click ( ) ;
172176
173177 //check new values
174- AssertUI . InnerTextEquals ( dateText , new DateTime ( 2018 , 12 , 27 ) . ToString ( "G" , culture ) ) ;
178+ AssertUI . InnerText ( dateText , t => EqualsIgnoreSpace ( t , new DateTime ( 2018 , 12 , 27 ) . ToString ( "G" , culture ) ) ) ;
175179 AssertUI . InnerTextEquals ( numberValueText , 2000 . ToString ( culture ) ) ;
176180
177181 AssertUI . Attribute ( numberTextbox , "value" , 2000 . ToString ( "n4" , culture ) ) ;
@@ -183,7 +187,7 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
183187 dateTextBox . Click ( ) ;
184188
185189 //check displayed values (behavior change in 3.0 - previous values should stay there)
186- AssertUI . InnerTextEquals ( dateText , new DateTime ( 2018 , 12 , 27 ) . ToString ( "G" , culture ) ) ;
190+ AssertUI . InnerText ( dateText , t => EqualsIgnoreSpace ( t , new DateTime ( 2018 , 12 , 27 ) . ToString ( "G" , culture ) ) ) ;
187191 AssertUI . InnerTextEquals ( numberValueText , 2000 . ToString ( culture ) ) ;
188192
189193 AssertUI . Attribute ( numberTextbox , "value" , "000//a" ) ;
@@ -195,20 +199,20 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
195199 dateTextBox . Click ( ) ;
196200
197201 //check new values
198- AssertUI . InnerTextEquals ( dateText , new DateTime ( 2018 , 1 , 1 ) . ToString ( "G" , culture ) ) ;
202+ AssertUI . InnerText ( dateText , t => EqualsIgnoreSpace ( t , new DateTime ( 2018 , 1 , 1 ) . ToString ( "G" , culture ) ) ) ;
199203 AssertUI . InnerTextEquals ( numberValueText , 1000.550277 . ToString ( culture ) ) ;
200204
201205 AssertUI . Attribute ( numberTextbox , "value" , 1000.550277 . ToString ( "n4" , culture ) ) ;
202206 AssertUI . Attribute ( dateTextBox , "value" , dateResult3 ) ;
203207
204208 // try to supply different date formats
205- dateTextBox . Clear ( ) . SendKeys ( new DateTime ( 2020 , 2 , 16 ) . ToString ( "G" , culture ) ) . SendKeys ( Keys . Tab ) ;
206- AssertUI . Attribute ( dateTextBox , "value" , new DateTime ( 2020 , 2 , 16 ) . ToString ( "d" , culture ) ) ;
207- AssertUI . InnerTextEquals ( dateText , new DateTime ( 2020 , 2 , 16 ) . ToString ( "G" , culture ) ) ;
209+ dateTextBox . Clear ( ) . SendKeys ( cultureName switch { "en-US" => "2/16/2020 12:00:00 AM" , "cs-CZ" => "16.02.2020 0:00:00" , _ => "" } ) . SendKeys ( Keys . Tab ) ;
210+ AssertUI . Attribute ( dateTextBox , "value" , t => EqualsIgnoreSpace ( t , new DateTime ( 2020 , 2 , 16 ) . ToString ( "d" , culture ) ) ) ;
211+ AssertUI . InnerText ( dateText , t => EqualsIgnoreSpace ( t , new DateTime ( 2020 , 2 , 16 ) . ToString ( "G" , culture ) ) ) ;
208212
209213 nullableDateTextBox . Clear ( ) . SendKeys ( new DateTime ( 2020 , 4 , 2 ) . ToString ( "d" , culture ) ) . SendKeys ( Keys . Tab ) ;
210- AssertUI . Attribute ( nullableDateTextBox , "value" , new DateTime ( 2020 , 4 , 2 ) . ToString ( "G" , culture ) ) ;
211- AssertUI . InnerTextEquals ( nullableDateText , new DateTime ( 2020 , 4 , 2 ) . ToString ( "G" , culture ) ) ;
214+ AssertUI . Attribute ( nullableDateTextBox , "value" , t => EqualsIgnoreSpace ( t , new DateTime ( 2020 , 4 , 2 ) . ToString ( "G" , culture ) ) ) ;
215+ AssertUI . InnerText ( nullableDateText , t => EqualsIgnoreSpace ( t , new DateTime ( 2020 , 4 , 2 ) . ToString ( "G" , culture ) ) ) ;
212216 } ) ;
213217 }
214218
0 commit comments