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);
}
}
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);
}
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");
}
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());
}
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");
}
Aggregations