-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support UserAttributes in to all components #1843
Comments
So we would need a |
What would you suggest if there are multiple elements of the same type (buttons as in my example)? I'm currently adding a dummy class that I can use as selector, but it's a bit weird that there's no CSS for those classes. |
We already provide a Could it be enough for your purposes? |
I think I understood better now, and you want we pass that to every first element in the component. Why not simply use |
You don't need a dictionary for UserAttributes. You can directly set them in the markup like this:
For the components who don't support them we'll just do so. It would be trivial for you to PR that. |
Is there a guaranty that the first element will receive the UserAttributes? |
Ah, didn't know usage was so easy, that would definitely help for me. I will create a PR to add UserAttributes where it's missing. |
We have total control where the user attributes are applied. Look for @attributes="UserAttributes" in razor |
I know, but sometimes they are applied to the first element, others to the more convenient element. |
Yes, sometimes userattributes is passed to an underlying input element, which isn't really a problem for testing, as long as it's consistent. I'm currently writing a test that uses reflection to get all MudComponentBase derivates and I then plan to use bunit to see if UserAttributes gets passed to an underlying element. Once we have this test, it would be impossible to forget about it when creating new components in future. But first, dinner 🍽 |
Btw trusting on order is very error prone in UI tests. Specifically in this Up/Down component, the customer has already requested to swap the up/down buttons twice 😁 Changes like this may break the snapshot test but should not break any functional test. |
I only added missing |
What about time picker for example or date picker. We test against many different sub-elements? We also loop through element arrays to test. |
O.M.G. This is way more work than I was thinking. I'm trying to get to the point where the test works, and we can improve from there. |
I have created a PR, which automatically tests all components for the forwarding of UserAttributes. However, you'll see that I had exclude a few components from my test because I don't know how to create them properly. Feel free to take a look at it. Meanwhile, I'm hungry again 😀 |
My PR is finished. Now I only have to exclude 4 components, which are base components that we shouldn't test. I also did a huge refactor and separated the component creation from the test itself, making things readable again (at least from my POV 😉). The |
* Use UserAttributes in all components + enforce with test * Automatically generate generic types using string as TData * Remove dead comment * Update comment * Change old-style code-behind for MudMenuItem * Change old-style code-behind for MudLegend * Test MudElement * Test MudSelectItem * Test MudTabs * Test MudTabPanel * Update comments * Test MudDialog * Test MudMessageBox * Refactor * Finish up :) Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
I want to start testing a lot of components in my application with bUnit. A pattern I'm using (and a lot of others are using) for selecting elements is to use the
data-testid
attribute on elements you want to select instead of using a more complex query-selector. See also this post by Kent C. Dodds. It's also a best practice listed in the cypress docsProposal
My proposal would be to add a parameter
TestId
toMudComponentBase
and to use that parameter to set thedata-testid
attribute on the first element of each component. I am open to create a PR for this.Any other ideas are welcome, my example would be this, how to select the increment or decrement button giving this template:
Alternatives I've considered
The alternative would be to use UserAttributes, but these are not implemented for all components and are also a lot more cumbersome to set (as we need to pass a dictionary).
The text was updated successfully, but these errors were encountered: