Hi folks,
I have a question that I'm not sure you'll have the answer to, but I'm hoping someone here might be able to point me in a decent direction. I've changed my actual values here as it's company source.
I have a Radzen Dropdown with a few items in it.
<div class="row mb-4">
<div class="col-md-4 align-items-center d-flex">
<RadzenLabel Text="Test Label:" id="test-type-label"/>
</div>
<div class="col">
<RadzenDropDown
AllowClear="false"
Data="@AvailableTypes"
TextProperty="TestTypeName "
@bind-Value="SelectedTestTypeModel"
style="width: 100%;"
Name="TestType"
id="test-type-input"/>
<RadzenRequiredValidator Component="TestType" Style="position: absolute" id="test-type-validation"/>
</div>
</div>
Here's an example of a similar C# class it's bound to.
public TestTypeModel(TestType testType)
{
TestType = testType;
TestTypeName = Enum.GetName(TestType);
}
public TestType TestType { get; }
public string TestTypeName { get; }
The page I'm using toggles the visibility of components beneath this dropdown when the value of the dropdown changes and re-renders the component.
The component definition looks like:
<TestComponent>
Visible="@(SelectedTestTypeModel.TestType == TestType.New)">
</TestComponent>
This works great through the UI.
Problem:
I have a unit test that renders the page with BUNIT.
using TestContext context = new TestContext();
// does some common registrations for arrows/input file/popup
context.SetupCommonJsInterop();
// adds a mock client to the component
AddMockClientToService(context);
IRenderedComponent<TestPage> testPage = context.RenderComponent<TestPage>();
// I then can find the dropdown by the id tag I've applied to the control or by finding the li with the appropriate text.
// here's what it looks like rendered
<div class="row mb-4">
<div class="col-md-4 align-items-center d-flex">
<label class="rz-label" id="test-type-label" blazor:elementReference="cfde00ae-7391-42f3-9ddb-bf88a108838c">Test Type:</label>
</div>
<div class="col">
<div class="rz-dropdown valid" onmousedown="Radzen.activeElement = null" blazor:onclick="6" style="width: 100%;" tabindex="0" blazor:onkeydown="7" id="test-type-input" blazor:onfocus="8" blazor:elementReference="">
<div class="rz-helper-hidden-accessible">
<input style="width:100%" aria-haspopup="listbox" readonly type="text" tabindex="-1" name="TestType" value="NamespacedOmmited.TestTypeModel" aria-label="New" />
</div>
<label class="rz-dropdown-label rz-inputtext ">
Update
</label>
<div class="rz-dropdown-trigger rz-corner-right">
<span class="rz-dropdown-trigger-icon rzi rzi-chevron-down"></span>
</div>
<div id="popup-test-type-input" class="rz-dropdown-panel " style="display:none; box-sizing: border-box">
<div class="rz-dropdown-items-wrapper" style="max-height: 200px;overflow-x: hidden">
<ul class="rz-dropdown-items rz-dropdown-list " role="listbox" blazor:elementReference="">
<li role="option" class="rz-dropdown-item rz-state-highlight" aria-label=">New" blazor:onmousedown:preventDefault blazor:onmousedown="9" blazor:onclick:preventDefault blazor:onclick="10">
<span>
New</span>
</li>
<li role="option" class="rz-dropdown-item " aria-label=">Update" blazor:onmousedown:preventDefault blazor:onmousedown="11" blazor:onclick:preventDefault blazor:onclick="12">
<span>
Update </span>
</li>
</ul>
</div>
</div>
</div>
// test code:
IRefreshableElementCollection<IElement> refreshableElementCollection = inlayPage.FindAll("li");
IElement element = refreshableElementCollection
.First(x => x.Text().StripLeadingTrailingSpaces().StripLineBreaks() == "New");
element.Click();
// no change to rendered css even if you manually re-render with
testPage.Render();
I probably should of provided a sample app for this looking at it all now....
Anyways I looked through the existing support tickets especially this one... How to test Radzen Dropdown with bunit?
Which lead me to hunt through the existing unit tests for the components/rendering and I didn't find any for selecting items in the dropdowns. I found some that select buttons for the date time picker which uses a dropdown of sorts.
Does anyone have a recommendation on how to approach this problem? Is it possible to programatically select an item in the dropdown at the moment?
I mostly want to test to make sure that the proper component gets rendered without making the property that we use to determine visibility public if it at all possible.
Thanks for your help,
Chris