use of elemental2.dom.HTMLOptGroupElement in project kie-wb-common by kiegroup.
the class DataTypeSelectView method makeOptionGroup.
HTMLOptGroupElement makeOptionGroup(final String groupTitle, final List<DataType> dataTypes, final Function<DataType, String> dataTypeConsumer) {
final HTMLOptGroupElement optionGroup = makeHTMLOptGroupElement();
optionGroup.label = groupTitle;
dataTypes.stream().forEach(dataType -> {
final HTMLOptionElement option = makeOption(dataType, dataTypeConsumer);
optionGroup.appendChild(option);
});
return optionGroup;
}
use of elemental2.dom.HTMLOptGroupElement in project kie-wb-common by kiegroup.
the class DataTypeSelectViewTest method testSetupDropdownItems.
@Test
public void testSetupDropdownItems() {
final HTMLOptGroupElement groupElementStructure = mock(HTMLOptGroupElement.class);
final HTMLOptGroupElement groupElementCustom = mock(HTMLOptGroupElement.class);
final HTMLOptGroupElement groupElementDefault = mock(HTMLOptGroupElement.class);
final List<DataType> defaultDataTypes = new ArrayList<>();
final List<DataType> customDataTypes = new ArrayList<>();
final Element element = mock(Element.class);
when(translationService.format(DataTypeSelectView_DefaultTitle)).thenReturn("Default");
when(translationService.format(DataTypeSelectView_CustomTitle)).thenReturn("Custom");
when(presenter.getDefaultDataTypes()).thenReturn(defaultDataTypes);
when(presenter.getCustomDataTypes()).thenReturn(customDataTypes);
doReturn(groupElementStructure).when(view).makeOptionStructureGroup();
doReturn(groupElementDefault).when(view).makeOptionGroup(eq("Default"), eq(defaultDataTypes), any());
doReturn(groupElementCustom).when(view).makeOptionGroup(eq("Custom"), eq(customDataTypes), any());
typeSelect.firstChild = element;
when(typeSelect.removeChild(element)).then(a -> {
typeSelect.firstChild = null;
return element;
});
view.setupDropdownItems();
final InOrder inOrder = inOrder(typeSelect, element, groupElementStructure, groupElementDefault, groupElementCustom);
inOrder.verify(typeSelect).removeChild(element);
inOrder.verify(typeSelect).appendChild(groupElementStructure);
inOrder.verify(typeSelect).appendChild(groupElementDefault);
inOrder.verify(typeSelect).appendChild(groupElementCustom);
}
use of elemental2.dom.HTMLOptGroupElement in project kie-wb-common by kiegroup.
the class DataTypeSelectViewTest method testMakeOptionGroup.
@Test
@SuppressWarnings("unchecked")
public void testMakeOptionGroup() {
final String dataTypeName = "name";
final String groupTitle = "Title";
final DataType dataType = makeDataType(dataTypeName);
final List<DataType> dataTypes = Collections.singletonList(dataType);
final HTMLOptGroupElement expectedGroupElement = mock(HTMLOptGroupElement.class);
final HTMLOptionElement optionElement = mock(HTMLOptionElement.class);
doReturn(expectedGroupElement).when(view).makeHTMLOptGroupElement();
doReturn(optionElement).when(view).makeOption(eq(dataType), any(Function.class));
final HTMLOptGroupElement actualGroupElement = view.makeOptionGroup(groupTitle, dataTypes, DataType::getName);
verify(expectedGroupElement).appendChild(optionElement);
assertEquals(expectedGroupElement, actualGroupElement);
assertEquals(groupTitle, actualGroupElement.label);
}
use of elemental2.dom.HTMLOptGroupElement in project kie-wb-common by kiegroup.
the class DataTypeSelectViewTest method testOptionGroupSorting.
@Test
@SuppressWarnings("unchecked")
public void testOptionGroupSorting() {
final HTMLOptGroupElement groupElement = mock(HTMLOptGroupElement.class);
final HTMLOptionElement optionElement = mock(HTMLOptionElement.class);
final DataType customDataType1 = makeDataType("b");
final DataType customDataType2 = makeDataType("a");
final List<DataType> customDataTypes = new Lists.Builder().add(customDataType1).add(customDataType2).build();
doReturn(groupElement).when(view).makeHTMLOptGroupElement();
doReturn(optionElement).when(view).makeHTMLOptionElement();
when(translationService.format(DataTypeSelectView_DefaultTitle)).thenReturn("Default");
when(translationService.format(DataTypeSelectView_CustomTitle)).thenReturn("Custom");
when(dataTypeStore.getTopLevelDataTypes()).thenReturn(customDataTypes);
doAnswer(i -> {
final BuiltInType bit = (BuiltInType) i.getArguments()[0];
final DataTypeManager dtm = mock(DataTypeManager.class);
final DataType dt = makeDataType(bit.getName());
when(dtm.get()).thenReturn(dt);
return dtm;
}).when(dataTypeManager).from(any(BuiltInType.class));
doAnswer(i -> dataTypeUtils.defaultDataTypes()).when(presenter).getDefaultDataTypes();
doAnswer(i -> dataTypeUtils.customDataTypes()).when(presenter).getCustomDataTypes();
view.setupDropdownItems();
final int visibleItems = BuiltInType.values().length - 1;
// Check all items were added to the group minus the UNDEFINED item
verify(view, times(visibleItems + customDataTypes.size())).makeOption(dataTypeCaptor.capture(), any(Function.class));
final List<DataType> dataTypes = dataTypeCaptor.getAllValues();
// Check the items were sorted correctly
assertEquals("Any", dataTypes.get(0).getType());
assertEquals("boolean", dataTypes.get(1).getType());
assertEquals("context", dataTypes.get(2).getType());
assertEquals("date", dataTypes.get(3).getType());
assertEquals("date and time", dataTypes.get(4).getType());
assertEquals("days and time duration", dataTypes.get(5).getType());
assertEquals("number", dataTypes.get(6).getType());
assertEquals("string", dataTypes.get(7).getType());
assertEquals("time", dataTypes.get(8).getType());
assertEquals("years and months duration", dataTypes.get(9).getType());
final int customDataTypesOffset = visibleItems;
assertEquals("a", dataTypes.get(customDataTypesOffset).getType());
assertEquals("b", dataTypes.get(customDataTypesOffset + 1).getType());
}
Aggregations