Unit testing a grid toolbar

Hi,

I'm creating a grid with a custom toolbar. One of the items, a ItemModel, contains a SfButtonGroup with several Buttons inside. I would like to test the click on one of this buttons.

How could I create some unit tests to validate this behavior?

thumbnail_image.png


Regards.


1 Reply

SK Sanjay Kumar Suresh Syncfusion Team March 25, 2025 02:24 PM UTC

Hi Juan Francisco,


As per your requirement, we have created a unit test case to validate the ItemModel inside the custom toolbar. In this test case, we have simulated the click action on the relevant icon and verified whether the expected action is executed successfully.


Concern Code Snippet:


  public void Test1()

  {

      using var context = new Bunit.TestContext();

 

      // Add Syncfusion Blazor service and Ignore script isolation.

      context.Services.AddSyncfusionBlazor();

      context.Services.AddOptions();

 

      // Arrange

      var cut = context.RenderComponent<UnitTesting.Components.Pages.Home>();

 

      // Act

      var button = cut.Find("div#big"); // Selects the button with ID "big"

      button.Click();

 

      var rowHeight = cut.Find(".e-row").GetAttribute("style");

 

      // Assert

      Xunit.Assert.True(rowHeight == "height: 60px");

 

  }


We have attached the concern sample please review the implementation, and let us know if you need any further modifications or assistance.


Regards,

Sanjay Kumar Suresh


Attachment: UnitTesting_39e2cb0c.7z

Loader.
Up arrow icon