Search in sources :

Example 61 with TextField

use of com.vaadin.flow.component.textfield.TextField in project testbench by vaadin.

the class ComponentQueryTest method withId_matchingComponent_getsComponent.

@Test
void withId_matchingComponent_getsComponent() {
    Element rootElement = getCurrentView().getElement();
    List<TextField> textFields = IntStream.rangeClosed(1, 5).mapToObj(idx -> {
        TextField field = new TextField();
        field.setId("field-" + idx);
        return field;
    }).peek(field -> rootElement.appendChild(field.getElement())).collect(Collectors.toList());
    ComponentQuery<TextField> query = $view(TextField.class);
    for (TextField expected : textFields) {
        List<TextField> result = query.withId(expected.getId().orElse("")).allComponents();
        Assertions.assertIterableEquals(Collections.singleton(expected), result);
    }
}
Also used : IntStream(java.util.stream.IntStream) Text(com.vaadin.flow.component.Text) Component(com.vaadin.flow.component.Component) Div(com.vaadin.flow.component.html.Div) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) HasLabel(com.vaadin.flow.component.HasLabel) List(java.util.List) Tag(com.vaadin.flow.component.Tag) Button(com.vaadin.flow.component.button.Button) Span(com.vaadin.testbench.unit.ComponentWrapTest.Span) GeneratedVaadinTextField(com.vaadin.flow.component.textfield.GeneratedVaadinTextField) Arrays.asList(java.util.Arrays.asList) IntegerField(com.vaadin.flow.component.textfield.IntegerField) Element(com.vaadin.flow.dom.Element) Assertions(org.junit.jupiter.api.Assertions) UI(com.vaadin.flow.component.UI) NoSuchElementException(java.util.NoSuchElementException) Collections(java.util.Collections) TextField(com.vaadin.flow.component.textfield.TextField) TextComponent(com.vaadin.testbench.unit.ElementConditionsTest.TextComponent) Element(com.vaadin.flow.dom.Element) GeneratedVaadinTextField(com.vaadin.flow.component.textfield.GeneratedVaadinTextField) TextField(com.vaadin.flow.component.textfield.TextField) Test(org.junit.jupiter.api.Test)

Example 62 with TextField

use of com.vaadin.flow.component.textfield.TextField in project testbench by vaadin.

the class ComponentQueryTest method thenOnFirst_chainedQuery_getsNestedComponents.

@Test
void thenOnFirst_chainedQuery_getsNestedComponents() {
    TextField deepNested = new TextField();
    Div nestedDiv = new Div(deepNested);
    nestedDiv.setId("nestedDiv");
    TextField nested1 = new TextField();
    TextField nested2 = new TextField();
    Div firstMatch = new Div(new Div(nestedDiv), nested1, new Div(nested2));
    firstMatch.setId("myId");
    UI.getCurrent().getElement().appendChild(new Div(firstMatch).getElement(), new TextField().getElement());
    List<TextField> result = $(Div.class).withId("myId").thenOnFirst(TextField.class).allComponents();
    Assertions.assertIterableEquals(List.of(deepNested, nested1, nested2), result);
    result = $(Div.class).withId("myId").thenOnFirst(Div.class).withId("nestedDiv").thenOnFirst(TextField.class).allComponents();
    Assertions.assertIterableEquals(List.of(deepNested), result);
}
Also used : Div(com.vaadin.flow.component.html.Div) GeneratedVaadinTextField(com.vaadin.flow.component.textfield.GeneratedVaadinTextField) TextField(com.vaadin.flow.component.textfield.TextField) Test(org.junit.jupiter.api.Test)

Example 63 with TextField

use of com.vaadin.flow.component.textfield.TextField in project testbench by vaadin.

the class ComponentQueryTest method first_multipleMatching_getsFirstComponent.

@Test
void first_multipleMatching_getsFirstComponent() {
    TextField first = new TextField();
    Element rootElement = getCurrentView().getElement();
    rootElement.appendChild(first.getElement(), new TextField().getElement(), new TextField().getElement(), new TextField().getElement());
    ComponentQuery<TextField> query = $(TextField.class);
    Assertions.assertSame(first, query.first().getComponent(), "Expecting query to find TextField component, but got different instance");
}
Also used : Element(com.vaadin.flow.dom.Element) GeneratedVaadinTextField(com.vaadin.flow.component.textfield.GeneratedVaadinTextField) TextField(com.vaadin.flow.component.textfield.TextField) Test(org.junit.jupiter.api.Test)

Example 64 with TextField

use of com.vaadin.flow.component.textfield.TextField in project testbench by vaadin.

the class ComponentQueryTest method withId_matchingDifferentComponentType_emptyList.

@Test
void withId_matchingDifferentComponentType_emptyList() {
    Element rootElement = getCurrentView().getElement();
    rootElement.appendChild(new TextField().getElement());
    Button button = new Button();
    button.setId("myId");
    rootElement.appendChild(button.getElement());
    ComponentQuery<TextField> query = $view(TextField.class);
    Assertions.assertTrue(query.withId("myId").allComponents().isEmpty());
}
Also used : Button(com.vaadin.flow.component.button.Button) Element(com.vaadin.flow.dom.Element) GeneratedVaadinTextField(com.vaadin.flow.component.textfield.GeneratedVaadinTextField) TextField(com.vaadin.flow.component.textfield.TextField) Test(org.junit.jupiter.api.Test)

Example 65 with TextField

use of com.vaadin.flow.component.textfield.TextField in project testbench by vaadin.

the class ComponentQueryTest method last_multipleMatching_getsLastComponent.

@Test
void last_multipleMatching_getsLastComponent() {
    TextField last = new TextField();
    Element rootElement = getCurrentView().getElement();
    rootElement.appendChild(new TextField().getElement(), new TextField().getElement(), new TextField().getElement(), last.getElement());
    ComponentQuery<TextField> query = $(TextField.class);
    Assertions.assertSame(last, query.last().getComponent(), "Expecting query to find TextField component, but got different instance");
}
Also used : Element(com.vaadin.flow.dom.Element) GeneratedVaadinTextField(com.vaadin.flow.component.textfield.GeneratedVaadinTextField) TextField(com.vaadin.flow.component.textfield.TextField) Test(org.junit.jupiter.api.Test)

Aggregations

TextField (com.vaadin.flow.component.textfield.TextField)227 Test (org.junit.jupiter.api.Test)61 Button (com.vaadin.flow.component.button.Button)54 Div (com.vaadin.flow.component.html.Div)38 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)32 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)29 Binder (com.vaadin.flow.data.binder.Binder)29 GeneratedVaadinTextField (com.vaadin.flow.component.textfield.GeneratedVaadinTextField)28 Element (com.vaadin.flow.dom.Element)26 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)23 Route (com.vaadin.flow.router.Route)21 Component (com.vaadin.flow.component.Component)16 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)15 BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)15 Grid (com.vaadin.flow.component.grid.Grid)15 Span (com.vaadin.flow.component.html.Span)15 List (java.util.List)15 EmailField (com.vaadin.flow.component.textfield.EmailField)14 TextArea (com.vaadin.flow.component.textfield.TextArea)14 Test (org.junit.Test)14