Skip to content

Commit 2b313d5

Browse files
committed
Move tests to WebAssembly-only scenarios
1 parent dbcfe11 commit 2b313d5

File tree

2 files changed

+112
-65
lines changed

2 files changed

+112
-65
lines changed

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

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -522,46 +522,7 @@ public void PreventDefault_CanBlockNavigation(string navigationType, string wher
522522
}
523523
}
524524

525-
[Fact]
526-
public void CanLazyLoadOnRouteChange()
527-
{
528-
// Navigate to a page without any lazy-loaded dependencies
529-
SetUrlViaPushState("/");
530-
var app = Browser.MountTestComponent<TestRouter>();
531-
532-
// Ensure that we haven't requested the lazy loaded assembly
533-
Assert.False(HasLoadedAssembly("Newtonsoft.Json.dll"));
534-
535-
// Visit the route for the lazy-loaded assembly
536-
SetUrlViaPushState("/WithDynamicAssembly");
537-
538-
var button = app.FindElement(By.Id("use-package-button"));
539-
540-
// Now we should have requested the DLL
541-
Assert.True(HasLoadedAssembly("Newtonsoft.Json.dll"));
542-
543-
button.Click();
544-
545-
// We shouldn't get any errors about assemblies not being available
546-
AssertLogDoesNotContainCriticalMessages("Could not load file or assembly 'Newtonsoft.Json");
547-
}
548-
549-
[Fact]
550-
public void CanLazyLoadOnFirstVisit()
551-
{
552-
// Navigate to a page with lazy loaded assemblies for the first time
553-
SetUrlViaPushState("/WithDynamicAssembly");
554-
var app = Browser.MountTestComponent<TestRouter>();
555-
var button = app.FindElement(By.Id("use-package-button"));
556-
557-
// We should have requested the DLL
558-
Assert.True(HasLoadedAssembly("Newtonsoft.Json.dll"));
559-
560-
button.Click();
561-
562-
// We shouldn't get any errors about assemblies not being available
563-
AssertLogDoesNotContainCriticalMessages("Could not load file or assembly 'Newtonsoft.Json");
564-
}
525+
565526

566527
private long BrowserScrollY
567528
{
@@ -579,36 +540,11 @@ private string SetUrlViaPushState(string relativeUri)
579540
return absoluteUri.AbsoluteUri;
580541
}
581542

