com.github.mvysny.kaributesting.v10.RadioButtons.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of karibu-testing-v10 Show documentation
Show all versions of karibu-testing-v10 Show documentation
Karibu Testing, support for browserless Vaadin testing in Kotlin
package com.github.mvysny.kaributesting.v10
import com.vaadin.flow.component.Component
import com.vaadin.flow.component.ItemLabelGenerator
import com.vaadin.flow.component.radiobutton.RadioButtonGroup
import com.vaadin.flow.component.select.Select
import com.vaadin.flow.data.renderer.ComponentRenderer
/**
* Returns all item's captions.
*/
public fun RadioButtonGroup.getItemLabels(): List {
val labelGenerator = itemLabelGenerator
return dataProvider._findAll().map { labelGenerator.apply(it) }
}
internal val RadioButtonGroup.itemLabelGenerator: ItemLabelGenerator get() {
val r = itemRenderer
return ItemLabelGenerator { r._getPresentationValue(it).toString() }
}
/**
* Retrieves a component produced by [RadioButtonGroup.itemRenderer]. Fails if the
* renderer is not a [ComponentRenderer].
* @param item the item
* @throws IllegalStateException if the renderer is not [ComponentRenderer].
*/
public fun RadioButtonGroup._getRenderedComponent(item: T): Component =
itemRenderer.createComponent(item)
/**
* Select an item in the radio button group by [label].
*
* Fails if the item is not found, or multiple items are found. Fails if the radio button group is not editable.
*/
public fun RadioButtonGroup.selectByLabel(label: String) {
selectByLabel(label, dataProvider, itemLabelGenerator)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy