* E2E test to show current behavior * Actually support base-relative, root-relative, and absolute redirections during prerendering * Fix MVC functional test
This commit is contained in:
parent
178374d228
commit
077df0e3ca
|
|
@ -88,8 +88,10 @@ namespace Microsoft.AspNetCore.Components.Server.Circuits
|
|||
|
||||
if (_jsRuntime == null)
|
||||
{
|
||||
throw new NavigationException(uri);
|
||||
var absoluteUriString = ToAbsoluteUri(uri).ToString();
|
||||
throw new NavigationException(absoluteUriString);
|
||||
}
|
||||
|
||||
_jsRuntime.InvokeAsync<object>(Interop.NavigateTo, uri, forceLoad);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
|
||||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
|
||||
using Microsoft.AspNetCore.E2ETesting;
|
||||
|
|
@ -75,6 +79,24 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
|
|||
() => Browser.FindElement(By.TagName("strong")).Text);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("base/relative", "prerendered/base/relative")]
|
||||
[InlineData("/root/relative", "/root/relative")]
|
||||
[InlineData("http://absolute/url", "http://absolute/url")]
|
||||
public async Task CanRedirectDuringPrerendering(string destinationParam, string expectedRedirectionLocation)
|
||||
{
|
||||
var requestUri = new Uri(
|
||||
_serverFixture.RootUri,
|
||||
"prerendered/prerendered-redirection?destination=" + destinationParam);
|
||||
|
||||
var httpClient = new HttpClient(new HttpClientHandler { AllowAutoRedirect = false });
|
||||
var response = await httpClient.GetAsync(requestUri);
|
||||
|
||||
var expectedUri = new Uri(_serverFixture.RootUri, expectedRedirectionLocation);
|
||||
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
|
||||
Assert.Equal(expectedUri, response.Headers.Location);
|
||||
}
|
||||
|
||||
private void BeginInteractivity()
|
||||
{
|
||||
Browser.FindElement(By.Id("load-boot-script")).Click();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
@page "/prerendered-redirection"
|
||||
@inject IUriHelper UriHelper
|
||||
|
||||
@{
|
||||
throw new InvalidOperationException("The rendering logic should never be executed");
|
||||
}
|
||||
|
||||
@code {
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
var uri = UriHelper.GetAbsoluteUri();
|
||||
var destination = uri.Substring(uri.IndexOf("?destination=") + 13);
|
||||
UriHelper.NavigateTo(destination);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
|
||||
// Assert
|
||||
await response.AssertStatusCodeAsync(HttpStatusCode.Redirect);
|
||||
Assert.Equal("/navigation-redirect", response.Headers.Location.ToString());
|
||||
Assert.Equal("http://localhost/navigation-redirect", response.Headers.Location.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -99,10 +99,9 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
|
||||
var response = await client.GetAsync("http://localhost/components/Navigation/false");
|
||||
|
||||
// Assert
|
||||
// Assert
|
||||
await response.AssertStatusCodeAsync(HttpStatusCode.Redirect);
|
||||
Assert.Equal("/navigation-redirect", response.Headers.Location.ToString());
|
||||
Assert.Equal("http://localhost/navigation-redirect", response.Headers.Location.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in New Issue