-
Notifications
You must be signed in to change notification settings - Fork 155
Refactor dashboard automation tests and improve configuration handling #4238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,5 +1,7 @@ | ||||
namespace Aspire.Dashboard.ScreenCapture; | ||||
| ||||
namespace Aspire.Dashboard.ScreenCapture; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The empty line at the beginning of the file should be removed to maintain consistent file formatting.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||
|
||||
[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")] | ||||
public class FluentDataGridSelector(string initialSelector) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The DebuggerDisplay attribute is missing the required using statement for System.Diagnostics. This will cause a compilation error. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||
{ | ||||
private readonly StringBuilder _selector = new(initialSelector); | ||||
|
@@ -46,4 +48,6 @@ public FluentDataGridSelector Descendant(string selector) | |||
|
||||
public static implicit operator string(FluentDataGridSelector fluentDataGridSelector) => | ||||
fluentDataGridSelector.ToString(); | ||||
|
||||
private string GetDebuggerDisplay() => ToString(); | ||||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,30 +1,54 @@ | ||||
namespace Aspire.Dashboard.ScreenCapture; | ||||
using Aspire.Hosting.ApplicationModel; | ||||
using Microsoft.AspNetCore.Hosting.Server; | ||||
using Microsoft.AspNetCore.Hosting.Server.Features; | ||||
using Microsoft.Extensions.DependencyInjection; | ||||
|
||||
namespace Aspire.Dashboard.ScreenCapture; | ||||
|
||||
public class PlaywrightTestsBase<TDashboardServerFixture>(AppHostTestFixture appHostTestFixture) | ||||
: IClassFixture<TDashboardServerFixture>, IAsyncDisposable | ||||
where TDashboardServerFixture : AppHostTestFixture | ||||
{ | ||||
public AppHostTestFixture AppHostTestFixture { get; } = appHostTestFixture; | ||||
public PlaywrightFixture PlaywrightFixture { get; } = appHostTestFixture.PlaywrightFixture; | ||||
public string? DashboardUrl { get; private set; } | ||||
public string? DashboardUrl { get; internal set; } | ||||
public string DashboardLoginToken { get; private set; } = ""; | ||||
|
||||
private IBrowserContext? _context; | ||||
|
||||
public Task<DistributedApplication> ConfigureAsync<TEntryPoint>( | ||||
public async Task<DistributedApplication> ConfigureAsync<TEntryPoint>( | ||||
string[]? args = null, | ||||
Action<IDistributedApplicationTestingBuilder>? configureBuilder = null) where TEntryPoint : class => | ||||
AppHostTestFixture.ConfigureAsync<TEntryPoint>(args, builder => | ||||
Action<IDistributedApplicationTestingBuilder>? configureBuilder = null) where TEntryPoint : class | ||||
{ | ||||
var app = await AppHostTestFixture.ConfigureAsync<TEntryPoint>(args, builder => | ||||
{ | ||||
var aspNetCoreUrls = builder.Configuration["ASPNETCORE_URLS"]; | ||||
var urls = aspNetCoreUrls is not null ? aspNetCoreUrls.Split(";") : []; | ||||
|
||||
DashboardUrl = urls.FirstOrDefault(); | ||||
DashboardLoginToken = builder.Configuration["AppHost:BrowserToken"] ?? ""; | ||||
|
||||
builder.Eventing.Subscribe<ResourceEndpointsAllocatedEvent>((@event, _) => | ||||
{ | ||||
if (@event.Resource.TryGetUrls(out var urls)) | ||||
{ | ||||
DashboardUrl = urls.FirstOrDefault()?.ToString() ?? ""; | ||||
} | ||||
|
||||
return Task.CompletedTask; | ||||
}); | ||||
|
||||
configureBuilder?.Invoke(builder); | ||||
}); | ||||
|
||||
var server = app.Services.GetRequiredService<IServer>(); | ||||
var addresses = server.Features.Get<IServerAddressesFeature>()?.Addresses; | ||||
if (addresses is not null) | ||||
{ | ||||
|
||||
} | ||||
var hostUrl = app.GetEndpoint("aspire-dashboard"); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code block from lines 40-45 appears to be unused dead code. The server variable and addresses are retrieved but never used, and the block is empty. This should be removed to improve code clarity.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||
DashboardUrl = hostUrl.ToString(); | ||||
|
||||
return app; | ||||
} | ||||
|
||||
public async Task InteractWithPageAsync(Func<IPage, Task> test, ViewportSize? size = null) | ||||
{ | ||||
var page = await CreateNewPageAsync(size); | ||||
|
@@ -33,6 +57,12 @@ public async Task InteractWithPageAsync(Func<IPage, Task> test, ViewportSize? si | |||
{ | ||||
await test(page); | ||||
} | ||||
catch (Exception ex) | ||||
{ | ||||
Console.Error.WriteLine($"Error during test interaction: {ex.Message}"); | ||||
|
||||
throw; | ||||
} | ||||
finally | ||||
{ | ||||
await page.CloseAsync(); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple lines of commented-out code (lines 197, 199-201) should be removed rather than left as comments. If this code might be needed later, consider using version control history instead.
Copilot uses AI. Check for mistakes.