Skip to content

Commit 92cd5b8

Browse files
Cleanups in E2E test code
1 parent 2d64856 commit 92cd5b8

File tree

4 files changed

+56
-68
lines changed

4 files changed

+56
-68
lines changed

src/Components/test/E2ETest/Tests/RoutingTest.cs

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -410,59 +410,54 @@ public void CanNavigateProgrammaticallyWithForceLoad()
410410
[Fact]
411411
public void CanNavigateProgrammaticallyValidateNoReplaceHistoryEntry()
412412
{
413-
//This test checks if default navigation does not replace Browser history entries
413+
// This test checks if default navigation does not replace Browser history entries
414414
SetUrlViaPushState("/");
415415

416416
var app = Browser.MountTestComponent<TestRouter>();
417417
var testSelector = Browser.WaitUntilTestSelectorReady();
418418

419-
app.FindElement(By.LinkText("TestHistory")).Click();
419+
app.FindElement(By.LinkText("Programmatic navigation cases")).Click();
420+
Browser.True(() => Browser.Url.EndsWith("/ProgrammaticNavigationCases", StringComparison.Ordinal));
421+
Browser.Contains("programmatic navigation", () => app.FindElement(By.Id("test-info")).Text);
420422

421-
Browser.True(() => Browser.Url.EndsWith("/TestHistory", StringComparison.Ordinal));
422-
Browser.Equal("This is the test history page.", () => app.FindElement(By.Id("test-info")).Text);
423-
424-
425-
//We navigate to the /Other page
426-
//This will also test our new NavigatTo(string uri) overload (it should not replace the browser history)
423+
// We navigate to the /Other page
424+
// This will also test our new NavigatTo(string uri) overload (it should not replace the browser history)
427425
app.FindElement(By.Id("do-other-navigation")).Click();
428426
Browser.True(() => Browser.Url.EndsWith("/Other", StringComparison.Ordinal));
429427
AssertHighlightedLinks("Other", "Other with base-relative URL (matches all)");
430428

429+
// After we press back, we should end up at the "/ProgrammaticNavigationCases" page so we know browser history has not been replaced
430+
// If history had been replaced we would have ended up at the "/" page
431431
Browser.Navigate().Back();
432-
//After we press back, we should end up at the "/TestHistory" page so we know browser history has not been replaced
433-
//If history would have been replaced we would have ended up at the "/" page
434-
Browser.True(() => Browser.Url.EndsWith("/TestHistory", StringComparison.Ordinal));
435-
AssertHighlightedLinks("TestHistory");
432+
Browser.True(() => Browser.Url.EndsWith("/ProgrammaticNavigationCases", StringComparison.Ordinal));
433+
AssertHighlightedLinks("Programmatic navigation cases");
436434

437-
//For completeness, we will test if the normal NavigateTo(string uri, bool forceLoad) overload will also NOT change the browsers history
438-
//So we basically repeat what we have done above
435+
// For completeness, we will test if the normal NavigateTo(string uri, bool forceLoad) overload will also
436+
// NOT change the browser's history. So we basically repeat what we have done above.
439437
app.FindElement(By.Id("do-other-navigation2")).Click();
440438
Browser.True(() => Browser.Url.EndsWith("/Other", StringComparison.Ordinal));
441439
AssertHighlightedLinks("Other", "Other with base-relative URL (matches all)");
442440

443441
Browser.Navigate().Back();
444-
Browser.True(() => Browser.Url.EndsWith("/TestHistory", StringComparison.Ordinal));
445-
AssertHighlightedLinks("TestHistory");
442+
Browser.True(() => Browser.Url.EndsWith("/ProgrammaticNavigationCases", StringComparison.Ordinal));
443+
AssertHighlightedLinks("Programmatic navigation cases");
446444

447445
// Because this was client-side navigation, we didn't lose the state in the test selector
448446
Assert.Equal(typeof(TestRouter).FullName, testSelector.SelectedOption.GetAttribute("value"));
449447

450448
app.FindElement(By.Id("do-other-navigation-forced")).Click();
451449
Browser.True(() => Browser.Url.EndsWith("/Other", StringComparison.Ordinal));
452450

453-
//We check if we had a force load
451+
// We check if we had a force load
454452
Assert.Throws<StaleElementReferenceException>(() =>
455-
{
456-
testSelector.SelectedOption.GetAttribute("value");
457-
});
453+
testSelector.SelectedOption.GetAttribute("value"));
458454

459-
////But still we should be able to navigate back, and end up at the "/TestHistory" page
455+
// But still we should be able to navigate back, and end up at the "/ProgrammaticNavigationCases" page
460456
Browser.Navigate().Back();
461-
Browser.True(() => Browser.Url.EndsWith("/TestHistory", StringComparison.Ordinal));
457+
Browser.True(() => Browser.Url.EndsWith("/ProgrammaticNavigationCases", StringComparison.Ordinal));
462458
Browser.WaitUntilTestSelectorReady();
463459
}
464460

465-
466461
[Fact]
467462
public void CanNavigateProgrammaticallyWithReplaceHistoryEntry()
468463
{
@@ -471,20 +466,18 @@ public void CanNavigateProgrammaticallyWithReplaceHistoryEntry()
471466
var app = Browser.MountTestComponent<TestRouter>();
472467
var testSelector = Browser.WaitUntilTestSelectorReady();
473468

474-
app.FindElement(By.LinkText("TestHistory")).Click();
475-
476-
Browser.True(() => Browser.Url.EndsWith("/TestHistory", StringComparison.Ordinal));
477-
Browser.Equal("This is the test history page.", () => app.FindElement(By.Id("test-info")).Text);
469+
app.FindElement(By.LinkText("Programmatic navigation cases")).Click();
470+
Browser.True(() => Browser.Url.EndsWith("/ProgrammaticNavigationCases", StringComparison.Ordinal));
471+
Browser.Contains("programmatic navigation", () => app.FindElement(By.Id("test-info")).Text);
478472

479-
480-
//We navigate to the /Other page, with replacehistroyentry enabled
473+
// We navigate to the /Other page, with "replace" enabled
481474
app.FindElement(By.Id("do-other-navigation-replacehistoryentry")).Click();
482475
Browser.True(() => Browser.Url.EndsWith("/Other", StringComparison.Ordinal));
483476
AssertHighlightedLinks("Other", "Other with base-relative URL (matches all)");
484477

478+
// After we press back, we should end up at the "/" page so we know browser history has been replaced
479+
// If history would not have been replaced we would have ended up at the "/ProgrammaticNavigationCases" page
485480
Browser.Navigate().Back();
486-
//After we press back, we should end up at the "/" page so we know browser history has been replaced
487-
//If history would not have been replaced we would have ended up at the "/TestHistory" page
488481
Browser.True(() => Browser.Url.EndsWith("/", StringComparison.Ordinal));
489482
AssertHighlightedLinks("Default (matches all)", "Default with base-relative URL (matches all)");
490483

@@ -500,29 +493,24 @@ public void CanNavigateProgrammaticallyWithForceLoadAndReplaceHistoryEntry()
500493
var app = Browser.MountTestComponent<TestRouter>();
501494
var testSelector = Browser.WaitUntilTestSelectorReady();
502495

503-
app.FindElement(By.LinkText("TestHistory")).Click();
504-
505-
Browser.True(() => Browser.Url.EndsWith("/TestHistory", StringComparison.Ordinal));
506-
Browser.Equal("This is the test history page.", () => app.FindElement(By.Id("test-info")).Text);
496+
app.FindElement(By.LinkText("Programmatic navigation cases")).Click();
497+
Browser.True(() => Browser.Url.EndsWith("/ProgrammaticNavigationCases", StringComparison.Ordinal));
498+
Browser.Contains("programmatic navigation", () => app.FindElement(By.Id("test-info")).Text);
507499

508-
//We navigate to the /Other page, with replacehistroyentry and forceload enabled
500+
// We navigate to the /Other page, with replacehistroyentry and forceload enabled
509501
app.FindElement(By.Id("do-other-navigation-forced-replacehistoryentry")).Click();
510502
Browser.True(() => Browser.Url.EndsWith("/Other", StringComparison.Ordinal));
511503

512-
//We check if we had a force load
504+
// We check if we had a force load
513505
Assert.Throws<StaleElementReferenceException>(() =>
514-
{
515-
testSelector.SelectedOption.GetAttribute("value");
516-
});
506+
testSelector.SelectedOption.GetAttribute("value"));
517507

