hi a couple of years ago it was not possible to unit test the RadzenDataGridService with Bunit. by now I think it should be possible but I cannot get it to work.
My Compoment
@using Radzen
@using Radzen.Blazor
<script src="_content/Radzen.Blazor/Radzen.Blazor.js?v=@(typeof(Radzen.Colors).Assembly.GetName().Version)"></script>
<RadzenComponents />
<div>
<button class="trigger-dialog" @onclick="OpenDialog">Open Dialog</button>
</div>
@code {
[Inject]
protected DialogService? DialogService { get; set; }
private void OpenDialog()
{
Console.WriteLine("dialog opened");
DialogService.Open<MyDialog>(
"My dialog title",
new Dictionary<string, object>()
{
{ "SomeParameter", "Hello from MyComponent!" }
}
);
}
protected override void OnInitialized()
{
DialogService.OnOpen += DialogServiceOnOnOpen;
base.OnInitialized();
}
private void DialogServiceOnOnOpen(string arg1, Type arg2, Dictionary<string, object> arg3, DialogOptions arg4)
{
Console.WriteLine("dialog opened in MyComponent");
}
}
my dialog
@code {
[Parameter]
public string SomeParameter { get; set; }
}
<div>
<h3>This is content inside MyDialog</h3>
<p>@SomeParameter</p>
</div>
my test
[Fact]
public void RendersMyComponentAndShowsRadzenDialog()
{
using var ctx = new TestContext();
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
var navigationManager = new InnovativeDialogTests.TestNavigationManager();
var jsRuntimeMock = new Mock<IJSRuntime>();
var dialogService = new DialogService(navigationManager, jsRuntimeMock.Object);
var notificationService = new NotificationService();
ctx.Services.AddSingleton(dialogService);
ctx.Services.AddSingleton(notificationService);
ctx.Services.AddRadzenComponents();
var cut = ctx.RenderComponent<MyComponent>();
var button = cut.Find("button.trigger-dialog");
button.Click();
Assert.Contains("rz-dialog-header", cut.Markup); // Example class name in dialog's header
Assert.Contains("My dialog title", cut.Markup); // Sample title you'd set in your dialog
}
}
}
when I run it I can see that my component in tet has the following body
<script src="_content/Radzen.Blazor/Radzen.Blazor.js?v=6.3.0.0"></script>
<div aria-live="polite" class="rz-notification"></div>
<div><button class="trigger-dialog" blazor:onclick="1">Open Dialog</button></div>
I think I miss something very simple why my dialog is not showing up