Skip to content

Commit

Permalink
Revert changes in old test assets and create new ones for scroll scen…
Browse files Browse the repository at this point in the history
…arios.
  • Loading branch information
ilonatommy committed Feb 21, 2025
1 parent 634fa8e commit c973c00
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,11 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(bool enable
// or to the beginning of a fragment, regardless of the previous scroll position
string landingPageSuffix = enableStreaming ? "" : "-no-streaming";
string buttonKeyword = programmaticNavigation ? "-programmatic" : "";
Navigate($"{ServerPathBase}/nav/testing-scroll{landingPageSuffix}");
Navigate($"{ServerPathBase}/nav/scroll-test{landingPageSuffix}");
EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress: !useEnhancedNavigation, skipNavigation: true);

// "scroll" page: scroll maximally down and go to "hash" page - we should land at the top of that page
AssertWeAreOnScrollTestPage();
// "landing" page: scroll maximally down and go to "next" page - we should land at the top of that page
AssertWeAreOnLandingPage();

// staleness check is used to assert enhanced navigation is enabled/disabled, as requested
var elementForStalenessCheckOnHashPage = Browser.Exists(By.TagName("html"));
Expand All @@ -695,8 +695,8 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(bool enable
Browser.SetScrollY(button1Pos);
Browser.Exists(By.Id(button1Id)).Click();

// "hash" page: check if we landed at 0, then navigate to "scroll"
AssertWeAreOnHashPage();
// "next" page: check if we landed at 0, then navigate to "landing"
AssertWeAreOnNextPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnHashPage);
Assert.Equal(0, Browser.GetScrollY());
Expand All @@ -705,14 +705,14 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(bool enable
var fragmentScrollPosition = (long)jsExecutor.ExecuteScript("return Math.round(document.getElementById('some-content').getBoundingClientRect().top + window.scrollY);");
Browser.Exists(By.Id(button1Id)).Click();

// "scroll" page: navigate to a fragment on another page - we should land at the beginning of the fragment
AssertWeAreOnScrollTestPage();
// "landing" page: navigate to a fragment on another page - we should land at the beginning of the fragment
AssertWeAreOnLandingPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnScrollPage);

var button2Id = $"do{buttonKeyword}-navigation-with-fragment";
Browser.Exists(By.Id(button2Id)).Click();
AssertWeAreOnHashPage();
AssertWeAreOnNextPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnHashPage);
var expectedFragmentScrollPosition = fragmentScrollPosition - 1;
Expand All @@ -733,11 +733,11 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnBackwardsForwardsActio
// This test checks if the scroll position is preserved after backwards/forwards action
string landingPageSuffix = enableStreaming ? "" : "-no-streaming";
string buttonKeyword = programmaticNavigation ? "-programmatic" : "";
Navigate($"{ServerPathBase}/nav/testing-scroll{landingPageSuffix}");
Navigate($"{ServerPathBase}/nav/scroll-test{landingPageSuffix}");
EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress: !useEnhancedNavigation, skipNavigation: true);

// "scroll" page: scroll to pos1, navigate away
AssertWeAreOnScrollTestPage();
// "landing" page: scroll to pos1, navigate away
AssertWeAreOnLandingPage();
WaitStreamingRendersFullPage(enableStreaming);

// staleness check is used to assert enhanced navigation is enabled/disabled, as requested
Expand All @@ -749,8 +749,8 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnBackwardsForwardsActio
Browser.SetScrollY(scrollPagePos1);
Browser.Exists(By.Id(buttonId)).Click();

// "hash" page: scroll to pos1, navigate away
AssertWeAreOnHashPage();
// "next" page: scroll to pos1, navigate away
AssertWeAreOnNextPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnHashPage);
var elementForStalenessCheckOnScrollPage = Browser.Exists(By.TagName("html"));
Expand All @@ -760,16 +760,16 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnBackwardsForwardsActio
Browser.SetScrollY(hashPagePos1);
Browser.Exists(By.Id(buttonId)).Click();

// "scroll" page: scroll to pos2, go backwards
AssertWeAreOnScrollTestPage();
// "landing" page: scroll to pos2, go backwards
AssertWeAreOnLandingPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnScrollPage);
var scrollPagePos2 = 500;
Browser.SetScrollY(scrollPagePos2);
Browser.Navigate().Back();

// "hash" page: check if we landed on pos1, move the scroll to pos2, go backwards
AssertWeAreOnHashPage();
// "next" page: check if we landed on pos1, move the scroll to pos2, go backwards
AssertWeAreOnNextPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnHashPage);
AssertScrollPositionCorrect(useEnhancedNavigation, hashPagePos1);
Expand All @@ -778,24 +778,24 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnBackwardsForwardsActio
Browser.SetScrollY(hashPagePos2);
Browser.Navigate().Back();

// "scroll" page: check if we landed on pos1, move the scroll to pos3, go forwards
AssertWeAreOnScrollTestPage();
// "landing" page: check if we landed on pos1, move the scroll to pos3, go forwards
AssertWeAreOnLandingPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnScrollPage);
AssertScrollPositionCorrect(useEnhancedNavigation, scrollPagePos1);
var scrollPagePos3 = 700;
Browser.SetScrollY(scrollPagePos3);
Browser.Navigate().Forward();

// "hash" page: check if we landed on pos1, go forwards
AssertWeAreOnHashPage();
// "next" page: check if we landed on pos1, go forwards
AssertWeAreOnNextPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnHashPage);
AssertScrollPositionCorrect(useEnhancedNavigation, hashPagePos2);
Browser.Navigate().Forward();

// "scroll" page: check if we landed on pos2
AssertWeAreOnScrollTestPage();
AssertWeAreOnLandingPage();
WaitStreamingRendersFullPage(enableStreaming);
AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnScrollPage);
AssertScrollPositionCorrect(useEnhancedNavigation, scrollPagePos2);
Expand All @@ -821,18 +821,18 @@ private void AssertEnhancedNavigation(bool useEnhancedNavigation, IWebElement el
Assert.Equal(useEnhancedNavigation, enhancedNavigationDetected);
}

private void AssertWeAreOnScrollTestPage()
private void AssertWeAreOnLandingPage()
{
string infoName = "test-info-scroll";
string infoName = "test-info-1";
Browser.WaitForElementToBeVisible(By.Id(infoName), timeoutInSeconds: 20);
Browser.Equal("Scroll tests landing page", () => Browser.Exists(By.Id(infoName)).Text);
}

private void AssertWeAreOnHashPage()
private void AssertWeAreOnNextPage()
{
string infoName = "test-info-hash";
string infoName = "test-info-2";
Browser.WaitForElementToBeVisible(By.Id(infoName), timeoutInSeconds: 20);
Browser.Equal("Scroll to hash", () => Browser.Exists(By.Id(infoName)).Text);
Browser.Equal("Scroll tests next page", () => Browser.Exists(By.Id(infoName)).Text);
}

private void WaitStreamingRendersFullPage(bool enableStreaming)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@page "/nav/scroll-to-hash"
@inject NavigationManager NavigationManager
@attribute [StreamRendering]
@rendermode RenderMode.InteractiveServer
@inject NavigationManager NavigationManager

<PageTitle>Page for scrolling to hash</PageTitle>

<h1 id="test-info-hash">Scroll to hash</h1>
<h1>Scroll to hash</h1>

<p>If you scroll down a long way, you'll find more content. We add it asynchronously via streaming rendering.</p>

Expand All @@ -14,27 +13,18 @@
<div id="uri-on-page-load" style="display: none" data-value="@uriOnPageLoad"></div>
</p>

<div style="height: 2000px; border: 2px dashed red;">top spacer</div>
<div style="height: 2000px; border: 2px dashed red;">spacer</div>

@if (showContent)
{
<h2 id="some-content">Some content</h2>
<NavLink id="do-navigation" href="@(scrollPagePath)">
Navigation to another page (testing-scroll)
</NavLink>
<button id="do-programmatic-navigation" @onclick="@(() => NavigationManager.NavigateTo(scrollPagePath))">
Programmatic navigation to another page (testing-scroll)
</button>

<p>This is the content.</p>
}

<div style="height: 2000px; border: 2px dashed red;">bottom spacer</div>

