diff --git a/src/Components/test/E2ETest/ServerExecutionTests/GlobalizationTest.cs b/src/Components/test/E2ETest/ServerExecutionTests/GlobalizationTest.cs index ae4c699153fc5b9d397526a4cf31e25ec131fa06..af0ef6980e50d8906aa3a854f19963e8a0ca0ec7 100644 --- a/src/Components/test/E2ETest/ServerExecutionTests/GlobalizationTest.cs +++ b/src/Components/test/E2ETest/ServerExecutionTests/GlobalizationTest.cs @@ -41,16 +41,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests public void CanSetCultureAndParseCultueSensitiveNumbersAndDates(string culture) { var cultureInfo = CultureInfo.GetCultureInfo(culture); - - var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector"))); - selector.SelectByValue(culture); - - // That should have triggered a redirect, wait for the main test selector to come up. - MountTestComponent<GlobalizationBindCases>(); - WaitUntilExists(By.Id("globalization-cases")); - - var cultureDisplay = WaitUntilExists(By.Id("culture-name-display")); - Assert.Equal($"Culture is: {culture}", cultureDisplay.Text); + SetCulture(culture); // int var input = Browser.FindElement(By.Id("input_type_text_int")); @@ -113,16 +104,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests public void CanSetCultureAndParseCultureInvariantNumbersAndDatesWithInputFields(string culture) { var cultureInfo = CultureInfo.GetCultureInfo(culture); - - var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector"))); - selector.SelectByValue(culture); - - // That should have triggered a redirect, wait for the main test selector to come up. - MountTestComponent<GlobalizationBindCases>(); - WaitUntilExists(By.Id("globalization-cases")); - - var cultureDisplay = WaitUntilExists(By.Id("culture-name-display")); - Assert.Equal($"Culture is: {culture}", cultureDisplay.Text); + SetCulture(culture); // int var input = Browser.FindElement(By.Id("input_type_number_int")); @@ -179,16 +161,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests public void CanSetCultureAndParseCultureInvariantNumbersAndDatesWithFormComponents(string culture) { var cultureInfo = CultureInfo.GetCultureInfo(culture); - - var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector"))); - selector.SelectByValue(culture); - - // That should have triggered a redirect, wait for the main test selector to come up. - MountTestComponent<GlobalizationBindCases>(); - WaitUntilExists(By.Id("globalization-cases")); - - var cultureDisplay = WaitUntilExists(By.Id("culture-name-display")); - Assert.Equal($"Culture is: {culture}", cultureDisplay.Text); + SetCulture(culture); // int var input = Browser.FindElement(By.Id("inputnumber_int")); @@ -247,5 +220,21 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests element.SendKeys(Keys.Control + "a"); element.SendKeys(text); } + + private void SetCulture(string culture) + { + var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector"))); + selector.SelectByValue(culture); + + // Click the link to return back to the test page + WaitUntilExists(By.ClassName("return-from-culture-setter")).Click(); + + // That should have triggered a page load, so wait for the main test selector to come up. + MountTestComponent<GlobalizationBindCases>(); + WaitUntilExists(By.Id("globalization-cases")); + + var cultureDisplay = WaitUntilExists(By.Id("culture-name-display")); + Assert.Equal($"Culture is: {culture}", cultureDisplay.Text); + } } } diff --git a/src/Components/test/E2ETest/ServerExecutionTests/LocalizationTest.cs b/src/Components/test/E2ETest/ServerExecutionTests/LocalizationTest.cs index 94faed00bcd81867e27476159d282be7c0ecd22a..3faa49879d64be701d9b8394da15f3278e73f51f 100644 --- a/src/Components/test/E2ETest/ServerExecutionTests/LocalizationTest.cs +++ b/src/Components/test/E2ETest/ServerExecutionTests/LocalizationTest.cs @@ -40,7 +40,10 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests var selector = new SelectElement(Browser.FindElement(By.Id("culture-selector"))); selector.SelectByValue(culture); - // That should have triggered a redirect, wait for the main test selector to come up. + // Click the link to return back to the test page + WaitUntilExists(By.ClassName("return-from-culture-setter")).Click(); + + // That should have triggered a page load, so wait for the main test selector to come up. MountTestComponent<LocalizedText>(); var cultureDisplay = WaitUntilExists(By.Id("culture-name-display")); diff --git a/src/Components/test/testassets/BasicTestApp/CulturePicker.razor b/src/Components/test/testassets/BasicTestApp/CulturePicker.razor index 6e20528c69c1a42e130db8919674dca7df0c8b47..7a367ba766274f4b40b27f0032e782c19b4f8bec 100644 --- a/src/Components/test/testassets/BasicTestApp/CulturePicker.razor +++ b/src/Components/test/testassets/BasicTestApp/CulturePicker.razor @@ -12,7 +12,7 @@ { // Included fragment to preserve choice of Blazor client or server. var redirect = new Uri(NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery | UriComponents.Fragment, UriFormat.UriEscaped); - var query = $"?culture={Uri.EscapeDataString((string)e.Value)}&redirectUri={redirect}"; + var query = $"?culture={Uri.EscapeDataString((string)e.Value)}&redirectUri={Uri.EscapeDataString(redirect)}"; NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true); } } diff --git a/src/Components/test/testassets/TestServer/Controllers/CultureController.cs b/src/Components/test/testassets/TestServer/Controllers/CultureController.cs index f3cbaf8286e5c1c778c44de02ca01a3895617125..4466bb59c35290ed6f451ab6f5711b7eb166138c 100644 --- a/src/Components/test/testassets/TestServer/Controllers/CultureController.cs +++ b/src/Components/test/testassets/TestServer/Controllers/CultureController.cs @@ -1,5 +1,8 @@ +using System.Text.Encodings.Web; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.WebUtilities; +using Microsoft.Net.Http.Headers; namespace Components.TestServer.Controllers { @@ -15,7 +18,10 @@ namespace Components.TestServer.Controllers CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture))); } - return LocalRedirect(redirectUri); + var htmlEncoder = HtmlEncoder.Default; + var html = $"<h1>Culture has been changed to {htmlEncoder.Encode(culture)}</h1>" + + $"<a class='return-from-culture-setter' href='{htmlEncoder.Encode(redirectUri)}'>Return to previous page</a>"; + return Content(html, "text/html"); } } }