Clarify IUriHelper GetAbsoluteUrl behavior. Fixes #9717 (#12422)

* E2E test showing it already works when navigating inside the app

* E2E test showing expected behavior around both sides of prerendering
This commit is contained in:
Steve Sanderson 2019-07-21 17:22:26 -07:00 committed by GitHub
parent e043f9317f
commit 22fbeac336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View File

@ -55,6 +55,26 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
Browser.Equal("Hello from interop call", () => Browser.FindElement(By.Id("val-set-by-interop")).GetAttribute("value"));
}
[Fact]
public void CanReadUrlHashOnlyOnceConnected()
{
var urlWithoutHash = "prerendered/show-uri?my=query&another=value";
var url = $"{urlWithoutHash}#some/hash?tokens";
// The server doesn't receive the hash part of the URL, so you can't
// read it during prerendering
Navigate(url);
Browser.Equal(
_serverFixture.RootUri + urlWithoutHash,
() => Browser.FindElement(By.TagName("strong")).Text);
// Once connected, you do have access to the full URL
BeginInteractivity();
Browser.Equal(
_serverFixture.RootUri + url,
() => Browser.FindElement(By.TagName("strong")).Text);
}
private void BeginInteractivity()
{
Browser.FindElement(By.Id("load-boot-script")).Click();

View File

@ -388,6 +388,19 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
Browser.Equal(initialUrl, () => app.FindElement(By.Id("test-info")).Text);
}
[Fact]
public void UriHelperCanReadAbsoluteUriIncludingHash()
{
var app = MountTestComponent<UriHelperComponent>();
Browser.Equal(Browser.Url, () => app.FindElement(By.Id("test-info")).Text);
var uri = "/mytestpath?my=query&another#some/hash?tokens";
var expectedAbsoluteUri = $"{_serverFixture.RootUri}subdir{uri}";
SetUrlViaPushState(uri);
Browser.Equal(expectedAbsoluteUri, () => app.FindElement(By.Id("test-info")).Text);
}
[Fact]
public void CanArriveAtRouteWithExtension()
{

View File

@ -0,0 +1,3 @@
@page "/show-uri"
@inject IUriHelper UriHelper
The current URL is <strong>@UriHelper.GetAbsoluteUri()</strong>