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.1.8
Show newest version
package com.github.mvysny.kaributesting.v10

import com.github.mvysny.kaributools.caption
import com.github.mvysny.kaributools.label
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.VaadinIcon
import java.util.function.Predicate

/**
 * Makes sure that the component's [Component.caption] contains given [substring].
 */
@Suppress("DEPRECATION")
@Deprecated("use 'labelContains()' or 'textContains()'")
public fun  SearchSpec.captionContains(substring: String) {
    predicates.add(CaptionContainsPredicate(substring))
}

@Suppress("DEPRECATION")
@Deprecated("use 'label' or 'text'")
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 [Component.caption] contains given [substring].
 */
public fun  SearchSpec.labelContains(substring: String) {
    predicates.add(LabelContainsPredicate(substring))
}

private data class LabelContainsPredicate(val substring: String) : Predicate {
    override fun test(t: T): Boolean = t.label.contains(substring)
    override fun toString() = "labelContains('$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')"
}

@Deprecated("replaced by iconIs()")
public fun  SearchSpec.buttonIconIs(collection: String, iconName: String) {
    iconIs(collection, iconName)
}

@Deprecated("replaced by iconIs()")
public fun  SearchSpec.buttonIconIs(vaadinIcon: VaadinIcon) {
    iconIs(vaadinIcon)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy