|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using Components.TestServer.RazorComponents; |
| 5 | +using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; |
| 6 | +using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; |
| 7 | +using Microsoft.AspNetCore.E2ETesting; |
| 8 | +using OpenQA.Selenium; |
| 9 | +using TestServer; |
| 10 | +using Xunit.Abstractions; |
| 11 | + |
| 12 | +namespace Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests; |
| 13 | + |
| 14 | +[CollectionDefinition(nameof(InteractivityTest), DisableParallelization = true)] |
| 15 | +public class EndpointsServerReconnectionTest : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>> |
| 16 | +{ |
| 17 | + public EndpointsServerReconnectionTest( |
| 18 | + BrowserFixture browserFixture, |
| 19 | + BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture, |
| 20 | + ITestOutputHelper output) |
| 21 | + : base(browserFixture, serverFixture, output) |
| 22 | + { |
| 23 | + } |
| 24 | + |
| 25 | + public override Task InitializeAsync() |
| 26 | + => InitializeAsync(BrowserFixture.StreamingContext); |
| 27 | + |
| 28 | + [Fact] |
| 29 | + public void ReconnectUI_Displays_OnFirstReconnect() |
| 30 | + { |
| 31 | + Navigate($"{ServerPathBase}/streaming-interactivity"); |
| 32 | + |
| 33 | + Browser.Equal("Not streaming", () => Browser.FindElement(By.Id("status")).Text); |
| 34 | + |
| 35 | + Browser.Click(By.Id("add-server-counter-prerendered-link")); |
| 36 | + Browser.Equal("True", () => Browser.FindElement(By.Id("is-interactive-0")).Text); |
| 37 | + |
| 38 | + var javascript = (IJavaScriptExecutor)Browser; |
| 39 | + |
| 40 | + javascript.ExecuteScript("Blazor._internal.forceCloseConnection()"); |
| 41 | + Browser.Equal("block", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); |
| 42 | + Browser.Equal("none", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); |
| 43 | + Browser.Exists(By.Id("increment-0")).Click(); |
| 44 | + Browser.Equal("1", () => Browser.Exists(By.Id("count-0")).Text); |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public void ReconnectUI_Displays_OnSuccessiveReconnects_AfterEnhancedNavigation() |
| 49 | + { |
| 50 | + Navigate($"{ServerPathBase}/streaming-interactivity"); |
| 51 | + |
| 52 | + Browser.Equal("Not streaming", () => Browser.FindElement(By.Id("status")).Text); |
| 53 | + |
| 54 | + Browser.Click(By.Id("add-server-counter-prerendered-link")); |
| 55 | + Browser.Equal("True", () => Browser.FindElement(By.Id("is-interactive-0")).Text); |
| 56 | + |
| 57 | + var javascript = (IJavaScriptExecutor)Browser; |
| 58 | + |
| 59 | + // Perform the first reconnect |
| 60 | + javascript.ExecuteScript("Blazor._internal.forceCloseConnection()"); |
| 61 | + Browser.Equal("block", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); |
| 62 | + Browser.Equal("none", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); |
| 63 | + Browser.Exists(By.Id("increment-0")).Click(); |
| 64 | + Browser.Equal("1", () => Browser.Exists(By.Id("count-0")).Text); |
| 65 | + |
| 66 | + // Perform an enhanced navigation by updating the component's parameters |
| 67 | + Browser.Exists(By.Id("update-counter-link-0")).Click(); |
| 68 | + Browser.Equal("2", () => Browser.FindElement(By.Id("increment-amount-0")).Text); |
| 69 | + |
| 70 | + // Perform the second reconnect |
| 71 | + javascript.ExecuteScript("Blazor._internal.forceCloseConnection()"); |
| 72 | + Browser.Equal("block", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); |
| 73 | + Browser.Equal("none", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); |
| 74 | + Browser.Exists(By.Id("increment-0")).Click(); |
| 75 | + Browser.Equal("3", () => Browser.Exists(By.Id("count-0")).Text); |
| 76 | + } |
| 77 | +} |
0 commit comments