Skip to content

Commit c6554c6

Browse files
adamintAdam Ratzman
andauthored
Always update resource list in console logs after hidden bool changes (#10705)
Co-authored-by: Adam Ratzman <[email protected]>
1 parent 2e95c6f commit c6554c6

File tree

2 files changed

+109
-4
lines changed

2 files changed

+109
-4
lines changed

src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,15 @@ private void UpdateMenuButtons()
346346
value =>
347347
{
348348
_showHiddenResources = value;
349+
UpdateResourcesList();
350+
UpdateMenuButtons();
349351

350352
if (!_showHiddenResources && PageViewModel.SelectedResource?.IsResourceHidden(showHiddenResources: false) is true)
351353
{
352354
PageViewModel.SelectedResource = null;
353355
PageViewModel.SelectedOption = _noSelection;
354356
await this.AfterViewModelChangedAsync(_contentLayout, false);
355-
return;
356357
}
357-
358-
UpdateResourcesList();
359-
UpdateMenuButtons();
360358
}));
361359

362360
_logsMenuItems.Add(new()

tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,113 @@ public async Task ResourceName_SubscribeOnLoadAndChange_SubscribeConsoleLogsOnce
173173
Assert.False(await subscribedResourceNamesChannel.Reader.WaitToReadAsync().DefaultTimeout());
174174
}
175175

176+
[Fact]
177+
public void ToggleHiddenResources_HiddenResourceVisibilityAndSelection_WorksCorrectly()
178+
{
179+
// Arrange
180+
var regularResource = ModelTestHelpers.CreateResource(appName: "regular-resource", state: KnownResourceState.Running);
181+
var hiddenResource = ModelTestHelpers.CreateResource(appName: "hidden-resource", state: KnownResourceState.Running, hidden: true);
182+
183+
var consoleLogsChannel = Channel.CreateUnbounded<IReadOnlyList<ResourceLogLine>>();
184+
var resourceChannel = Channel.CreateUnbounded<IReadOnlyList<ResourceViewModelChange>>();
185+
var dashboardClient = new TestDashboardClient(
186+
isEnabled: true,
187+
consoleLogsChannelProvider: name => consoleLogsChannel,
188+
resourceChannelProvider: () => resourceChannel,
189+
initialResources: [regularResource, hiddenResource]);
190+
191+
SetupConsoleLogsServices(dashboardClient);
192+
193+
var dimensionManager = Services.GetRequiredService<DimensionManager>();
194+
var viewport = new ViewportInformation(IsDesktop: true, IsUltraLowHeight: false, IsUltraLowWidth: false);
195+
dimensionManager.InvokeOnViewportInformationChanged(viewport);
196+
197+
// Act & Assert 1: Render component - initially hidden resource should not be visible
198+
var cut = RenderComponent<Components.Pages.ConsoleLogs>(builder =>
199+
{
200+
builder.Add(p => p.ViewportInformation, viewport);
201+
});
202+
203+
var instance = cut.Instance;
204+
205+
// Wait for resources to load - use resource select component as proxy
206+
cut.WaitForAssertion(() =>
207+
{
208+
var resourceSelect = cut.FindComponent<ResourceSelect>();
209+
var selectElement = resourceSelect.Find("fluent-select");
210+
var selectOptions = selectElement.QuerySelectorAll("fluent-option");
211+
212+
// Should have at least 2 options (None + regular resource) when resources are loaded
213+
Assert.True(selectOptions.Length >= 2);
214+
});
215+
216+
// Initially, hidden resources should not be shown
217+
var resourceSelect = cut.FindComponent<ResourceSelect>();
218+
var selectElement = resourceSelect.Find("fluent-select");
219+
var selectOptions = selectElement.QuerySelectorAll("fluent-option");
220+
221+
// Should only have "None" option + regular resource (hidden resource filtered out)
222+
Assert.Equal(2, selectOptions.Length); // "None" + regular-resource
223+
var optionValues = selectOptions.Select(opt => opt.GetAttribute("value")).ToList();
224+
Assert.Contains("regular-resource", optionValues);
225+
Assert.DoesNotContain("hidden-resource", optionValues);
226+
227+
// Act & Assert 2: Click the settings menu button to show the menu, then click "Show hidden resources"
228+
var settingsMenuButton = cut.Find("fluent-button[title='" + Resources.ConsoleLogs.ConsoleLogsSettings + "']");
229+
Assert.NotNull(settingsMenuButton);
230+
settingsMenuButton.Click();
231+
232+
// Find and click the "Show hidden resources" menu item
233+
cut.WaitForAssertion(() =>
234+
{
235+
var showHiddenMenuItem = cut.Find("fluent-menu-item:contains('" + Resources.ControlsStrings.ShowHiddenResources + "')");
236+
Assert.NotNull(showHiddenMenuItem);
237+
showHiddenMenuItem.Click();
238+
});
239+
240+
// Wait for UI to update
241+
cut.WaitForAssertion(() =>
242+
{
243+
var updatedOptions = selectElement.QuerySelectorAll("fluent-option");
244+
// Should now have "None" + both resources
245+
Assert.Equal(3, updatedOptions.Length); // "None" + regular-resource + hidden-resource
246+
var updatedOptionValues = updatedOptions.Select(opt => opt.GetAttribute("value")).ToList();
247+
Assert.Contains("regular-resource", updatedOptionValues);
248+
Assert.Contains("hidden-resource", updatedOptionValues);
249+
});
250+
251+
// Act & Assert 3: Select the hidden resource
252+
var hiddenResourceOption = selectElement.QuerySelector("fluent-option[value='hidden-resource']");
253+
Assert.NotNull(hiddenResourceOption);
254+
selectElement.Change("hidden-resource");
255+
256+
cut.WaitForState(() => instance.PageViewModel.SelectedResource?.Name == "hidden-resource");
257+
258+
// Act & Assert 4: Click the settings menu button again and click "Hide hidden resources" to hide them again
259+
settingsMenuButton.Click();
260+
261+
cut.WaitForAssertion(() =>
262+
{
263+
var hideHiddenMenuItem = cut.Find("fluent-menu-item:contains('" + Resources.ControlsStrings.HideHiddenResources + "')");
264+
Assert.NotNull(hideHiddenMenuItem);
265+
hideHiddenMenuItem.Click();
266+
});
267+
268+
// Wait for UI to update - hidden resource should be filtered out and selection should be cleared
269+
cut.WaitForAssertion(() =>
270+
{
271+
var finalOptions = selectElement.QuerySelectorAll("fluent-option");
272+
// Should be back to "None" + regular resource only
273+
Assert.Equal(2, finalOptions.Length); // "None" + regular-resource
274+
var finalOptionValues = finalOptions.Select(opt => opt.GetAttribute("value")).ToList();
275+
Assert.Contains("regular-resource", finalOptionValues);
276+
Assert.DoesNotContain("hidden-resource", finalOptionValues);
277+
});
278+
279+
// Selection should be cleared since selected resource is now hidden
280+
cut.WaitForState(() => instance.PageViewModel.SelectedResource is null);
281+
}
282+
176283
[Fact]
177284
public async Task ResourceName_ViaUrlAndResourceLoaded_LogViewerUpdated()
178285
{

0 commit comments

Comments
 (0)