Search in sources :

Example 1 with TestEnum

use of org.linkki.core.ui.bind.TestEnum in project linkki by linkki-framework.

the class AvailableValuesAspectDefinitionTest method testUiUpdater_SetComboBoxValueBeforeUiUpdate.

@Test
void testUiUpdater_SetComboBoxValueBeforeUiUpdate() {
    AvailableValuesAspectDefinition<ComboBox<Object>> availableValuesAspectDefinition = new AvailableValuesAspectDefinition<>(AvailableValuesType.DYNAMIC, ComboBox::setItems);
    ComboBox<TestEnum> component = new ComboBox<>();
    availableValuesAspectDefinition.createUiUpdater(mock(PropertyDispatcher.class), new NoLabelComponentWrapper(component));
    // linkki sets values before the UI updater has been called for the first time
    component.setValue(TestEnum.ONE);
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) TestEnum(org.linkki.core.ui.bind.TestEnum) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) Test(org.junit.jupiter.api.Test)

Example 2 with TestEnum

use of org.linkki.core.ui.bind.TestEnum in project linkki by linkki-framework.

the class GenericAvailableValuesAspectDefinitionTest method testHandleNullItems_NativeSelect_NoNull.

@Test
public void testHandleNullItems_NativeSelect_NoNull() {
    GenericAvailableValuesAspectDefinition hasItemsAvailableValuesAspectDefinition = new GenericAvailableValuesAspectDefinition(AvailableValuesType.DYNAMIC);
    Select<TestEnum> nativeSelect = new Select<>();
    ComponentWrapper componentWrapper = new NoLabelComponentWrapper(nativeSelect, WrapperType.FIELD);
    hasItemsAvailableValuesAspectDefinition.handleNullItems(componentWrapper, new LinkedList<>(Arrays.asList(TestEnum.TWO)));
    assertThat(nativeSelect.isEmptySelectionAllowed(), is(false));
}
Also used : NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Select(com.vaadin.flow.component.select.Select) TestEnum(org.linkki.core.ui.bind.TestEnum) ComponentWrapper(org.linkki.core.binding.wrapper.ComponentWrapper) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Test(org.junit.jupiter.api.Test)

Example 3 with TestEnum

use of org.linkki.core.ui.bind.TestEnum in project linkki by linkki-framework.

the class GenericAvailableValuesAspectDefinitionTest method testHandleNullItems_ComboBox_WithNullValue.

@Test
public void testHandleNullItems_ComboBox_WithNullValue() {
    GenericAvailableValuesAspectDefinition hasItemsAvailableValuesAspectDefinition = new GenericAvailableValuesAspectDefinition(AvailableValuesType.DYNAMIC);
    ComboBox<TestEnum> comboBox = new ComboBox<>();
    ComponentWrapper componentWrapper = new NoLabelComponentWrapper(comboBox, WrapperType.FIELD);
    hasItemsAvailableValuesAspectDefinition.handleNullItems(componentWrapper, new LinkedList<>(Arrays.asList(TestEnum.ONE, null)));
    assertThat(comboBox.isAllowCustomValue());
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) TestEnum(org.linkki.core.ui.bind.TestEnum) ComponentWrapper(org.linkki.core.binding.wrapper.ComponentWrapper) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Test(org.junit.jupiter.api.Test)

Example 4 with TestEnum

use of org.linkki.core.ui.bind.TestEnum in project linkki by linkki-framework.

the class GenericAvailableValuesAspectDefinitionTest method testHandleNullItems_ComboBox_NoNullValue.

@Test
public void testHandleNullItems_ComboBox_NoNullValue() {
    GenericAvailableValuesAspectDefinition hasItemsAvailableValuesAspectDefinition = new GenericAvailableValuesAspectDefinition(AvailableValuesType.DYNAMIC);
    ComboBox<TestEnum> comboBox = new ComboBox<>();
    ComponentWrapper componentWrapper = new NoLabelComponentWrapper(comboBox, WrapperType.FIELD);
    hasItemsAvailableValuesAspectDefinition.handleNullItems(componentWrapper, new LinkedList<>(Arrays.asList(TestEnum.TWO)));
    assertThat(comboBox.isAllowCustomValue(), is(false));
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) TestEnum(org.linkki.core.ui.bind.TestEnum) ComponentWrapper(org.linkki.core.binding.wrapper.ComponentWrapper) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Test(org.junit.jupiter.api.Test)

Example 5 with TestEnum

use of org.linkki.core.ui.bind.TestEnum in project linkki by linkki-framework.

the class AvailableValuesAspectDefinitionTest method testUiUpdater.

@SuppressWarnings("unchecked")
@Test
void testUiUpdater() {
    AvailableValuesAspectDefinition<DataComponent<Object>> availableValuesAspectDefinition = new AvailableValuesAspectDefinition<>(AvailableValuesType.DYNAMIC, DataComponent<Object>::setItems);
    DataComponent<TestEnum> component = spy(new DataComponent<>());
    PropertyDispatcher propertyDispatcher = mock(PropertyDispatcher.class);
    when(propertyDispatcher.pull(any())).thenReturn(Arrays.asList(TestEnum.ONE, TestEnum.TWO));
    Handler uiUpdater = availableValuesAspectDefinition.createUiUpdater(propertyDispatcher, new NoLabelComponentWrapper(component));
    // items are set initially during the first update
    reset(component);
    uiUpdater.apply();
    verify(component).setItems(List.of(TestEnum.ONE, TestEnum.TWO));
    verifyNoMoreInteractions(component);
    // items are updated when the aspect value changes
    reset(component);
    when(propertyDispatcher.pull(any())).thenReturn(List.of(TestEnum.ONE));
    uiUpdater.apply();
    verify(component).setItems(List.of(TestEnum.ONE));
    verifyNoMoreInteractions(component);
    // items are not updated when the aspect value stays the same
    reset(component);
    uiUpdater.apply();
    verifyNoMoreInteractions(component);
}
Also used : NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Handler(org.linkki.util.handler.Handler) TestEnum(org.linkki.core.ui.bind.TestEnum) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)6 TestEnum (org.linkki.core.ui.bind.TestEnum)6 NoLabelComponentWrapper (org.linkki.core.ui.wrapper.NoLabelComponentWrapper)6 ComponentWrapper (org.linkki.core.binding.wrapper.ComponentWrapper)4 ComboBox (com.vaadin.flow.component.combobox.ComboBox)3 Select (com.vaadin.flow.component.select.Select)2 PropertyDispatcher (org.linkki.core.binding.dispatcher.PropertyDispatcher)2 Handler (org.linkki.util.handler.Handler)1