From d388cb651032dd5d6c4c70ab495fbf6bfae69be6 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 22 Feb 2018 14:51:01 +0000 Subject: [PATCH] Add E2E test covering nav menu and NavLink usage in StandaloneApp --- .../Tests/StandaloneAppTest.cs | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/StandaloneAppTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/StandaloneAppTest.cs index bfcac18d6e..05129d9937 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/StandaloneAppTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/StandaloneAppTest.cs @@ -11,11 +11,14 @@ using Xunit; namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests { public class StandaloneAppTest - : ServerTestBase> + : ServerTestBase>, IDisposable { + private readonly ServerFixture _serverFixture; + public StandaloneAppTest(BrowserFixture browserFixture, DevHostServerFixture serverFixture) : base(browserFixture, serverFixture) { + _serverFixture = serverFixture; Navigate("/", noReload: true); WaitUntilLoaded(); } @@ -42,10 +45,43 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests Assert.Equal("function", bootstrapTooltipType); } + [Fact] + public void NavMenuHighlightsCurrentLocation() + { + var activeNavLinksSelector = By.CssSelector(".main-nav a.active"); + var mainHeaderSelector = By.TagName("h1"); + + // Verify we start at home, with the home link highlighted + Assert.Equal("Hello, world!", Browser.FindElement(mainHeaderSelector).Text); + Assert.Collection(Browser.FindElements(activeNavLinksSelector), + item => Assert.Equal("Home", item.Text)); + + // Click on the "counter" link + Browser.FindElement(By.LinkText("Counter")).Click(); + + // Verify we're now on the counter page, with that nav link (only) highlighted + Assert.Equal("Counter", Browser.FindElement(mainHeaderSelector).Text); + Assert.Collection(Browser.FindElements(activeNavLinksSelector), + item => Assert.Equal("Counter", item.Text)); + + // Verify we can navigate back to home too + Browser.FindElement(By.LinkText("Home")).Click(); + Assert.Equal("Hello, world!", Browser.FindElement(mainHeaderSelector).Text); + Assert.Collection(Browser.FindElements(activeNavLinksSelector), + item => Assert.Equal("Home", item.Text)); + } + private void WaitUntilLoaded() { new WebDriverWait(Browser, TimeSpan.FromSeconds(30)).Until( driver => driver.FindElement(By.TagName("app")).Text != "Loading..."); } + + public void Dispose() + { + // Make the tests run faster by navigating back to the home page when we are done + // If we don't, then the next test will reload the whole page before it starts + Browser.FindElement(By.LinkText("Home")).Click(); + } } }