All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mvysny.kaributesting.v10.LocatorAddons.kt Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package com.github.mvysny.kaributesting.v10

import com.github.mvysny.kaributools.IconName
import com.github.mvysny.kaributools.caption
import com.github.mvysny.kaributools.iconName
import com.vaadin.flow.component.Component
import com.vaadin.flow.component.HasText
import com.vaadin.flow.component.button.Button
import com.vaadin.flow.component.icon.Icon
import com.vaadin.flow.component.icon.VaadinIcon
import java.util.function.Predicate

/**
 * Makes sure that the component's [Component.caption] contains given [substring].
 */
public fun  SearchSpec.captionContains(substring: String) {
    predicates.add(CaptionContainsPredicate(substring))
}

private data class CaptionContainsPredicate(val substring: String) : Predicate {
    override fun test(t: T): Boolean = t.caption.contains(substring)
    override fun toString() = "captionContains('$substring')"
}

/**
 * Makes sure that the component's [HasText.getText] contains given [substring].
 */
public fun  SearchSpec.textContains(substring: String) where T : HasText, T : Component {
    predicates.add(TextContainsPredicate(substring))
}

private data class TextContainsPredicate(val substring: String) : Predicate {
    override fun test(t: T): Boolean = t.text.contains(substring)
    override fun toString() = "textContains('$substring')"
}

/**
 * Makes sure that [Button.getIcon] is of given [collection] and matches the [iconName].
 */
public fun  SearchSpec.buttonIconIs(collection: String, iconName: String) {
    predicates.add(ButtonIconIsPredicate(IconName(collection, iconName)))
}

/**
 * Makes sure that [Button.getIcon] is given [vaadinIcon].
 */
public fun  SearchSpec.buttonIconIs(vaadinIcon: VaadinIcon) {
    predicates.add(ButtonIconIsPredicate(IconName.of(vaadinIcon)))
}

private data class ButtonIconIsPredicate(val iconName: IconName) : Predicate {
    override fun test(t: T): Boolean {
        val icon: Icon = t.icon as? Icon ?: return false
        return icon.iconName == iconName

    }
    override fun toString() = "buttonIconIs($iconName)"
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy