Skip to content

Commit

Permalink
Update E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSandersonMS committed Apr 16, 2024
1 parent 283150f commit 7f78bc7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
16 changes: 8 additions & 8 deletions src/Components/test/E2ETest/Tests/GlobalInteractivityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void CanFindStaticallyRenderedPageAfterClickingBrowserBackButtonOnDynamic
public void CanNavigateFromStaticToInteractiveAndBack()
{
// Start on a static page
Navigate("/subdir/globally-interactive/static-via-route");
Browser.Equal("Global interactivity page: Static via route", () => Browser.Exists(By.TagName("h1")).Text);
Navigate("/subdir/globally-interactive/static-via-attribute");
Browser.Equal("Global interactivity page: Static via attribute", () => Browser.Exists(By.TagName("h1")).Text);
Browser.Equal("static", () => Browser.Exists(By.Id("execution-mode")).Text);

// Navigate to an interactive page and observe it really is interactive
Expand All @@ -47,7 +47,7 @@ public void CanNavigateFromStaticToInteractiveAndBack()

// Show that, after "back", we revert to static rendering on the previous page
Browser.Navigate().Back();
Browser.Equal("Global interactivity page: Static via route", () => Browser.Exists(By.TagName("h1")).Text);
Browser.Equal("Global interactivity page: Static via attribute", () => Browser.Exists(By.TagName("h1")).Text);
Browser.Equal("static", () => Browser.Exists(By.Id("execution-mode")).Text);
}

Expand All @@ -60,8 +60,8 @@ public void CanNavigateFromInteractiveToStaticAndBack()
Browser.Equal("interactive webassembly", () => Browser.Exists(By.Id("execution-mode")).Text);

// Navigate to a static page
Browser.Click(By.LinkText("Static via route"));
Browser.Equal("Global interactivity page: Static via route", () => Browser.Exists(By.TagName("h1")).Text);
Browser.Click(By.LinkText("Static via attribute"));
Browser.Equal("Global interactivity page: Static via attribute", () => Browser.Exists(By.TagName("h1")).Text);
Browser.Equal("static", () => Browser.Exists(By.Id("execution-mode")).Text);

// Show that, after "back", we revert to interactive rendering on the previous page
Expand All @@ -74,10 +74,10 @@ public void CanNavigateFromInteractiveToStaticAndBack()
public void CanNavigateBetweenStaticPagesViaEnhancedNav()
{
// Start on a static page
Navigate("/subdir/globally-interactive/static-via-route");
Navigate("/subdir/globally-interactive/static-via-attribute");
Browser.Equal("static", () => Browser.Exists(By.Id("execution-mode")).Text);
var h1 = Browser.Exists(By.TagName("h1"));
Assert.Equal("Global interactivity page: Static via route", h1.Text);
Assert.Equal("Global interactivity page: Static via attribute", h1.Text);

// Navigate to another static page
// We check it's the same h1 element, because this is enhanced nav
Expand All @@ -87,7 +87,7 @@ public void CanNavigateBetweenStaticPagesViaEnhancedNav()

// Back also works
Browser.Navigate().Back();
Browser.Equal("Global interactivity page: Static via route", () => h1.Text);
Browser.Equal("Global interactivity page: Static via attribute", () => h1.Text);
Browser.Equal("static", () => Browser.Exists(By.Id("execution-mode")).Text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<head>
<meta charset="utf-8" />
<base href="/subdir/" />
<HeadOutlet @rendermode="@RenderModeForPage" />
<HeadOutlet @rendermode="@PageRenderMode" />
</head>
<body>
<Components.WasmMinimal.Routes @rendermode="@RenderModeForPage" />
<Components.WasmMinimal.Routes @rendermode="@PageRenderMode" />
<script src="_framework/blazor.web.js" autostart="false"></script>
<script>
Blazor.start({
Expand All @@ -22,9 +22,10 @@
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;

// Statically render a specific page to show we can override the rendermode based on URL
// Elsewhere, use global interactivity.
private IComponentRenderMode? RenderModeForPage => HttpContext.Request.Path.StartsWithSegments("/globally-interactive/static-via-url")
? null
: RenderMode.InteractiveWebAssembly;
// Show we can use arbitrary logic to determine the rendermode. Here it's global by default,
// but that can be suppressed via URL or attribute.
private IComponentRenderMode? PageRenderMode
=> HttpContext.AllowInteractiveRouting() && ! HttpContext.Request.Path.StartsWithSegments("/globally-interactive/static-via-url")
? RenderMode.InteractiveWebAssembly
: null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<ul>
<li><NavLink href="globally-interactive">Globally-interactive by default</NavLink></li>
<li><NavLink href="globally-interactive/static-via-url">Static via URL</NavLink></li>
<li><NavLink href="globally-interactive/static-via-route">Static via route</NavLink></li>
<li><NavLink href="globally-interactive/static-via-attribute">Static via attribute</NavLink></li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@page "/globally-interactive/static-via-attribute"
@using Microsoft.AspNetCore.Components.Routing
@attribute [AllowInteractiveRouting(false)]

<h1>Global interactivity page: Static via attribute</h1>

<p>
This page should be rendered statically by GlobalInteractivityApp because
it has [AllowInteractiveRouting(false)]
</p>

<ShowExecutionMode />

<GloballyInteractive_Links />

This file was deleted.

0 comments on commit 7f78bc7

Please sign in to comment.