-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spike: Study implementation of unit tests requiring external components #1028
Comments
Let's say we have a blazor component called To test the component ComponentOne (more precisely user interactions with MudAutocomplete), we need to render in first MudPopoverProvider: [TestFixture]
public class DeviceToDuplicateSelectorTests : BlazorUnitTest
{
[Test]
public void Test()
{
// Arrange
// 0) Previous arranges/mockups are ommited on this example
// 1) First we have to render the component MudPopoverProvider
var popoverProvider = RenderComponent<MudPopoverProvider>();
// 2) Then the component under test must be rendered
var cut = RenderComponent<ComponentOne>();
// 3) Find the MudAutocomplete component
var autocompleteComponent = cut.FindComponent<MudAutocomplete<string>>();
// 4) Fire click event on the MudAutocomplete component to allow user input
autocompleteComponent.Find(TagNames.Input).Click();
// 5) Fire input event with user input content
autocompleteComponent.Find(TagNames.Input).Input("");
// 6) Wait until MudPopoverProvider render the expected list of items from MudAutocomplete
popoverProvider.WaitForAssertion(() => popoverProvider.FindAll("div.mud-list-item").Count.Should().Be(1));
// Act
// 7) Find an item on rendered MudPopoverProvider
var item = popoverProvider.Find("div.mud-list-item");
// 8) Fire click event on the desired item to select it
item.Click();
// Assert
// 9) Wait until the MudAutocomplete component is closed after the user has selected an item
cut.WaitForAssertion(() => autocompleteComponent.Instance.IsOpen.Should().BeFalse());
// 10) Add all necessary asserts
cut.WaitForAssertion(() => MockRepository.VerifyAll());
}
} |
See #1168 |
Description
External component like
MudPopoverProvider
should be injected in unit tests to update html DOMAcceptance criteria
The text was updated successfully, but these errors were encountered: