Search in sources :

Example 6 with ValueChangeEvent

use of com.vaadin.flow.component.HasValue.ValueChangeEvent in project flow-components by vaadin.

the class CheckboxGroupTest method selectDisabledItem_noRedundantEvent.

@Test
public void selectDisabledItem_noRedundantEvent() {
    CheckboxGroup<String> group = new CheckboxGroup<>();
    group.setItems("enabled", "disabled");
    group.setItemEnabledProvider("enabled"::equals);
    List<HasValue.ValueChangeEvent<Set<String>>> events = new ArrayList<>();
    group.addValueChangeListener(events::add);
    List<String> keys = group.getChildren().map(Component::getElement).map(element -> element.getProperty("value")).collect(Collectors.toList());
    String enabledKey = keys.get(0);
    String disabledKey = keys.get(1);
    JsonArray array = Json.createArray();
    array.set(0, disabledKey);
    group.getElement().setPropertyJson("value", array);
    Assert.assertThat(group.getValue(), IsEmptyCollection.empty());
    Assert.assertTrue(events.isEmpty());
    array = Json.createArray();
    array.set(0, enabledKey);
    group.getElement().setPropertyJson("value", array);
    Assert.assertEquals(Collections.singleton("enabled"), group.getValue());
    Assert.assertEquals(1, events.size());
    ValueChangeEvent<Set<String>> event = events.get(0);
    Assert.assertThat(event.getOldValue(), IsEmptyCollection.empty());
    Assert.assertEquals(Collections.singleton("enabled"), event.getValue());
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) HasValue(com.vaadin.flow.component.HasValue) Arrays(java.util.Arrays) Component(com.vaadin.flow.component.Component) Json(elemental.json.Json) Div(com.vaadin.flow.component.html.Div) JsonArray(elemental.json.JsonArray) IsEmptyCollection(org.hamcrest.collection.IsEmptyCollection) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) CheckboxGroupListDataView(com.vaadin.flow.component.checkbox.dataview.CheckboxGroupListDataView) MultiSelectionEvent(com.vaadin.flow.data.selection.MultiSelectionEvent) DataProvider(com.vaadin.flow.data.provider.DataProvider) Element(com.vaadin.flow.dom.Element) UI(com.vaadin.flow.component.UI) ExpectedException(org.junit.rules.ExpectedException) VaadinSession(com.vaadin.flow.server.VaadinSession) Instantiator(com.vaadin.flow.di.Instantiator) Collection(java.util.Collection) ValueChangeEvent(com.vaadin.flow.component.HasValue.ValueChangeEvent) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Mockito(org.mockito.Mockito) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) VaadinService(com.vaadin.flow.server.VaadinService) CheckboxGroup(com.vaadin.flow.component.checkbox.CheckboxGroup) Assert(org.junit.Assert) Collections(java.util.Collections) Set(java.util.Set) CheckboxGroup(com.vaadin.flow.component.checkbox.CheckboxGroup) ArrayList(java.util.ArrayList) JsonArray(elemental.json.JsonArray) ValueChangeEvent(com.vaadin.flow.component.HasValue.ValueChangeEvent) Component(com.vaadin.flow.component.Component) Test(org.junit.Test)

Aggregations

ValueChangeEvent (com.vaadin.flow.component.HasValue.ValueChangeEvent)6 Div (com.vaadin.flow.component.html.Div)6 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)3 ResponsiveStep (com.vaadin.flow.component.formlayout.FormLayout.ResponsiveStep)3 NumberField (com.vaadin.flow.component.textfield.NumberField)3 TextField (com.vaadin.flow.component.textfield.TextField)3 ValueChangeListener (com.vaadin.flow.component.HasValue.ValueChangeListener)2 Html (com.vaadin.flow.component.Html)2 Button (com.vaadin.flow.component.button.Button)2 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)2 H6 (com.vaadin.flow.component.html.H6)2 Alignment (com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment)2 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)2 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)2 Select (com.vaadin.flow.component.select.Select)2 TextArea (com.vaadin.flow.component.textfield.TextArea)2 EFieldTypeDefinition (ch.akros.marketplace.administration.constants.EFieldTypeDefinition)1 FieldTypeDefinition (ch.akros.marketplace.administration.dataservice.entity.FieldTypeDefinition)1 Component (com.vaadin.flow.component.Component)1 HasValue (com.vaadin.flow.component.HasValue)1