-
Couldn't load subscription status.
- Fork 712
Persist dismissing the OTLP unsecured message bar #5465
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.FluentUI.AspNetCore.Components; | ||
|
|
||
| namespace Aspire.Dashboard.Utils; | ||
|
|
||
| internal static class BrowserStorageKeys | ||
| { | ||
| public const string UnsecuredTelemetryMessageDismissedKey = "Aspire_Telemetry_UnsecuredMessageDismissed"; | ||
|
|
||
| public const string TracesPageState = "Aspire_PageState_Traces"; | ||
| public const string StructuredLogsPageState = "Aspire_PageState_StructuredLogs"; | ||
| public const string MetricsPageState = "Aspire_PageState_Metrics"; | ||
| public const string ConsoleLogsPageState = "Aspire_PageState_ConsoleLogs"; | ||
|
|
||
| public static string SplitterOrientationKey(string viewKey) | ||
| { | ||
| return $"Aspire_SplitterOrientation_{viewKey}"; | ||
| } | ||
|
|
||
| public static string SplitterSizeKey(string viewKey, Orientation orientation) | ||
| { | ||
| return $"Aspire_SplitterSize_{orientation}_{viewKey}"; | ||
| } | ||
| } |
162 changes: 162 additions & 0 deletions
162
tests/Aspire.Dashboard.Components.Tests/Layout/MainLayoutTests.cs
This file contains hidden or 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,162 @@ | ||
| // 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.Components.Layout; | ||
| using Aspire.Dashboard.Components.Resize; | ||
| using Aspire.Dashboard.Components.Tests.Shared; | ||
| using Aspire.Dashboard.Configuration; | ||
| using Aspire.Dashboard.Model; | ||
| using Aspire.Dashboard.Model.BrowserStorage; | ||
| using Aspire.Dashboard.Utils; | ||
| using Bunit; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.FluentUI.AspNetCore.Components; | ||
| using Microsoft.FluentUI.AspNetCore.Components.Components.Tooltip; | ||
| using Xunit; | ||
|
|
||
| namespace Aspire.Dashboard.Components.Tests.Layout; | ||
|
|
||
| [UseCulture("en-US")] | ||
| public partial class MainLayoutTests : TestContext | ||
| { | ||
| [Fact] | ||
| public async Task OnInitialize_UnsecuredOtlp_NotDismissed_DisplayMessageBar() | ||
| { | ||
| // Arrange | ||
| var testLocalStorage = new TestLocalStorage(); | ||
| var messageService = new MessageService(); | ||
|
|
||
| SetupMainLayoutServices(localStorage: testLocalStorage, messageService: messageService); | ||
|
|
||
| Message? message = null; | ||
| var messageShownTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| messageService.OnMessageItemsUpdatedAsync += () => | ||
| { | ||
| message = messageService.AllMessages.Single(); | ||
| messageShownTcs.TrySetResult(); | ||
| return Task.CompletedTask; | ||
| }; | ||
|
|
||
| testLocalStorage.OnGetUnprotectedAsync = key => | ||
| { | ||
| if (key == BrowserStorageKeys.UnsecuredTelemetryMessageDismissedKey) | ||
| { | ||
| return (false, false); | ||
| } | ||
| else | ||
| { | ||
| throw new InvalidOperationException("Unexpected key."); | ||
| } | ||
| }; | ||
|
|
||
| var dismissedSettingSetTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| testLocalStorage.OnSetUnprotectedAsync = (key, value) => | ||
| { | ||
| if (key == BrowserStorageKeys.UnsecuredTelemetryMessageDismissedKey) | ||
| { | ||
| dismissedSettingSetTcs.TrySetResult((bool)value!); | ||
| } | ||
| else | ||
| { | ||
| throw new InvalidOperationException("Unexpected key."); | ||
| } | ||
| }; | ||
|
|
||
| // Act | ||
| var cut = RenderComponent<MainLayout>(builder => | ||
| { | ||
| builder.Add(p => p.ViewportInformation, new ViewportInformation(IsDesktop: true, IsUltraLowHeight: false, IsUltraLowWidth: false)); | ||
| }); | ||
|
|
||
| // Assert | ||
| await messageShownTcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| Assert.NotNull(message); | ||
|
|
||
| message.Close(); | ||
|
|
||
| Assert.True(await dismissedSettingSetTcs.Task.WaitAsync(TimeSpan.FromSeconds(5))); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task OnInitialize_UnsecuredOtlp_Dismissed_NoMessageBar() | ||
| { | ||
| // Arrange | ||
| var testLocalStorage = new TestLocalStorage(); | ||
| var messageService = new MessageService(); | ||
|
|
||
| SetupMainLayoutServices(localStorage: testLocalStorage, messageService: messageService); | ||
|
|
||
| var messageShownTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| messageService.OnMessageItemsUpdatedAsync += () => | ||
| { | ||
| messageShownTcs.TrySetResult(); | ||
| return Task.CompletedTask; | ||
| }; | ||
|
|
||
| testLocalStorage.OnGetUnprotectedAsync = key => | ||
| { | ||
| if (key == BrowserStorageKeys.UnsecuredTelemetryMessageDismissedKey) | ||
| { | ||
| return (true, true); | ||
| } | ||
| else | ||
| { | ||
| throw new InvalidOperationException("Unexpected key."); | ||
| } | ||
| }; | ||
|
|
||
| // Act | ||
| var cut = RenderComponent<MainLayout>(builder => | ||
| { | ||
| builder.Add(p => p.ViewportInformation, new ViewportInformation(IsDesktop: true, IsUltraLowHeight: false, IsUltraLowWidth: false)); | ||
| }); | ||
|
|
||
| // Assert | ||
| var timeoutTask = Task.Delay(100); | ||
| var completedTask = await Task.WhenAny(messageShownTcs.Task, timeoutTask).WaitAsync(TimeSpan.FromSeconds(5)); | ||
|
|
||
| // It's hard to test something not happening. | ||
| // In this case of checking for a message, apply a small display and then double check that no message was displayed. | ||
| Assert.True(completedTask != messageShownTcs.Task, "No message bar should be displayed."); | ||
| Assert.Empty(messageService.AllMessages); | ||
| } | ||
|
|
||
| private void SetupMainLayoutServices(TestLocalStorage? localStorage = null, MessageService? messageService = null) | ||
| { | ||
| Services.AddLocalization(); | ||
| Services.AddOptions(); | ||
| Services.AddSingleton<ThemeManager>(); | ||
| Services.AddSingleton<IDialogService, DialogService>(); | ||
| Services.AddSingleton<IDashboardClient, TestDashboardClient>(); | ||
| Services.AddSingleton<ILocalStorage>(localStorage ?? new TestLocalStorage()); | ||
| Services.AddSingleton<IEffectiveThemeResolver, TestEffectiveThemeResolver>(); | ||
| Services.AddSingleton<ShortcutManager>(); | ||
| Services.AddSingleton<BrowserTimeProvider, TestTimeProvider>(); | ||
| Services.AddSingleton<IMessageService>(messageService ?? new MessageService()); | ||
| Services.AddSingleton<LibraryConfiguration>(); | ||
| Services.AddSingleton<ITooltipService, TooltipService>(); | ||
| Services.AddSingleton<IToastService, ToastService>(); | ||
| Services.AddSingleton<GlobalState>(); | ||
| Services.Configure<DashboardOptions>(o => o.Otlp.AuthMode = OtlpAuthMode.Unsecured); | ||
|
|
||
| var version = typeof(FluentMain).Assembly.GetName().Version!; | ||
|
|
||
| var overflowModule = JSInterop.SetupModule(GetFluentFile("./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Overflow/FluentOverflow.razor.js", version)); | ||
| overflowModule.SetupVoid("fluentOverflowInitialize", _ => true); | ||
|
|
||
| var anchorModule = JSInterop.SetupModule(GetFluentFile("./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Anchor/FluentAnchor.razor.js", version)); | ||
|
|
||
| var themeModule = JSInterop.SetupModule("/js/app-theme.js"); | ||
|
|
||
| JSInterop.SetupModule("window.registerGlobalKeydownListener", _ => true); | ||
| JSInterop.SetupModule("window.registerOpenTextVisualizerOnClick", _ => true); | ||
|
|
||
| JSInterop.Setup<string>("window.getBrowserTimeZone").SetResult("abc"); | ||
| } | ||
|
|
||
| private static string GetFluentFile(string filePath, Version version) | ||
| { | ||
| return $"{filePath}?v={version}"; | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
tests/Aspire.Dashboard.Components.Tests/Shared/TestDashboardClient.cs
This file contains hidden or 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,33 @@ | ||
| // 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.Model; | ||
|
|
||
| namespace Aspire.Dashboard.Components.Tests.Shared; | ||
|
|
||
| public class TestDashboardClient : IDashboardClient | ||
| { | ||
| public bool IsEnabled { get; } | ||
| public Task WhenConnected { get; } = Task.CompletedTask; | ||
| public string ApplicationName { get; } = "TestApp"; | ||
|
|
||
| public ValueTask DisposeAsync() | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| 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) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Only include AuthorizeView on the page if the user profile should be displayed (which means the auth mode needs to be a certain value).
This avoids the need to include various authz services in tests.