forked from dotnet/aspire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into tests-out-of-repo
- Loading branch information
Showing
18 changed files
with
310 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/Aspire.Dashboard.Tests/Integration/Playwright/AppBarTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Aspire.Dashboard.Resources; | ||
using Aspire.Workload.Tests; | ||
using Microsoft.Playwright; | ||
using Xunit; | ||
|
||
namespace Aspire.Dashboard.Tests.Integration.Playwright; | ||
|
||
[ActiveIssue("https://github.com/dotnet/aspire/issues/4623", typeof(PlaywrightProvider), nameof(PlaywrightProvider.DoesNotHavePlaywrightSupport))] | ||
public class AppBarTests : PlaywrightTestsBase | ||
{ | ||
public AppBarTests(DashboardServerFixture dashboardServerFixture, PlaywrightFixture playwrightFixture) | ||
: base(dashboardServerFixture, playwrightFixture) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task AppBar_Change_Theme() | ||
{ | ||
// Arrange | ||
await RunTestAsync(async page => | ||
{ | ||
await PlaywrightFixture.GoToHomeAndWaitForDataGridLoad(page); | ||
|
||
var settingsButton = page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = Layout.MainLayoutLaunchSettings }); | ||
|
||
await settingsButton.ClickAsync(); | ||
|
||
// Act and Assert | ||
|
||
// set to dark | ||
var darkThemeCheckbox = page.GetByRole(AriaRole.Radio).And(page.GetByText(Dialogs.SettingsDialogDarkTheme)).First; | ||
var lightThemeCheckbox = page.GetByRole(AriaRole.Radio).And(page.GetByText(Dialogs.SettingsDialogLightTheme)).First; | ||
|
||
await SetAndVerifyTheme(darkThemeCheckbox, "dark"); | ||
await SetAndVerifyTheme(lightThemeCheckbox, "light"); | ||
|
||
return; | ||
|
||
async Task SetAndVerifyTheme(ILocator locator, string expected) | ||
{ | ||
await locator.ClickAsync(); | ||
await Assertions | ||
.Expect(page.Locator("html")) | ||
.ToHaveAttributeAsync("data-theme", expected); | ||
} | ||
}); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
tests/Aspire.Dashboard.Tests/Integration/Playwright/DashboardServerFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Reflection; | ||
using Aspire.Dashboard.Configuration; | ||
using Aspire.Dashboard.Model; | ||
using Aspire.Hosting; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Xunit; | ||
|
||
namespace Aspire.Dashboard.Tests.Integration.Playwright; | ||
|
||
public class DashboardServerFixture : IAsyncLifetime | ||
{ | ||
public DashboardWebApplication DashboardApp { get; private set; } = null!; | ||
|
||
public Task InitializeAsync() | ||
{ | ||
const string aspireDashboardAssemblyName = "Aspire.Dashboard"; | ||
var currentAssemblyName = Assembly.GetExecutingAssembly().GetName().Name!; | ||
var currentAssemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; | ||
var aspireAssemblyDirectory = currentAssemblyDirectory.Replace(currentAssemblyName, aspireDashboardAssemblyName); | ||
|
||
var initialData = new Dictionary<string, string?> | ||
{ | ||
[DashboardConfigNames.DashboardFrontendUrlName.ConfigKey] = "http://127.0.0.1:0", | ||
[DashboardConfigNames.DashboardOtlpHttpUrlName.ConfigKey] = "http://127.0.0.1:0", | ||
[DashboardConfigNames.DashboardOtlpAuthModeName.ConfigKey] = nameof(OtlpAuthMode.Unsecured), | ||
[DashboardConfigNames.DashboardFrontendAuthModeName.ConfigKey] = nameof(FrontendAuthMode.Unsecured) | ||
}; | ||
|
||
var config = new ConfigurationManager().AddInMemoryCollection(initialData).Build(); | ||
|
||
// Add services to the container. | ||
DashboardApp = new DashboardWebApplication( | ||
options: new WebApplicationOptions | ||
{ | ||
EnvironmentName = "Development", | ||
ContentRootPath = aspireAssemblyDirectory, | ||
WebRootPath = Path.Combine(aspireAssemblyDirectory, "wwwroot"), | ||
ApplicationName = aspireDashboardAssemblyName, | ||
}, | ||
preConfigureBuilder: builder => | ||
{ | ||
builder.Configuration.AddConfiguration(config); | ||
}, | ||
postConfigureBuilder: builder => | ||
{ | ||
builder.Services.RemoveAll<IDashboardClient>(); | ||
builder.Services.AddSingleton<IDashboardClient, MockDashboardClient>(); | ||
}); | ||
|
||
return DashboardApp.StartAsync(); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return DashboardApp.DisposeAsync().AsTask(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
tests/Aspire.Dashboard.Tests/Integration/Playwright/MockDashboardClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Frozen; | ||
using System.Collections.Immutable; | ||
using Aspire.Dashboard.Model; | ||
using Google.Protobuf.WellKnownTypes; | ||
|
||
namespace Aspire.Dashboard.Tests.Integration.Playwright; | ||
|
||
public sealed class MockDashboardClient : IDashboardClient | ||
{ | ||
public static readonly ResourceViewModel TestResource1 = new() | ||
{ | ||
Name = "TestResource", | ||
DisplayName = "TestResource", | ||
Commands = ImmutableArray<CommandViewModel>.Empty, | ||
CreationTimeStamp = DateTime.Now, | ||
Environment = ImmutableArray<EnvironmentVariableViewModel>.Empty, | ||
ResourceType = KnownResourceTypes.Project, | ||
Properties = new [] | ||
{ | ||
new KeyValuePair<string, Value>(KnownProperties.Project.Path, new Value() | ||
{ | ||
StringValue = "C:/MyProjectPath/Project.csproj" | ||
}) | ||
}.ToFrozenDictionary(), | ||
State = "Running", | ||
Uid = Guid.NewGuid().ToString(), | ||
StateStyle = null, | ||
Urls = ImmutableArray<UrlViewModel>.Empty, | ||
|
||
}; | ||
|
||
public bool IsEnabled => true; | ||
public Task WhenConnected => Task.CompletedTask; | ||
public string ApplicationName => "IntegrationTestApplication"; | ||
public ValueTask DisposeAsync() => ValueTask.CompletedTask; | ||
public Task<ResourceCommandResponseViewModel> ExecuteResourceCommandAsync(string resourceName, string resourceType, CommandViewModel command, CancellationToken cancellationToken) => throw new NotImplementedException(); | ||
public IAsyncEnumerable<IReadOnlyList<ResourceLogLine>>? SubscribeConsoleLogs(string resourceName, CancellationToken cancellationToken) => throw new NotImplementedException(); | ||
|
||
public Task<ResourceViewModelSubscription> SubscribeResourcesAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult(new ResourceViewModelSubscription( | ||
[TestResource1], | ||
Test() | ||
)); | ||
} | ||
|
||
private static async IAsyncEnumerable<IReadOnlyList<ResourceViewModelChange>> Test() | ||
{ | ||
await Task.CompletedTask; | ||
yield return new List<ResourceViewModelChange> { }; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Aspire.Dashboard.Tests/Integration/Playwright/PlaywrightFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Aspire.Workload.Tests; | ||
using Microsoft.Playwright; | ||
using Xunit; | ||
|
||
namespace Aspire.Dashboard.Tests.Integration.Playwright; | ||
|
||
public class PlaywrightFixture : IAsyncLifetime | ||
{ | ||
public IBrowser Browser { get; set; } = null!; | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
PlaywrightProvider.DetectAndSetInstalledPlaywrightDependenciesPath(); | ||
Browser = await PlaywrightProvider.CreateBrowserAsync(); | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await Browser.CloseAsync(); | ||
} | ||
|
||
public async Task GoToHomeAndWaitForDataGridLoad(IPage page) | ||
{ | ||
await page.GotoAsync("/"); | ||
await Assertions | ||
.Expect(page.GetByText(MockDashboardClient.TestResource1.DisplayName)) | ||
.ToBeVisibleAsync(); | ||
} | ||
} |
Oops, something went wrong.