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