fix: open the user menu on click of the initials (MudBlazor 9 custom activator)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4a5703adce
commit
164e988906
3 files changed
+55
-2
No files matched your search
@@ -5,8 +5,8 @@
|
||||
<AuthorizeView>
|
||||
<Authorized Context="auth">
|
||||
<MudMenu AnchorOrigin="Origin.BottomRight" TransformOrigin="Origin.TopRight" aria-label="Benutzermenü">
|
||||
<ActivatorContent>
|
||||
<div class="fp-user-avatar" style="cursor:pointer">
|
||||
<ActivatorContent Context="menu"> @* MudBlazor 9: ein eigener Aktivator muss MenuContext.ToggleAsync aufrufen, sonst öffnet sich nichts (Tastatur übernimmt MudMenu) *@
|
||||
<div class="fp-user-avatar" style="cursor:pointer" @onclick="e => menu.ToggleAsync(e)">
|
||||
<UserAvatarView Name="@DisplayNameOf(auth.User)" Color="@ColorOf(auth.User)" AvatarUrl="@AuthState.CurrentUser?.AvatarUrl" />
|
||||
</div>
|
||||
</ActivatorContent>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
@* Testhülle: MudBlazor-Popover-Provider + Benutzermenü, damit das geöffnete Menü gerendert wird. *@
|
||||
<MudPopoverProvider />
|
||||
<FamilyPlanner.Web.Client.Layout.UserMenu />
|
||||
@@ -0,0 +1,50 @@
|
||||
using FamilyPlanner.Domain;
|
||||
using FamilyPlanner.Shared.Auth;
|
||||
using FamilyPlanner.Web.Client.Auth;
|
||||
using FamilyPlanner.Web.Client.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MudBlazor.Services;
|
||||
|
||||
namespace FamilyPlanner.Web.Tests.Account;
|
||||
|
||||
/// <summary>Klick auf die eigenen Initialen öffnet das Benutzermenü (MudBlazor 9: eigener Aktivator muss <c>ToggleAsync</c> aufrufen).</summary>
|
||||
public sealed class UserMenuTests : BunitContext
|
||||
{
|
||||
public UserMenuTests()
|
||||
{
|
||||
JSInterop.Mode = JSRuntimeMode.Loose;
|
||||
Services.AddMudServices();
|
||||
var auth = AddAuthorization();
|
||||
auth.SetAuthorized("Mia");
|
||||
auth.SetRoles(Roles.Family);
|
||||
Services.AddSingleton<IAuthService, NoopAuthService>();
|
||||
Services.AddSingleton<ApiAuthenticationStateProvider>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Clicking_the_initials_opens_the_menu_with_settings_password_and_logout()
|
||||
{
|
||||
var cut = Render<UserMenuHost>();
|
||||
|
||||
cut.Find(".fp-user-avatar").Click();
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var items = cut.FindAll(".mud-menu-item").Select(i => i.TextContent.Trim()).ToList();
|
||||
Assert.Contains("Meine Einstellungen", items);
|
||||
Assert.Contains("Passwort ändern", items);
|
||||
Assert.Contains("Abmelden", items);
|
||||
});
|
||||
}
|
||||
|
||||
private sealed class NoopAuthService : IAuthService
|
||||
{
|
||||
public Task<CurrentUserDto?> GetCurrentUserAsync(CancellationToken cancellationToken = default) => Task.FromResult<CurrentUserDto?>(null);
|
||||
|
||||
public Task<AuthResult> LoginAsync(LoginRequest request, CancellationToken cancellationToken = default) => throw new NotSupportedException();
|
||||
|
||||
public Task LogoutAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
|
||||
public Task<AuthResult> ChangePasswordAsync(ChangePasswordRequest request, CancellationToken cancellationToken = default) => throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user