Skip to content

Commit ee4aa34

Browse files
committed
Fix RefreshCanFallBackOnFullPageReload
1 parent fa057a8 commit ee4aa34

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/Components/test/E2ETest/Infrastructure/ServerTestBase.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
5+
using Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests;
56
using Microsoft.AspNetCore.E2ETesting;
67
using OpenQA.Selenium;
78
using Xunit.Abstractions;
@@ -49,15 +50,7 @@ private void TryCleanSessionStorage()
4950
{
5051
try
5152
{
52-
// only tests that suppress enhanced navigation will have these items set
53-
var testId = ((IJavaScriptExecutor)Browser).ExecuteScript($"return sessionStorage.getItem('test-id')");
54-
if (testId == null)
55-
{
56-
return;
57-
}
58-
59-
((IJavaScriptExecutor)Browser).ExecuteScript($"sessionStorage.removeItem('test-id')");
60-
((IJavaScriptExecutor)Browser).ExecuteScript($"sessionStorage.removeItem('suppress-enhanced-navigation-{testId}')");
53+
EnhancedNavigationTestUtil.CleanEnhancedNavigationSuppression(this);
6154
}
6255
catch (Exception ex)
6356
{

src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ public void RefreshCanFallBackOnFullPageReload(string renderMode)
317317
Browser.Navigate().Refresh();
318318
Browser.Equal("Page with interactive components that navigate", () => Browser.Exists(By.TagName("h1")).Text);
319319

320+
// if we don't clean up the suppression, all subsequent navigations will be suppressed by default
321+
EnhancedNavigationTestUtil.CleanEnhancedNavigationSuppression(this);
322+
320323
// Normally, you shouldn't store references to elements because they could become stale references
321324
// after the page re-renders. However, we want to explicitly test that the element becomes stale
322325
// across renders to ensure that a full page reload occurs.

src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTestUtil.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ public static void SuppressEnhancedNavigation<TServerFixture>(ServerTestBase<TSe
4747
"Expected 'suppress-enhanced-navigation' to be set in sessionStorage.");
4848
}
4949
}
50+
51+
public static void CleanEnhancedNavigationSuppression<TServerFixture>(ServerTestBase<TServerFixture> fixture)
52+
where TServerFixture : ServerFixture
53+
{
54+
var browser = fixture.Browser;
55+
56+
// only tests that suppress enhanced navigation will have these items set, so it can throw
57+
var testId = ((IJavaScriptExecutor)browser).ExecuteScript($"return sessionStorage.getItem('test-id')");
58+
if (testId == null)
59+
{
60+
return;
61+
}
62+
63+
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.removeItem('test-id')");
64+
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.removeItem('suppress-enhanced-navigation-{testId}')");
65+
}
66+
5067
private static string GrantTestId(IWebDriver browser)
5168
{
5269
var testId = Guid.NewGuid().ToString("N")[..8];

0 commit comments

Comments
 (0)