Skip to content

Commit

Permalink
Hopefully fixed UI tests (ICU update probably)
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Oct 16, 2024
1 parent 0c5c7c6 commit 6d03d8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/Samples/Tests/Tests/Control/TextBoxTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using DotVVM.Samples.Tests.Base;
using DotVVM.Testing.Abstractions;
using OpenQA.Selenium;
Expand Down Expand Up @@ -125,6 +126,9 @@ private void CheckSelectAllOnFocus(IBrowserWrapper browser, string textBoxDataUi
new object[] { "cs-CZ", SamplesRouteUrls.ControlSamples_TextBox_TextBox_Format, "#czech"},
new object[] { "en-US", SamplesRouteUrls.ControlSamples_TextBox_TextBox_Format, "#english"},
};

// different versions of localization libraries may produce different whitespace (no space before AM/PM, no-break spaces, ...)
static bool EqualsIgnoreSpace(string a, string b) => Regex.Replace(a, @"\s+", "") == Regex.Replace(b, @"\s+", "");

[Theory]
[MemberData(nameof(TextBoxStringFormatChangedCommandData))]
Expand All @@ -145,13 +149,13 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
AssertUI.Attribute(dateTextBox, "value", dateResult1);

var dateText = browser.First("#DateValueText");
AssertUI.InnerTextEquals(dateText, new DateTime(2015, 12, 27).ToString("G", culture));
AssertUI.InnerText(dateText, t => EqualsIgnoreSpace(t, new DateTime(2015, 12, 27).ToString("G", culture)));

var nullableDateTextBox = browser.First("#nullableDateTextbox");
AssertUI.Attribute(nullableDateTextBox, "value", new DateTime(2015, 12, 27).ToString("G", culture));

var nullableDateText = browser.First("#nullableDateValueText");
AssertUI.InnerTextEquals(nullableDateText, new DateTime(2015, 12, 27).ToString("G", culture));
AssertUI.InnerText(nullableDateText, t => EqualsIgnoreSpace(t, new DateTime(2015, 12, 27).ToString("G", culture)));

var numberTextbox = browser.First("#numberTextbox");
AssertUI.Attribute(numberTextbox, "value", 123.1235.ToString(culture));
Expand All @@ -171,7 +175,7 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
dateTextBox.Click();

//check new values
AssertUI.InnerTextEquals(dateText, new DateTime(2018, 12, 27).ToString("G", culture));
AssertUI.InnerText(dateText, t => EqualsIgnoreSpace(t, new DateTime(2018, 12, 27).ToString("G", culture)));
AssertUI.InnerTextEquals(numberValueText, 2000.ToString(culture));

AssertUI.Attribute(numberTextbox, "value", 2000.ToString("n4", culture));
Expand All @@ -183,7 +187,7 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
dateTextBox.Click();

//check displayed values (behavior change in 3.0 - previous values should stay there)
AssertUI.InnerTextEquals(dateText, new DateTime(2018, 12, 27).ToString("G", culture));
AssertUI.InnerText(dateText, t => EqualsIgnoreSpace(t, new DateTime(2018, 12, 27).ToString("G", culture)));
AssertUI.InnerTextEquals(numberValueText, 2000.ToString(culture));

AssertUI.Attribute(numberTextbox, "value", "000//a");
Expand All @@ -195,7 +199,7 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
dateTextBox.Click();

//check new values
AssertUI.InnerTextEquals(dateText, new DateTime(2018, 1, 1).ToString("G", culture));
AssertUI.InnerText(dateText, t => EqualsIgnoreSpace(t, new DateTime(2018, 1, 1).ToString("G", culture)));
AssertUI.InnerTextEquals(numberValueText, 1000.550277.ToString(culture));

AssertUI.Attribute(numberTextbox, "value", 1000.550277.ToString("n4", culture));
Expand All @@ -204,11 +208,11 @@ public void Control_TextBox_StringFormat(string cultureName, string url, string
// try to supply different date formats
dateTextBox.Clear().SendKeys(new DateTime(2020, 2, 16).ToString("G", culture)).SendKeys(Keys.Tab);
AssertUI.Attribute(dateTextBox, "value", new DateTime(2020, 2, 16).ToString("d", culture));
AssertUI.InnerTextEquals(dateText, new DateTime(2020, 2, 16).ToString("G", culture));
AssertUI.InnerText(dateText, t => EqualsIgnoreSpace(t, new DateTime(2020, 2, 16).ToString("G", culture)));

nullableDateTextBox.Clear().SendKeys(new DateTime(2020, 4, 2).ToString("d", culture)).SendKeys(Keys.Tab);
AssertUI.Attribute(nullableDateTextBox, "value", new DateTime(2020, 4, 2).ToString("G", culture));
AssertUI.InnerTextEquals(nullableDateText, new DateTime(2020, 4, 2).ToString("G", culture));
AssertUI.InnerText(nullableDateText, t => EqualsIgnoreSpace(t, new DateTime(2020, 4, 2).ToString("G", culture)));
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/Samples/Tests/Tests/Feature/StaticCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using DotVVM.Samples.Tests.Base;
Expand Down Expand Up @@ -878,7 +879,9 @@ protected List<string> RowContent(IElementWrapper row, ICollection<int> cols)
var content = new List<string>();
foreach (var col in cols)
{
content.Add(cells.ElementAt(col).GetInnerText());
var text = cells.ElementAt(col).GetInnerText();
text = Regex.Replace(text, "\\s+", " "); // diffrent version of localization libraries can produce different whitespace (space, or no-break space)
content.Add(text);
}

return content;
Expand Down

0 comments on commit 6d03d8d

Please sign in to comment.