Skip to content
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

TestBench for unit testing: add typed "selectItem" #1842

Open
RSM-CWI opened this issue Jan 9, 2025 · 3 comments
Open

TestBench for unit testing: add typed "selectItem" #1842

RSM-CWI opened this issue Jan 9, 2025 · 3 comments

Comments

@RSM-CWI
Copy link

RSM-CWI commented Jan 9, 2025

As of now, the ComboBoxTester as well as RadioButtonGroupTester have the method
"selectItem(String)"
I understand that this makes sence from "user point of view" and if you migrate vom Vaadin testBench (selenium based).

But UnitTests are more whitebox tests instead of the blacl box selenium basted tests.

To I recommend, that there should be a typed "selectItem" method, wich accepts the actual values of the ComboBoxes as an alternativ.

In addidtion the _setValue() vor ComboBoxes and RadioButtonGroups in Karibu (you base on) accept the typed values, too!

The CheckBoxTester should have a "setValue" in addition. A "click()" and hope that'll toggle correctly is not that helpful in whitebox tests...

I'd appreciate this extension I assume that it will be helpful for most developers.

@RSM-CWI RSM-CWI changed the title TestBench fo unit testing: add typed "selectItem" TestBench for unit testing: add typed "selectItem" Jan 9, 2025
@mshabarov
Copy link
Contributor

Thanks for the issue, could you please provide an example code that you have in mind for this use case and where you expect another way of selecting an item? Just for us to understand what use case we need to optimise.

@RSM-CWI
Copy link
Author

RSM-CWI commented Jan 14, 2025

Shure. Easy ;-)

Usually ComboBoxes are populated by Enums (sometimes by Entities...)

public enum Status {
  OPEN("Open", 1)
  CLOSED("Closed", 2)
  [...whatever...]
}
ComboBox<Status> statusFilterComboBox;
statusFilterComboBox.setItems(Status.values());

Now for the UnitTest:
Currently I have these 2 options:

test(myView.statusFilterComboBox).selectItem("Open");  // Hoping that "Open" is the correct String being displayed ;-)

or

myView.statusFilterComboBox.setValue(Status.OPEN); // Not really test code, but... ;-)

I would really preffer this, because UnitTesting is more whitebox-testing, so that would make more sense to me:

test(myView.statusFilterComboBox).selectItem(Status.OPEN);  

In addition Karibu allowed setting the value to the ComboBox as typed as above and not only Strings :-)

@mshabarov mshabarov moved this from Inbox (needs triage) to Maybe in Vaadin Flow enhancements backlog (Vaadin 10+) Jan 14, 2025
@mshabarov
Copy link
Contributor

Makes sense to me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants