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
9 changes: 6 additions & 3 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,12 @@ async Task SubscribeResourcesAsync()
{
UpdateFromResource(
resource,
t => AreAllTypesVisible,
s => AreAllStatesVisible,
s => AreAllHealthStatesVisible);
// The new type/state/health status should be visible if it's either
// 1) new, or
// 2) previously visible
t => !PageViewModel.ResourceTypesToVisibility.TryGetValue(t, out var value) || value,
s => !PageViewModel.ResourceStatesToVisibility.TryGetValue(s, out var value) || value,
s => !PageViewModel.ResourceHealthStatusesToVisibility.TryGetValue(s, out var value) || value);

if (string.Equals(SelectedResource?.Name, resource.Name, StringComparisons.ResourceName))
{
Expand Down
47 changes: 47 additions & 0 deletions tests/Aspire.Dashboard.Components.Tests/Pages/ResourcesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,53 @@ private static void AssertResourceFilterListEquals(IRenderedComponent<Components
Assert.Equal(healthStates, healthSelect.Instance.Values.ToImmutableSortedDictionary() /* sort for equality comparison */);
}

[Fact]
public void ResourcesShouldRemainUnchangedWhenFilterDoesNotMatchUpdatedResource()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this test all 3 lines of your fix above?

{
// Arrange
var viewport = new ViewportInformation(IsDesktop: true, IsUltraLowHeight: false, IsUltraLowWidth: false);
var initialResources = new List<ResourceViewModel>
{
CreateResource("Resource1", "Type1", "Running", null),
CreateResource("Resource2", "Type2", "Stopping", null),
};
var channel = Channel.CreateUnbounded<IReadOnlyList<ResourceViewModelChange>>();
var dashboardClient = new TestDashboardClient(isEnabled: true, initialResources: initialResources, resourceChannelProvider: () => channel);

ResourceSetupHelpers.SetupResourcesPage(this, viewport, dashboardClient);

var cut = RenderComponent<Components.Pages.Resources>(builder =>
{
builder.AddCascadingValue(viewport);
});

// Open the resource filter and apply a filter
cut.Find("#resourceFilterButton").Click();
cut.FindComponents<SelectResourceOptions<string>>()
.First(f => f.Instance.Id == "resource-types")
.FindComponents<FluentCheckbox>()
.First(checkbox => checkbox.Instance.Label == "Type1")
.Find("fluent-checkbox")
.TriggerEvent("oncheckedchange", new CheckboxChangeEventArgs { Checked = false });

cut.WaitForState(() => cut.Instance.GetFilteredResources().Count() == 1);

// Act
channel.Writer.TryWrite(new[]
{
new ResourceViewModelChange(
ResourceViewModelChangeType.Upsert,
CreateResource("Resource3", "Type3", "Running", null))
});

cut.WaitForState(() => cut.Instance.GetFilteredResources().Count() == 2);

// Assert
var filteredResources = cut.Instance.GetFilteredResources().ToList();
Assert.Contains(filteredResources, r => r.Name == "Resource2");
Assert.Contains(filteredResources, r => r.Name == "Resource3");
}

private static ResourceViewModel CreateResource(string name, string type, string? state, ImmutableArray<HealthReportViewModel>? healthReports)
{
return new ResourceViewModel
Expand Down