Stylistic tweaks
This commit is contained in:
parent
3610068929
commit
2492d00e75
|
|
@ -23,10 +23,9 @@ registerFunction(`${registeredFunctionPrefix}.enableNavigationInterception`, ()
|
||||||
if (anchorTarget) {
|
if (anchorTarget) {
|
||||||
const href = anchorTarget.getAttribute('href');
|
const href = anchorTarget.getAttribute('href');
|
||||||
const absoluteHref = toAbsoluteUri(href);
|
const absoluteHref = toAbsoluteUri(href);
|
||||||
//if the user wants to user some specific browser/OS feature, we dont handle it and let the browser/OS
|
|
||||||
const anyChangeBehaviorKeyHold = event.ctrlKey || event.shiftKey || event.altKey || event.metaKey;
|
// Don't stop ctrl/meta-click (etc) from opening links in new tabs/windows
|
||||||
if (isWithinBaseUriSpace(absoluteHref) && !anyChangeBehaviorKeyHold)
|
if (isWithinBaseUriSpace(absoluteHref) && !eventHasSpecialKey(event)) {
|
||||||
{
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
performInternalNavigation(absoluteHref);
|
performInternalNavigation(absoluteHref);
|
||||||
}
|
}
|
||||||
|
|
@ -92,3 +91,7 @@ function isWithinBaseUriSpace(href: string) {
|
||||||
function toBaseUriWithTrailingSlash(baseUri: string) {
|
function toBaseUriWithTrailingSlash(baseUri: string) {
|
||||||
return baseUri.substr(0, baseUri.lastIndexOf('/') + 1);
|
return baseUri.substr(0, baseUri.lastIndexOf('/') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function eventHasSpecialKey(event: MouseEvent) {
|
||||||
|
return event.ctrlKey || event.shiftKey || event.altKey || event.metaKey;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,43 +88,42 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanFollowLinkToOtherPageWithCtrlClick()
|
public void CanFollowLinkToOtherPageWithCtrlClick()
|
||||||
{
|
{
|
||||||
|
// On macOS we need to hold the command key not the control for opening a popup
|
||||||
var key = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? Keys.Command : Keys.Control;
|
var key = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? Keys.Command : Keys.Control;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SetUrlViaPushState($"{ServerPathBase}/RouterTest/");
|
SetUrlViaPushState($"{ServerPathBase}/");
|
||||||
|
|
||||||
var app = MountTestComponent<TestRouter>();
|
var app = MountTestComponent<TestRouter>();
|
||||||
var button = app.FindElement(By.LinkText("Other"));
|
var button = app.FindElement(By.LinkText("Other"));
|
||||||
//on mac os build we need to hold the meta button not the control for openning a popup
|
|
||||||
|
|
||||||
new Actions(Browser)
|
new Actions(Browser).KeyDown(key).Click(button).Build().Perform();
|
||||||
.KeyDown(Keys.Control)
|
|
||||||
.Click(button)
|
|
||||||
.Build()
|
|
||||||
.Perform();
|
|
||||||
|
|
||||||
Assert.Equal(2, Browser.WindowHandles.Count);
|
Assert.Equal(2, Browser.WindowHandles.Count);
|
||||||
|
|
||||||
//closing newly opened windows if a new one was opened
|
|
||||||
|
|
||||||
Browser.SwitchTo().Window(Browser.WindowHandles.Last());
|
|
||||||
Browser.Close();
|
|
||||||
Browser.SwitchTo().Window(Browser.WindowHandles.First());
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// leaving the ctrl key up
|
// Leaving the ctrl key up
|
||||||
new Actions(Browser)
|
new Actions(Browser).KeyUp(key).Build().Perform();
|
||||||
.KeyUp(key)
|
|
||||||
.Build()
|
// Closing newly opened windows if a new one was opened
|
||||||
.Perform();
|
while (Browser.WindowHandles.Count > 1)
|
||||||
|
{
|
||||||
|
Browser.SwitchTo().Window(Browser.WindowHandles.Last());
|
||||||
|
Browser.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Needed otherwise Selenium tries to direct subsequent commands
|
||||||
|
// to the tab that has already been closed
|
||||||
|
Browser.SwitchTo().Window(Browser.WindowHandles.First());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanFollowLinkToOtherPageDoesNotOpenNewWindow()
|
public void CanFollowLinkToOtherPageDoesNotOpenNewWindow()
|
||||||
{
|
{
|
||||||
SetUrlViaPushState($"{ServerPathBase}/RouterTest/");
|
SetUrlViaPushState($"{ServerPathBase}/");
|
||||||
|
|
||||||
var app = MountTestComponent<TestRouter>();
|
var app = MountTestComponent<TestRouter>();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue