Search in sources :

Example 1 with TextComponent

use of com.vaadin.testbench.unit.ElementConditionsTest.TextComponent in project testbench by vaadin.

the class ComponentQueryTest method withTextContaining_getsCorrectComponent.

@Test
void withTextContaining_getsCorrectComponent() {
    TextComponent span1 = new TextComponent("this is sample text for first span");
    TextComponent span2 = new TextComponent("this is other text second span");
    TextComponent span3 = new TextComponent(null);
    UI.getCurrent().getElement().appendChild(span1.getElement(), span2.getElement(), span3.getElement());
    Assertions.assertIterableEquals(List.of(span1, span2), $(TextComponent.class).withTextContaining("text").allComponents());
    Assertions.assertIterableEquals(List.of(span1, span2), $(TextComponent.class).withTextContaining("span").allComponents());
    Assertions.assertIterableEquals(List.of(span1, span2), $(TextComponent.class).withTextContaining("this").allComponents());
    Assertions.assertIterableEquals(List.of(span1, span2, span3), $(TextComponent.class).withTextContaining("").allComponents());
    Assertions.assertTrue($(TextComponent.class).withTextContaining("textual").allComponents().isEmpty());
}
Also used : TextComponent(com.vaadin.testbench.unit.ElementConditionsTest.TextComponent) Test(org.junit.jupiter.api.Test)

Example 2 with TextComponent

use of com.vaadin.testbench.unit.ElementConditionsTest.TextComponent in project testbench by vaadin.

the class ComponentQueryTest method withText_exactMatch_getsCorrectComponent.

@Test
void withText_exactMatch_getsCorrectComponent() {
    TextComponent span1 = new TextComponent("sample text");
    TextComponent span2 = new TextComponent("other text");
    TextComponent span3 = new TextComponent(null);
    UI.getCurrent().getElement().appendChild(span1.getElement(), span2.getElement(), span3.getElement());
    Assertions.assertSame(span1, $(TextComponent.class).withText("sample text").findComponent());
    Assertions.assertSame(span2, $(TextComponent.class).withText("other text").findComponent());
    Assertions.assertTrue($(TextComponent.class).withText("text").allComponents().isEmpty());
    Assertions.assertTrue($(TextComponent.class).withText("SAMPLE TEXT").allComponents().isEmpty());
    Assertions.assertTrue($(TextComponent.class).withText("other TEXT").allComponents().isEmpty());
}
Also used : TextComponent(com.vaadin.testbench.unit.ElementConditionsTest.TextComponent) Test(org.junit.jupiter.api.Test)

Aggregations

TextComponent (com.vaadin.testbench.unit.ElementConditionsTest.TextComponent)2 Test (org.junit.jupiter.api.Test)2