Skip to content

Commit a98c876

Browse files
exyitomasherceg
authored andcommitted
UI tests tollerate whispace changes in datetime format
ICU update probably caused different whitespace being generated before AM/PM (no whitespace, &nbsp, and simple space are all possible).
1 parent 11acb9e commit a98c876

File tree

6 files changed

+48
-26
lines changed

6 files changed

+48
-26
lines changed

src/Samples/Tests/Tests/Control/TextBoxTests.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
4+
using System.Text.RegularExpressions;
45
using DotVVM.Samples.Tests.Base;
56
using DotVVM.Testing.Abstractions;
67
using 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

src/Samples/Tests/Tests/Feature/AutoUITests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Text.RegularExpressions;
56
using System.Threading.Tasks;
67
using DotVVM.Samples.Tests.Base;
78
using DotVVM.Testing.Abstractions;
@@ -128,7 +129,7 @@ public void Feature_AutoUI_AutoGridViewColumns()
128129
.ThrowIfDifferentCountThan(4);
129130
AssertUI.TextEquals(cells[0].Single("span"), "1");
130131
AssertUI.TextEquals(cells[1].Single("h2"), "John Doe");
131-
AssertUI.TextEquals(cells[2].Single("span"), "4/1/1976 12:00:00 AM");
132+
AssertUI.Text(cells[2].Single("span"), t => Regex.Replace(t, "\\s+", "") == "4/1/197612:00:00AM");
132133
AssertUI.IsNotChecked(cells[3].Single("input[type=checkbox]"));
133134
});
134135
}

src/Samples/Tests/Tests/Feature/DateTimeTranslationTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Text.RegularExpressions;
56
using System.Threading.Tasks;
67
using DotVVM.Samples.Tests.Base;
78
using DotVVM.Testing.Abstractions;
@@ -14,6 +15,9 @@ namespace DotVVM.Samples.Tests.Feature
1415
{
1516
public class DateTimeTranslationTests : AppSeleniumTest
1617
{
18+
// different versions of localization libraries may produce different whitespace (no space before AM/PM, no-break spaces, ...)
19+
static bool EqualsIgnoreSpace(string a, string b) => Regex.Replace(a, @"\s+", "") == Regex.Replace(b, @"\s+", "");
20+
1721
[Fact]
1822
public void Feature_DateTime_PropertyTranslations()
1923
{
@@ -45,18 +49,18 @@ public void Feature_DateTime_PropertyTranslations()
4549

4650
// try the conversion
4751
var localTextBox = browser.Single("input[data-ui=toBrowserLocalTime]");
48-
AssertUI.TextEquals(localTextBox, localDateTime);
52+
AssertUI.Text(localTextBox, t => EqualsIgnoreSpace(t, localDateTime));
4953

5054
localTextBox.Clear().SendKeys(localDateTime2).SendEnterKey();
51-
AssertUI.TextEquals(textbox, stringDateTime2);
55+
AssertUI.Text(textbox, t => EqualsIgnoreSpace(t, stringDateTime2));
5256

5357
// try the conversion on nullable
5458
var localTextBoxNullable = browser.Single("input[data-ui=toBrowserLocalTimeOnNullable]");
5559
var spanNullable = browser.Single("span[data-ui=toBrowserLocalTimeOnNullable]");
5660
AssertUI.TextEquals(localTextBoxNullable, "");
5761

5862
localTextBoxNullable.Clear().SendKeys(localDateTime2).SendEnterKey();
59-
AssertUI.TextEquals(spanNullable, stringDateTime2);
63+
AssertUI.Text(spanNullable, t => EqualsIgnoreSpace(t, stringDateTime2));
6064

6165
// try the null propagation
6266
var localTextBoxNullPropagation = browser.Single("input[data-ui=toBrowserLocalTimeNullPropagation]");

src/Samples/Tests/Tests/Feature/SerializationTests.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq;
2+
using System.Text.RegularExpressions;
23
using DotVVM.Samples.Tests.Base;
34
using DotVVM.Testing.Abstractions;
45
using OpenQA.Selenium;
@@ -253,6 +254,10 @@ public void Feature_Serialization_ByteArray()
253254
});
254255
}
255256

257+
// different versions of localization libraries may produce different whitespace (no space before AM/PM, no-break spaces, ...)
258+
static bool EqualsIgnoreSpace(string a, string b) => Regex.Replace(a, @"\s+", "") == Regex.Replace(b, @"\s+", "");
259+
260+
256261
[Fact]
257262
public void Feature_Serialization_DateOnly()
258263
{
@@ -290,16 +295,16 @@ public void Feature_Serialization_TimeOnly()
290295

291296
// Initial state
292297
const string initialTimeOnlyValue = "11:56:42 PM";
293-
AssertUI.TextEquals(timeOnlyTextBox, initialTimeOnlyValue);
294-
AssertUI.TextEquals(timeOnlySpan, initialTimeOnlyValue);
295-
AssertUI.TextEquals(timeOnlyPlain, "TimeOnly: " + initialTimeOnlyValue);
298+
AssertUI.Text(timeOnlyTextBox, t => EqualsIgnoreSpace(t, initialTimeOnlyValue));
299+
AssertUI.Text(timeOnlySpan, t => EqualsIgnoreSpace(t, initialTimeOnlyValue));
300+
AssertUI.Text(timeOnlyPlain, t => EqualsIgnoreSpace(t, "TimeOnly: " + initialTimeOnlyValue));
296301

297302
// Change date
298303
const string newTimeOnlyValue = "9:23:00 AM";
299304
timeOnlyTextBox.Clear().SendKeys(newTimeOnlyValue).SendEnterKey();
300-
AssertUI.TextEquals(timeOnlyTextBox, newTimeOnlyValue);
301-
AssertUI.TextEquals(timeOnlySpan, newTimeOnlyValue);
302-
AssertUI.TextEquals(timeOnlyPlain, "TimeOnly: " + newTimeOnlyValue);
305+
AssertUI.Text(timeOnlyTextBox, t => EqualsIgnoreSpace(t, newTimeOnlyValue));
306+
AssertUI.Text(timeOnlySpan, t => EqualsIgnoreSpace(t, newTimeOnlyValue));
307+
AssertUI.Text(timeOnlyPlain, t => EqualsIgnoreSpace(t, "TimeOnly: " + newTimeOnlyValue));
303308
});
304309
}
305310

src/Samples/Tests/Tests/Feature/StaticCommandTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Net;
55
using System.Net.Http;
6+
using System.Text.RegularExpressions;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using DotVVM.Samples.Tests.Base;
@@ -878,7 +879,9 @@ protected List<string> RowContent(IElementWrapper row, ICollection<int> cols)
878879
var content = new List<string>();
879880
foreach (var col in cols)
880881
{
881-
content.Add(cells.ElementAt(col).GetInnerText());
882+
var text = cells.ElementAt(col).GetInnerText();
883+
text = Regex.Replace(text, "\\s+", " "); // diffrent version of localization libraries can produce different whitespace (space, or no-break space)
884+
content.Add(text);
882885
}
883886

884887
return content;

src/Samples/Tests/Tests/Feature/ViewModelDeserializationTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using DotVVM.Samples.Tests.Base;
1+
using System.Text.RegularExpressions;
2+
using DotVVM.Samples.Tests.Base;
23
using DotVVM.Testing.Abstractions;
34
using Riganti.Selenium.Core;
45
using Xunit;
@@ -52,6 +53,10 @@ public void Feature_ViewModelDeserialization_NegativeLongNumber()
5253
});
5354
}
5455

56+
// different versions of localization libraries may produce different whitespace (no space before AM/PM, no-break spaces, ...)
57+
static bool EqualsIgnoreSpace(string a, string b) => Regex.Replace(a, @"\s+", "") == Regex.Replace(b, @"\s+", "");
58+
59+
5560
[Fact]
5661
public void Feature_ViewModelDeserialization_PropertyNullAssignment()
5762
{
@@ -64,13 +69,13 @@ public void Feature_ViewModelDeserialization_PropertyNullAssignment()
6469
AssertUI.InnerTextEquals(value, "");
6570

6671
buttons[0].Click();
67-
AssertUI.InnerTextEquals(value, "1/2/2023 3:04:05 AM");
72+
AssertUI.InnerText(value, t => EqualsIgnoreSpace(t, "1/2/2023 3:04:05 AM"));
6873

6974
buttons[1].Click();
7075
AssertUI.InnerTextEquals(value, "");
7176

7277
buttons[0].Click();
73-
AssertUI.InnerTextEquals(value, "1/2/2023 3:04:05 AM");
78+
AssertUI.InnerText(value, t => EqualsIgnoreSpace(t, "1/2/2023 3:04:05 AM"));
7479

7580
buttons[2].Click();
7681
AssertUI.InnerTextEquals(value, "");

0 commit comments

Comments
 (0)