Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<FluentButton Appearance="Appearance.Lightweight"
Title="@(!string.IsNullOrEmpty(command.DisplayDescription) ? command.DisplayDescription : command.DisplayName)"
Disabled="@(command.State == CommandViewModelState.Disabled)"
OnClick="@(() => ExecuteResourceCommandAsync(command))">
OnClick="@(() => ExecuteResourceCommandAsync(command))"
Class="highlighted-command">
@if (!string.IsNullOrEmpty(command.IconName) && CommandViewModel.ResolveIconName(command.IconName, command.IconVariant) is { } icon)
{
<FluentIcon Value="@icon" Width="16px" />
Expand Down
9 changes: 8 additions & 1 deletion src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ async Task TrackResourceSnapshotsAsync()
}
}

await InvokeAsync(StateHasChanged);
await InvokeAsync(() =>
{
// The selected resource may have changed, so update resource action buttons.
// Update inside in the render's sync context so the buttons don't change while the UI is rendering.
UpdateMenuButtons();

StateHasChanged();
});
}
});
}
Expand Down
64 changes: 64 additions & 0 deletions tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,70 @@ public async Task ConsoleLogsManager_ClearLogs_LogsFilteredOutAsync()
cut.WaitForState(() => instance._logEntries.EntriesCount > 0);
}

[Fact]
public void MenuButtons_SelectedResourceChanged_ButtonsUpdated()
{
// Arrange
var testResource = ModelTestHelpers.CreateResource(
appName: "test-resource",
state: KnownResourceState.Running,
commands: [new CommandViewModel("test-name", CommandViewModelState.Enabled, "test-displayname", "test-displaydescription", confirmationMessage: "", parameter: null, isHighlighted: true, iconName: string.Empty, iconVariant: IconVariant.Regular)]);
var subscribedResourceNameTcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
var consoleLogsChannel = Channel.CreateUnbounded<IReadOnlyList<ResourceLogLine>>();
var resourceChannel = Channel.CreateUnbounded<IReadOnlyList<ResourceViewModelChange>>();
var dashboardClient = new TestDashboardClient(
isEnabled: true,
consoleLogsChannelProvider: name =>
{
subscribedResourceNameTcs.TrySetResult(name);
return consoleLogsChannel;
},
resourceChannelProvider: () => resourceChannel,
initialResources: [testResource]);

SetupConsoleLogsServices(dashboardClient);

var dimensionManager = Services.GetRequiredService<DimensionManager>();
var viewport = new ViewportInformation(IsDesktop: true, IsUltraLowHeight: false, IsUltraLowWidth: false);
dimensionManager.InvokeOnViewportInformationChanged(viewport);

// Act 1
var cut = RenderComponent<Components.Pages.ConsoleLogs>(builder =>
{
builder.Add(p => p.ResourceName, "test-resource");
builder.Add(p => p.ViewportInformation, viewport);
});

var instance = cut.Instance;
var logger = Services.GetRequiredService<ILogger<ConsoleLogsTests>>();
var loc = Services.GetRequiredService<IStringLocalizer<Resources.ConsoleLogs>>();

// Assert 1
cut.WaitForState(() => instance.PageViewModel.SelectedResource == testResource);

cut.WaitForAssertion(() =>
{
var highlightedCommands = cut.FindAll(".highlighted-command");
Assert.Single(highlightedCommands);
});

// Act 2
testResource = ModelTestHelpers.CreateResource(
appName: "test-resource",
state: KnownResourceState.Running,
commands: []);
resourceChannel.Writer.TryWrite([
new ResourceViewModelChange(ResourceViewModelChangeType.Upsert, testResource)
]);

// Assert 2
cut.WaitForAssertion(() =>
{
var highlightedCommands = cut.FindAll(".highlighted-command");
Assert.Empty(highlightedCommands);
});
}

private void SetupConsoleLogsServices(TestDashboardClient? dashboardClient = null, TestTimeProvider? timeProvider = null)
{
var version = typeof(FluentMain).Assembly.GetName().Version!;
Expand Down
5 changes: 3 additions & 2 deletions tests/Shared/DashboardModel/ModelTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public static ResourceViewModel CreateResource(
string? resourceType = null,
string? stateStyle = null,
HealthStatus? reportHealthStatus = null,
bool createNullHealthReport = false)
bool createNullHealthReport = false,
ImmutableArray<CommandViewModel>? commands = null)
{
return new ResourceViewModel
{
Expand All @@ -38,7 +39,7 @@ public static ResourceViewModel CreateResource(
KnownState = state,
StateStyle = stateStyle,
HealthReports = reportHealthStatus is null && !createNullHealthReport ? [] : [new HealthReportViewModel("healthcheck", reportHealthStatus, null, null)],
Commands = [],
Commands = commands ?? [],
Relationships = [],
};
}
Expand Down