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 bf2e517
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
26 changes: 15 additions & 11 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));
AssertUI.Attribute(nullableDateTextBox, "value", t => EqualsIgnoreSpace(t, 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,20 +199,20 @@ 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));
AssertUI.Attribute(dateTextBox, "value", dateResult3);
// 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));
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);
AssertUI.Attribute(dateTextBox, "value", t => EqualsIgnoreSpace(t, new DateTime(2020, 2, 16).ToString("d", 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.Attribute(nullableDateTextBox, "value", t => EqualsIgnoreSpace(t, new DateTime(2020, 4, 2).ToString("G", culture)));
AssertUI.InnerText(nullableDateText, t => EqualsIgnoreSpace(t, new DateTime(2020, 4, 2).ToString("G", culture)));
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/Samples/Tests/Tests/Feature/AutoUITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DotVVM.Samples.Tests.Base;
using DotVVM.Testing.Abstractions;
Expand Down Expand Up @@ -128,7 +129,7 @@ public void Feature_AutoUI_AutoGridViewColumns()
.ThrowIfDifferentCountThan(4);
AssertUI.TextEquals(cells[0].Single("span"), "1");
AssertUI.TextEquals(cells[1].Single("h2"), "John Doe");
AssertUI.TextEquals(cells[2].Single("span"), "4/1/1976 12:00:00 AM");
AssertUI.Text(cells[2].Single("span"), t => Regex.Replace(t, "\\s+", "") == "4/1/197612:00:00AM");
AssertUI.IsNotChecked(cells[3].Single("input[type=checkbox]"));
});
}
Expand Down
10 changes: 7 additions & 3 deletions src/Samples/Tests/Tests/Feature/DateTimeTranslationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DotVVM.Samples.Tests.Base;
using DotVVM.Testing.Abstractions;
Expand All @@ -14,6 +15,9 @@ namespace DotVVM.Samples.Tests.Feature
{
public class DateTimeTranslationTests : AppSeleniumTest
{
// 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+", "");

[Fact]
public void Feature_DateTime_PropertyTranslations()
{
Expand Down Expand Up @@ -45,18 +49,18 @@ public void Feature_DateTime_PropertyTranslations()
// try the conversion
var localTextBox = browser.Single("input[data-ui=toBrowserLocalTime]");
AssertUI.TextEquals(localTextBox, localDateTime);
AssertUI.Text(localTextBox, t => EqualsIgnoreSpace(t, localDateTime));
localTextBox.Clear().SendKeys(localDateTime2).SendEnterKey();
AssertUI.TextEquals(textbox, stringDateTime2);
AssertUI.Text(textbox, t => EqualsIgnoreSpace(t, stringDateTime2));
// try the conversion on nullable
var localTextBoxNullable = browser.Single("input[data-ui=toBrowserLocalTimeOnNullable]");
var spanNullable = browser.Single("span[data-ui=toBrowserLocalTimeOnNullable]");
AssertUI.TextEquals(localTextBoxNullable, "");
localTextBoxNullable.Clear().SendKeys(localDateTime2).SendEnterKey();
AssertUI.TextEquals(spanNullable, stringDateTime2);
AssertUI.Text(spanNullable, t => EqualsIgnoreSpace(t, stringDateTime2));
// try the null propagation
var localTextBoxNullPropagation = browser.Single("input[data-ui=toBrowserLocalTimeNullPropagation]");
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
11 changes: 8 additions & 3 deletions src/Samples/Tests/Tests/Feature/ViewModelDeserializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DotVVM.Samples.Tests.Base;
using System.Text.RegularExpressions;
using DotVVM.Samples.Tests.Base;
using DotVVM.Testing.Abstractions;
using Riganti.Selenium.Core;
using Xunit;
Expand Down Expand Up @@ -52,6 +53,10 @@ public void Feature_ViewModelDeserialization_NegativeLongNumber()
});
}

// 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+", "");


[Fact]
public void Feature_ViewModelDeserialization_PropertyNullAssignment()
{
Expand All @@ -64,13 +69,13 @@ public void Feature_ViewModelDeserialization_PropertyNullAssignment()
AssertUI.InnerTextEquals(value, "");
buttons[0].Click();
AssertUI.InnerTextEquals(value, "1/2/2023 3:04:05 AM");
AssertUI.InnerText(value, t => EqualsIgnoreSpace(t, "1/2/2023 3:04:05 AM"));
buttons[1].Click();
AssertUI.InnerTextEquals(value, "");
buttons[0].Click();
AssertUI.InnerTextEquals(value, "1/2/2023 3:04:05 AM");
AssertUI.InnerText(value, t => EqualsIgnoreSpace(t, "1/2/2023 3:04:05 AM"));
buttons[2].Click();
AssertUI.InnerTextEquals(value, "");
Expand Down

0 comments on commit bf2e517

Please sign in to comment.