-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
Copy pathNoInteractivityTest.cs
81 lines (67 loc) · 3.74 KB
/
NoInteractivityTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Net.Http;
using Components.TestServer.RazorComponents;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using OpenQA.Selenium;
using TestServer;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests;
[CollectionDefinition(nameof(InteractivityTest), DisableParallelization = true)]
public class NoInteractivityTest : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsNoInteractivityStartup<App>>>
{
public NoInteractivityTest(
BrowserFixture browserFixture,
BasicTestAppServerSiteFixture<RazorComponentEndpointsNoInteractivityStartup<App>> serverFixture,
ITestOutputHelper output)
: base(browserFixture, serverFixture, output)
{
}
public override Task InitializeAsync()
=> InitializeAsync(BrowserFixture.StreamingContext);
[Fact]
public void NavigationManagerCanRefreshSSRPageWhenInteractivityNotPresent()
{
Navigate($"{ServerPathBase}/forms/form-that-calls-navigation-manager-refresh");
var guid = Browser.Exists(By.Id("guid")).Text;
Browser.Exists(By.Id("submit-button")).Click();
// Checking that the page was refreshed.
// The redirect request method is GET.
// Providing a Guid to check that it is not the initial GET request for the page
Browser.NotEqual(guid, () => Browser.Exists(By.Id("guid")).Text);
Browser.Equal("GET", () => Browser.Exists(By.Id("method")).Text);
}
[Fact]
public void CanUseServerAuthenticationStateByDefault()
{
Navigate($"{ServerPathBase}/auth/static-authentication-state");
Browser.Equal("False", () => Browser.FindElement(By.Id("is-interactive")).Text);
Browser.Equal("Static", () => Browser.FindElement(By.Id("platform")).Text);
Browser.Equal("False", () => Browser.FindElement(By.Id("identity-authenticated")).Text);
Browser.Equal("", () => Browser.FindElement(By.Id("identity-name")).Text);
Browser.Equal("(none)", () => Browser.FindElement(By.Id("test-claim")).Text);
Browser.Equal("False", () => Browser.FindElement(By.Id("is-in-test-role-1")).Text);
Browser.Equal("False", () => Browser.FindElement(By.Id("is-in-test-role-2")).Text);
Browser.Click(By.LinkText("Log in"));
Browser.Equal("True", () => Browser.FindElement(By.Id("identity-authenticated")).Text);
Browser.Equal("YourUsername", () => Browser.FindElement(By.Id("identity-name")).Text);
Browser.Equal("Test claim value", () => Browser.FindElement(By.Id("test-claim")).Text);
Browser.Equal("True", () => Browser.FindElement(By.Id("is-in-test-role-1")).Text);
Browser.Equal("True", () => Browser.FindElement(By.Id("is-in-test-role-2")).Text);
}
[Theory]
[InlineData(true, true)]
[InlineData(true, false)]
[InlineData(false, true)]
public void NavigatesWithoutInteractivityByRequestRedirection(bool controlFlowByException, bool isStreaming)
{
AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException", isEnabled: controlFlowByException);
string streaming = isStreaming ? $"streaming-" : "";
Navigate($"{ServerPathBase}/routing/ssr-{streaming}navigate-to");
Browser.Equal("Click submit to navigate to home", () => Browser.Exists(By.Id("test-info")).Text);
Browser.Click(By.Id("redirectButton"));
Browser.Equal("Routing test cases", () => Browser.Exists(By.Id("test-info")).Text);
}
}