508+
// After we press back, we should end up at the "/" page so we know browser history has been replaced
518509
Browser.Navigate().Back();
519-
//After we press back, we should end up at the "/" page so we know browser history has been replaced
520510
Browser.True(() => Browser.Url.EndsWith("/", StringComparison.Ordinal));
521511
Browser.WaitUntilTestSelectorReady();
522512
}
523513

524-
525-
526514
[Fact]
527515
public void ClickingAnchorWithNoHrefShouldNotNavigate()
528516
{

src/Components/test/testassets/BasicTestApp/RouterTest/Links.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
<li><NavLink href="Other" Match=NavLinkMatch.All>Other with base-relative URL (matches all)</NavLink></li>
1717
<li><NavLink href="/subdir/other?abc=123">Other with query</NavLink></li>
1818
<li><NavLink href="/subdir/Other#blah">Other with hash</NavLink></li>
19-
<li><NavLink href="/subdir/TestHistory">TestHistory</NavLink></li>
2019
<li><NavLink href="/subdir/WithParameters/name/Abc">With parameters</NavLink></li>
2120
<li><NavLink href="/subdir/WithParameters/Name/Abc/LastName/McDef">With more parameters</NavLink></li>
2221
<li><NavLink href="/subdir/LongPage1">Long page 1</NavLink></li>
2322
<li><NavLink href="/subdir/LongPage2">Long page 2</NavLink></li>
2423
<li><NavLink href="/subdir/WithLazyAssembly" id="with-lazy-assembly">With lazy assembly</NavLink></li>
2524
<li><NavLink href="/subdir/WithLazyLoadedRoutes" id="with-lazy-routes">With lazy loaded routes</NavLink></li>
25+
<li><NavLink href="/subdir/ProgrammaticNavigationCases">Programmatic navigation cases</NavLink></li>
2626
<li><NavLink href="PreventDefaultCases">preventDefault cases</NavLink></li>
2727
<li><a href="/subdir/images/blazor_logo_1000x.png" download>Download Me</a></li>
2828
<li><NavLink>Null href never matches</NavLink></li>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@page "/ProgrammaticNavigationCases"
2+
@inject NavigationManager NavigationManager
3+
4+
<div id="test-info">This page has test cases for programmatic navigation.</div>
5+
6+
<button id="do-other-navigation" @onclick="@(() => NavigationManager.NavigateTo("Other", new NavigationOptions()))">
7+
Programmatic navigation (NavigationOptions overload)
8+
</button>
9+
10+
<button id="do-other-navigation2" @onclick="@(() => NavigationManager.NavigateTo("Other", false))">
11+
Programmatic navigation (bool overload)
12+
</button>
13+
14+
<button id="do-other-navigation-forced" @onclick="@(() => NavigationManager.NavigateTo("Other", true))">
15+
Programmatic navigation with force-load
16+
</button>
17+
18+
<button id="do-other-navigation-replacehistoryentry" @onclick="@(() => NavigationManager.NavigateTo("Other", replace: true))">
19+
Programmatic navigation with replace
20+
</button>
21+
22+
<button id="do-other-navigation-forced-replacehistoryentry" @onclick="@(() => NavigationManager.NavigateTo("Other", forceLoad: true, replace: true))">
23+
Programmatic navigation with force-load and replace
24+
</button>

src/Components/test/testassets/BasicTestApp/RouterTest/TestHistory.razor

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)