@code {
bool showContent;
string uriOnPageLoad;
string scrollPagePath = "nav/testing-scroll";

protected override async Task OnInitializedAsync()
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@page "/nav/testing-scroll"
@page "/nav/scroll-test"
@inject NavigationManager NavigationManager
@attribute [StreamRendering]
@rendermode RenderMode.InteractiveServer

<PageTitle>Page for testing scroll position</PageTitle>

<h1 id="test-info-scroll">Scroll tests landing page</h1>
<h1 id="test-info-1">Scroll tests landing page</h1>

<p>If you scroll down a long way, you'll find more content. We add it asynchronously via streaming rendering.</p>

Expand All @@ -14,16 +14,16 @@
@if (showContent)
{
<NavLink id="do-navigation-with-fragment" href="@(hashPageFragmentPath)">
Navigation to another page with fragment (scroll-to-hash#some-content)
Navigation to another page with fragment
</NavLink>
<NavLink id="do-navigation" href="@(hashPagePath)">
Navigation to another page (scroll-to-hash)
Navigation to another page
</NavLink>
<button id="do-programmatic-navigation-with-fragment" @onclick="@(() => NavigationManager.NavigateTo(hashPageFragmentPath))">
Programmatic navigation to another page with fragment (scroll-to-hash#some-content)
Programmatic navigation to another page with fragment
</button>
<button id="do-programmatic-navigation" @onclick="@(() => NavigationManager.NavigateTo(hashPagePath))">
Programmatic navigation to another page (scroll-to-hash)
Programmatic navigation to another page
</button>
}

Expand All @@ -38,8 +38,8 @@
@code {
bool showContent;
string uriOnPageLoad;
string hashPagePath = "nav/scroll-to-hash";
string hashPageFragmentPath = "nav/scroll-to-hash#some-content";
string hashPagePath = "nav/scroll-test-next";
string hashPageFragmentPath = "nav/scroll-test-next#some-content";

protected override async Task OnInitializedAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
@page "/nav/testing-scroll-no-streaming"
@page "/nav/scroll-test-no-streaming"
@inject NavigationManager NavigationManager
@rendermode RenderMode.InteractiveServer
@* This is a copy of PageForScrollPositionTests, without StreamRendering *@
@* This is a copy of ScrollTestLandingPage, without StreamRendering *@

<PageTitle>Page for testing scroll position</PageTitle>

<h1 id="test-info-scroll">Scroll tests landing page</h1>

<p>If you scroll down a long way, you'll find more content.</p>
<h1 id="test-info-1">Scroll tests landing page</h1>

<div style="height: 2000px; border: 2px dashed red;">spacer top</div>

<NavLink id="do-navigation-with-fragment" href="@(hashPageFragmentPath)">
Navigation to another page with fragment (scroll-to-hash#some-content)
Navigation to another page with fragment
</NavLink>
<NavLink id="do-navigation" href="@(hashPagePath)">
Navigation to another page (scroll-to-hash)
Navigation to another page
</NavLink>
<button id="do-programmatic-navigation-with-fragment" @onclick="@(() => NavigationManager.NavigateTo(hashPageFragmentPath))">
Programmatic navigation to another page with fragment (scroll-to-hash#some-content)
Programmatic navigation to another page with fragment
</button>
<button id="do-programmatic-navigation" @onclick="@(() => NavigationManager.NavigateTo(hashPagePath))">
Programmatic navigation to another page (scroll-to-hash)
Programmatic navigation to another page
</button>

<div style="height: 2000px; border: 2px dashed red;">spacer bottom</div>

<h2 id="some-content">Some content</h2>
<p>This is the content.</p>

@code {
string hashPagePath = "nav/scroll-to-hash-no-streaming";
string hashPageFragmentPath = "nav/scroll-to-hash-no-streaming#some-content";
string hashPagePath = "nav/scroll-test-next-no-streaming";
string hashPageFragmentPath = "nav/scroll-test-next-no-streaming#some-content";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@page "/nav/scroll-test-next"
@inject NavigationManager NavigationManager
@attribute [StreamRendering]
@rendermode RenderMode.InteractiveServer

<PageTitle>Next page for testing scroll position</PageTitle>

<h1 id="test-info-2">Scroll tests next page</h1>

<p>If you scroll down a long way, you'll find more content. We add it asynchronously via streaming rendering.</p>

<div style="height: 2000px; border: 2px dashed red;">top spacer</div>

@if (showContent)
{
<h2 id="some-content">Some content</h2>
<NavLink id="do-navigation" href="@(scrollPagePath)">
Navigation to another page
</NavLink>
<button id="do-programmatic-navigation" @onclick="@(() => NavigationManager.NavigateTo(scrollPagePath))">
Programmatic navigation to another page
</button>

<p>This is the content.</p>
}

<div style="height: 2000px; border: 2px dashed red;">bottom spacer</div>

@code {
bool showContent;
string scrollPagePath = "nav/scroll-test";

protected override async Task OnInitializedAsync()
{
await Task.Delay(1000);
showContent = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@page "/nav/scroll-test-next-no-streaming"
@inject NavigationManager NavigationManager
@rendermode RenderMode.InteractiveServer
@* This is a copy of ScrollTestNextPage, without StreamRendering *@

<PageTitle>Next page for testing scroll position</PageTitle>

<h1 id="test-info-2">Scroll tests next page</h1>

<div style="height: 1000px; border: 2px dashed red;">top spacer</div>

<h2 id="some-content">Some content</h2>
<NavLink id="do-navigation" href="@(scrollPagePath)">
Navigation to another page
</NavLink>
<button id="do-programmatic-navigation" @onclick="@(() => NavigationManager.NavigateTo(scrollPagePath))">
Programmatic navigation to another page
</button>

<div style="height: 2000px; border: 2px dashed red;">bottom spacer</div>

@code {
string scrollPagePath = "nav/scroll-test-no-streaming";
}

0 comments on commit c973c00

Please sign in to comment.