582-
private bool HasLoadedAssembly(string name)
583-
{
584-
var checkScript = $"return window.performance.getEntriesByType('resource').some(r => r.name.endsWith('{name}'));";
585-
var jsExecutor = (IJavaScriptExecutor)Browser;
586-
var nameRequested = jsExecutor.ExecuteScript(checkScript);
587-
if (nameRequested != null)
588-
{
589-
return (bool)nameRequested;
590-
}
591-
return false;
592-
}
593-
594543
private void AssertHighlightedLinks(params string[] linkTexts)
595544
{
596545
Browser.Equal(linkTexts, () => Browser
597546
.FindElements(By.CssSelector("a.active"))
598547
.Select(x => x.Text));
599548
}
600-
601-
private void AssertLogDoesNotContainCriticalMessages(params string[] messages)
602-
{
603-
var log = Browser.Manage().Logs.GetLog(LogType.Browser);
604-
foreach (var message in messages)
605-
{
606-
Assert.DoesNotContain(log, entry =>
607-
{
608-
return entry.Level == LogLevel.Severe
609-
&& entry.Message.Contains(message);
610-
});
611-
}
612-
}
613549
}
614550
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using BasicTestApp;
6+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
7+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
8+
using Microsoft.AspNetCore.E2ETesting;
9+
using OpenQA.Selenium;
10+
using Xunit;
11+
using Xunit.Abstractions;
12+
13+
namespace Microsoft.AspNetCore.Components.E2ETest.Tests
14+
{
15+
public class WebAssemblyLazyLoadTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
16+
{
17+
public WebAssemblyLazyLoadTest(
18+
BrowserFixture browserFixture,
19+
ToggleExecutionModeServerFixture<Program> serverFixture,
20+
ITestOutputHelper output)
21+
: base(browserFixture, serverFixture, output)
22+
{
23+
}
24+
25+
protected override void InitializeAsyncCore()
26+
{
27+
Navigate(ServerPathBase, noReload: false);
28+
Browser.MountTestComponent<TestRouter>();
29+
Browser.Exists(By.Id("blazor-error-ui"));
30+
31+
var errorUi = Browser.FindElement(By.Id("blazor-error-ui"));
32+
Assert.Equal("none", errorUi.GetCssValue("display"));
33+
}
34+
35+
[Fact]
36+
public void CanLazyLoadOnRouteChange()
37+
{
38+
// Navigate to a page without any lazy-loaded dependencies
39+
SetUrlViaPushState("/");
40+
var app = Browser.MountTestComponent<TestRouter>();
41+
42+
// Ensure that we haven't requested the lazy loaded assembly
43+
Assert.False(HasLoadedAssembly("Newtonsoft.Json.dll"));
44+
45+
// Visit the route for the lazy-loaded assembly
46+
SetUrlViaPushState("/WithDynamicAssembly");
47+
48+
var button = app.FindElement(By.Id("use-package-button"));
49+
50+
// Now we should have requested the DLL
51+
Assert.True(HasLoadedAssembly("Newtonsoft.Json.dll"));
52+
53+
button.Click();
54+
55+
// We shouldn't get any errors about assemblies not being available
56+
AssertLogDoesNotContainCriticalMessages("Could not load file or assembly 'Newtonsoft.Json");
57+
}
58+
59+
[Fact]
60+
public void CanLazyLoadOnFirstVisit()
61+
{
62+
// Navigate to a page with lazy loaded assemblies for the first time
63+
SetUrlViaPushState("/WithDynamicAssembly");
64+
var app = Browser.MountTestComponent<TestRouter>();
65+
var button = app.FindElement(By.Id("use-package-button"));
66+
67+
// We should have requested the DLL
68+
Assert.True(HasLoadedAssembly("Newtonsoft.Json.dll"));
69+
70+
button.Click();
71+
72+
// We shouldn't get any errors about assemblies not being available
73+
AssertLogDoesNotContainCriticalMessages("Could not load file or assembly 'Newtonsoft.Json");
74+
}
75+
76+
private string SetUrlViaPushState(string relativeUri)
77+
{
78+
var pathBaseWithoutHash = ServerPathBase.Split('#')[0];
79+
var jsExecutor = (IJavaScriptExecutor)Browser;
80+
var absoluteUri = new Uri(_serverFixture.RootUri, $"{pathBaseWithoutHash}{relativeUri}");
81+
jsExecutor.ExecuteScript($"Blazor.navigateTo('{absoluteUri.ToString().Replace("'", "\\'")}')");
82+
83+
return absoluteUri.AbsoluteUri;
84+
}
85+
86+
private bool HasLoadedAssembly(string name)
87+
{
88+
var checkScript = $"return window.performance.getEntriesByType('resource').some(r => r.name.endsWith('{name}'));";
89+
var jsExecutor = (IJavaScriptExecutor)Browser;
90+
var nameRequested = jsExecutor.ExecuteScript(checkScript);
91+
if (nameRequested != null)
92+
{
93+
return (bool)nameRequested;
94+
}
95+
return false;
96+
}
97+
98+
private void AssertLogDoesNotContainCriticalMessages(params string[] messages)
99+
{
100+
var log = Browser.Manage().Logs.GetLog(LogType.Browser);
101+
foreach (var message in messages)
102+
{
103+
Assert.DoesNotContain(log, entry =>
104+
{
105+
return entry.Level == LogLevel.Severe
106+
&& entry.Message.Contains(message);
107+
});
108+
}
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)