Search in sources :

Example 66 with TextField

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

the class ComponentQueryTest method id_noMatchingComponent_throws.

@Test
void id_noMatchingComponent_throws() {
    Element rootElement = getCurrentView().getElement();
    rootElement.appendChild(new TextField().getElement());
    TextField textField = new TextField();
    textField.setId("myId");
    rootElement.appendChild(textField.getElement());
    ComponentQuery<TextField> query = $view(TextField.class);
    Assertions.assertThrows(NoSuchElementException.class, () -> query.id("test"));
}
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 67 with TextField

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

the class ComponentQueryTest method atIndex_outOfUpperBound_throws.

@Test
void atIndex_outOfUpperBound_throws() {
    Element rootElement = getCurrentView().getElement();
    rootElement.appendChild(new TextField().getElement(), new TextField().getElement(), new TextField().getElement());
    ComponentQuery<TextField> query = $(TextField.class);
    Assertions.assertThrows(IndexOutOfBoundsException.class, () -> query.atIndex(4));
    Assertions.assertThrows(IndexOutOfBoundsException.class, () -> query.atIndex(100));
}
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 68 with TextField

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

the class ComponentQueryTest method thenOnFirst_firstNotFound_throws.

@Test
void thenOnFirst_firstNotFound_throws() {
    Div div = new Div(new TextField());
    div.setVisible(false);
    UI.getCurrent().getElement().appendChild(div.getElement());
    ComponentQuery<Div> query = $(Div.class);
    Assertions.assertThrows(NoSuchElementException.class, () -> query.thenOnFirst(TextField.class));
}
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 69 with TextField

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

the class ComponentQueryTest method atIndex_exactMatch_getsComponent.

@Test
void atIndex_exactMatch_getsComponent() {
    Element root = getCurrentView().getElement();
    TextField textField = new TextField();
    root.appendChild(textField.getElement());
    Button button = new Button();
    root.appendChild(button.getElement());
    ComponentQuery<TextField> textFieldQuery = $(TextField.class);
    Assertions.assertSame(textField, textFieldQuery.atIndex(1).getComponent(), "Expecting query to find TextField component, but got different instance");
    ComponentQuery<Button> buttonQuery = $(Button.class);
    Assertions.assertSame(button, buttonQuery.atIndex(1).getComponent(), "Expecting query to find Button component, but got different instance");
}
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 70 with TextField

use of com.vaadin.flow.component.textfield.TextField in project vaadin-spinkit by mcollovati.

the class DemoUI method spinnerSizesContainer.

private Component spinnerSizesContainer() {
    List<Spinner> spinners = EnumSet.complementOf(EnumSet.of(SpinnerSize.DEFAULT)).stream().map(size -> {
        Spinner s = createSpinner(SpinnerType.PLANE);
        s.setSize(size);
        s.setTitle(size.name());
        return s;
    }).collect(Collectors.toList());
    List<SpinnerType> spinnerTypes = Stream.of(SpinnerType.values()).filter(t -> !t.isAlias()).collect(Collectors.toList());
    ComboBox<SpinnerType> selector = new ComboBox<>("Select spinner type", spinnerTypes);
    selector.setPreventInvalidInput(true);
    selector.setValue(SpinnerType.ROTATING_PLANE);
    selector.addValueChangeListener(e -> spinners.forEach(s -> s.setType(selector.getValue())));
    TextField baseSize = new TextField("Base size (--sk-size)", "40px");
    baseSize.addValueChangeListener(e -> spinners.forEach(s -> s.setBaseSize(e.getValue())));
    FlexibleGridLayout spinnersContainer = new FlexibleGridLayout().withColumns(Repeat.RepeatMode.AUTO_FILL, new Length("25%")).withPadding(true).withSpacing(true).withItems(spinners.stream().map(s -> spinnerWithName(s, Spinner::getSize)).toArray(Component[]::new));
    for (SpinnerSize size : EnumSet.complementOf(EnumSet.of(SpinnerSize.DEFAULT))) {
        Spinner spinner = new Spinner(SpinnerType.PLANE);
        spinner.setSize(size);
        spinner.setTitle(size.name());
        spinners.add(spinner);
    }
    VerticalLayout commands = new VerticalLayout();
    commands.setSizeUndefined();
    commands.setAlignItems(FlexComponent.Alignment.START);
    commands.setMargin(false);
    commands.setSpacing(true);
    commands.add(selector, baseSize);
    VHorizontalLayout layout = new VHorizontalLayout(commands, spinnersContainer);
    layout.setSizeFull();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setFlexGrow(1, spinnersContainer);
    return layout;
}
Also used : Component(com.vaadin.flow.component.Component) CssImport(com.vaadin.flow.component.dependency.CssImport) Div(com.vaadin.flow.component.html.Div) VTabSheet(org.vaadin.firitin.layouts.VTabSheet) PageTitle(com.vaadin.flow.router.PageTitle) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Function(java.util.function.Function) Spinner(org.vaadin.spinkit.Spinner) VVerticalLayout(org.vaadin.firitin.components.orderedlayout.VVerticalLayout) Route(com.vaadin.flow.router.Route) FlexComponent(com.vaadin.flow.component.orderedlayout.FlexComponent) Repeat(com.github.appreciated.css.grid.sizes.Repeat) Length(com.github.appreciated.css.grid.sizes.Length) TextField(com.vaadin.flow.component.textfield.TextField) EnumSet(java.util.EnumSet) RichText(org.vaadin.firitin.components.RichText) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Collectors(java.util.stream.Collectors) FlexibleGridLayout(com.github.appreciated.layout.FlexibleGridLayout) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Stream(java.util.stream.Stream) Optional(java.util.Optional) VHorizontalLayout(org.vaadin.firitin.components.orderedlayout.VHorizontalLayout) SpinnerType(org.vaadin.spinkit.SpinnerType) Dialog(com.vaadin.flow.component.dialog.Dialog) SpinnerSize(org.vaadin.spinkit.SpinnerSize) Span(com.vaadin.flow.component.html.Span) Spinner(org.vaadin.spinkit.Spinner) ComboBox(com.vaadin.flow.component.combobox.ComboBox) SpinnerSize(org.vaadin.spinkit.SpinnerSize) Length(com.github.appreciated.css.grid.sizes.Length) VHorizontalLayout(org.vaadin.firitin.components.orderedlayout.VHorizontalLayout) TextField(com.vaadin.flow.component.textfield.TextField) FlexibleGridLayout(com.github.appreciated.layout.FlexibleGridLayout) VVerticalLayout(org.vaadin.firitin.components.orderedlayout.VVerticalLayout) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) SpinnerType(org.vaadin.spinkit.SpinnerType) Component(com.vaadin.flow.component.Component) FlexComponent(com.vaadin.flow.component.orderedlayout.FlexComponent)

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