Fixed flaky test 'CanInfluenceHeadDuringPrerender'. (#24624)

This commit is contained in:
Mackinnon Buck 2020-08-06 14:02:30 -07:00 committed by GitHub
parent 9d783c5b76
commit 6c35e2e84d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 22 deletions

View File

@ -88,44 +88,31 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
{
Navigate("/prerendered/prerendered-head");
var metaWithBindings = Browser.FindElement(By.Id("meta-with-bindings"));
var metaNoBindings = Browser.FindElement(By.Id("meta-no-bindings"));
// Validate updated head during prerender
Browser.Equal("Initial title", () => Browser.Title);
Browser.Equal("Initial meta content", () => metaWithBindings.GetAttribute("content"));
Browser.Equal("Immutable meta content", () => metaNoBindings.GetAttribute("content"));
Browser.Equal("Initial meta content", () => GetMetaWithBindings().GetAttribute("content"));
Browser.Equal("Immutable meta content", () => GetMetaWithoutBindings().GetAttribute("content"));
BeginInteractivity();
// Wait for elements to be recreated with internal ids to permit mutation
metaWithBindings = WaitForNewElement(metaWithBindings, "meta-with-bindings");
metaNoBindings = WaitForNewElement(metaNoBindings, "meta-no-bindings");
// Wait until the component has rerendered
Browser.Exists(By.Id("interactive-indicator"));
// Validate updated head after prerender
Browser.Equal("Initial title", () => Browser.Title);
Browser.Equal("Initial meta content", () => metaWithBindings.GetAttribute("content"));
Browser.Equal("Immutable meta content", () => metaNoBindings.GetAttribute("content"));
Browser.Equal("Initial meta content", () => GetMetaWithBindings().GetAttribute("content"));
Browser.Equal("Immutable meta content", () => GetMetaWithoutBindings().GetAttribute("content"));
// Change parameter of meta component
var inputMetaBinding = Browser.FindElement(By.Id("input-meta-binding"));
inputMetaBinding.Clear();
inputMetaBinding.SendKeys("Updated meta content\n");
// Wait for meta tag to be recreated with new attributes
metaWithBindings = WaitForNewElement(metaWithBindings, "meta-with-bindings");
// Validate new meta content attribute
Browser.Equal("Updated meta content", () => metaWithBindings.GetAttribute("content"));
Browser.Equal("Updated meta content", () => GetMetaWithBindings().GetAttribute("content"));
IWebElement WaitForNewElement(IWebElement existingElement, string id)
{
var newElement = existingElement;
Browser.NotEqual(existingElement, () => newElement = Browser.FindElement(By.Id(id)) ?? newElement);
return newElement;
}
IWebElement GetMetaWithBindings() => Browser.FindElement(By.Id("meta-with-bindings"));
IWebElement GetMetaWithoutBindings() => Browser.FindElement(By.Id("meta-no-bindings"));
}
[Fact]

View File

@ -23,7 +23,23 @@
<Meta id="meta-no-bindings" content="Immutable meta content" />
@if (isInteractive)
{
<span id="interactive-indicator">Interactive mode enabled.</span>
}
@code {
private string title = "Initial title";
private string metaContent = "Initial meta content";
private bool isInteractive;
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
isInteractive = true;
StateHasChanged();
}
}
}