Search in sources :

Example 1 with HTMLOptGroupElement

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;
}
Also used : HTMLOptGroupElement(elemental2.dom.HTMLOptGroupElement) HTMLOptionElement(elemental2.dom.HTMLOptionElement)

Example 2 with HTMLOptGroupElement

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);
}
Also used : HTMLOptGroupElement(elemental2.dom.HTMLOptGroupElement) InOrder(org.mockito.InOrder) HTMLOptionElement(elemental2.dom.HTMLOptionElement) HTMLElement(elemental2.dom.HTMLElement) HTMLSelectElement(elemental2.dom.HTMLSelectElement) Element(elemental2.dom.Element) HTMLOptGroupElement(elemental2.dom.HTMLOptGroupElement) HTMLDivElement(elemental2.dom.HTMLDivElement) ArrayList(java.util.ArrayList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 3 with HTMLOptGroupElement

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);
}
Also used : Function(java.util.function.Function) HTMLOptGroupElement(elemental2.dom.HTMLOptGroupElement) HTMLOptionElement(elemental2.dom.HTMLOptionElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with HTMLOptGroupElement

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());
}
Also used : Function(java.util.function.Function) HTMLOptGroupElement(elemental2.dom.HTMLOptGroupElement) DataTypeManager(org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager) Lists(org.kie.soup.commons.util.Lists) HTMLOptionElement(elemental2.dom.HTMLOptionElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Test(org.junit.Test)

Aggregations

HTMLOptGroupElement (elemental2.dom.HTMLOptGroupElement)4 HTMLOptionElement (elemental2.dom.HTMLOptionElement)4 Test (org.junit.Test)3 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)3 Function (java.util.function.Function)2 Element (elemental2.dom.Element)1 HTMLDivElement (elemental2.dom.HTMLDivElement)1 HTMLElement (elemental2.dom.HTMLElement)1 HTMLSelectElement (elemental2.dom.HTMLSelectElement)1 ArrayList (java.util.ArrayList)1 Lists (org.kie.soup.commons.util.Lists)1 BuiltInType (org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType)1 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 InOrder (org.mockito.InOrder)1