BankMan101
BankMan101

Reputation: 281

Tesiting latest Version of MudBlazor with Bunit Gives Missing MudPopoverProvider Error

I have just upgraded to Mudblazor 7.2 from 7. I have a MainLayout.cs file which has the

<MudPopoverProvider>

specified

<CascadingValue Value="this">
    <MudPopoverProvider> </MudPopoverProvider>
    <MudThemeProvider @bind-IsDarkMode="@_isDarkMode" Theme="_theme"/>
    <MudDialogProvider/>
    <MudLayout>
        <MudAppBar Dense="true" Color="MudBlazor.Color.Info">
            <MudIconButton Icon="@Icons.Material.Filled.Menu" Edge="Edge.Start" OnClick="@ToggleDrawer"/>
            <MudSpacer/>
            <MudText Typo="Typo.h5" Color="MudBlazor.Color.Default" Style="color: white;">@HeaderService.PageTitle</MudText>
            <MudSpacer/>
        </MudAppBar>
        <MudDrawer @bind-Open="@_menuOpen" ClipMode="_clipMode" Elevation="1" Variant="@DrawerVariant.Responsive">
            <NavMenu/>
        </MudDrawer>
        <MudMainContent>
            <CustomErrorBoundary>
                @Body
            </CustomErrorBoundary>
        </MudMainContent>
    </MudLayout>
</CascadingValue>

<BlazoredToasts Position="ToastPosition.BottomRight"
                Timeout="6"
                IconType="IconType.FontAwesome"
                SuccessClass="success-toast-override"
                SuccessIcon="fa fa-thumbs-up"
                ErrorIcon="fa fa-bug"
                ShowProgressBar="true"
                WarningIcon="warning"
                ShowCloseButton="true"
                PauseProgressOnHover="true"
                />

@code {
    private bool _menuOpen = true;
}

I have a component like follows called MyComponent

 <MudDataGrid T="CashDealResponseDto" MultiSelection="true" FilterCaseSensitivity="DataGridFilterCaseSensitivity.CaseInsensitive"
              Items="@ComponentData"  
              SortMode="SortMode.Multiple" Filterable="true" Dense="true"
               Striped="true" FilterMode="DataGridFilterMode.ColumnFilterRow">

     <Columns>

         <PropertyColumn HeaderStyle="font-weight:bold;width:8%;" Format="N2" Property="x => x.Amount" Title="Amount" Resizable="true" Filterable="true" />
     </Columns>

     <NoRecordsContent>
         <MudText>No items found</MudText>
     </NoRecordsContent>
     <LoadingContent>
         <MudText>Loading...</MudText>
     </LoadingContent>
 </MudDataGrid>

In my bunit test I have the following

var component = Ctx.RenderComponent<MyComponent>();

component.WaitForState(() => component.FindAll("td").Count > 0);

var tds = component.FindAll("td");
tds[0].InnerHtml.Contains("100").Should().BeTrue();

    
    
    I get this error 

System.InvalidOperationException Missing MudPopoverProvider, please add it to your layout. See https://mudblazor.com/getting-started/installation#manual-install-add-components at MudBlazor.PopoverService.CreatePopoverAsync(IPopover popover) at MudBlazor.MudPopoverBase.OnInitializedAsync()

This is only since Upgrading from v7 to v7.2.0. The same test ran fine before

Upvotes: 3

Views: 2093

Answers (2)

Qu&#226;n Trương
Qu&#226;n Trương

Reputation: 11

I had the same problem as you and how I handled it: <MudSnackbarProvider @rendermode="InteractiveServer" />

I have consulted the documentation:https://learn.microsoft.com/vi-vn/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0

Upvotes: 1

BankMan101
BankMan101

Reputation: 281

The answer was to setup the popup provider check in the test

Ctx.Services.AddMudServices(options =>{options.PopoverOptions.CheckForPopoverProvider = false;});

Upvotes: 4

Related Questions