mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
105 stars 14 forks source link

Add documentation about interactions with RadioGroup #107

Closed MonsieurNiark closed 2 years ago

MonsieurNiark commented 2 years ago

Hello,

I am struggling while trying to interact with a dynamic radio group, and I do not find any example in code or documentation (except something about getItemsLabel, which is returning me "Div[]" x2.

       final RadioButtonGroup<String> radioButtonGroup = new RadioButtonGroup<>();
        radioButtonGroup.setItems(userOrganisations.stream().map(OrganisationDto::getLibelle).collect(Collectors.toList()));
        radioButtonGroup.setRenderer(new ComponentRenderer<>(nomOrga -> new Div(new Paragraph(nomOrga))));
        radioButtonGroup.setId(ConstantesChoixOrganisationID.FCHOIXORGANISATION_RADIOBUTTON_ORGANISATION);
        radioButtonGroup.setClassName("choix-organisation-radiobouton");

They are rendering in div, because my radio group acting like a choice menu. Any idea on how to interact with them?

Thank you.

mvysny commented 2 years ago

Hi, good question. Components rendered by renderers are generally not attached on the server-side as children, therefore the RadioButtonGroup will never contain those components as children.

Grid has a means to return components returned by renderers: _getCellComponent() as documented at https://github.com/mvysny/karibu-testing/tree/master/karibu-testing-v10#componentrenderer . I'll add the same thing for RadioButtonGroup.

mvysny commented 2 years ago

Actually the code is very simple:

public fun <T : Any> RadioButtonGroup<T>._getRenderedComponent(item: T): Component =
    itemRenderer.createComponent(item)
mvysny commented 2 years ago

Implemented in Karibu-Testing 1.3.13