Search in sources :

Example 16 with HTMLOptionElement

use of elemental2.dom.HTMLOptionElement in project kie-wb-common by kiegroup.

the class TimeSelectorViewTest method testReloadTimeZoneSelectorIsOffsetMode.

@Test
public void testReloadTimeZoneSelectorIsOffsetMode() {
    final HTMLOptionElement none = mock(HTMLOptionElement.class);
    doReturn(none).when(view).createNoneOption();
    doReturn(true).when(view).getIsOffsetMode();
    view.reloadTimeZoneSelector();
    verify(view).populateTimeZoneSelectorWithOffSets();
    verify(view, never()).populateTimeZoneSelectorWithIds();
}
Also used : HTMLOptionElement(elemental2.dom.HTMLOptionElement) Test(org.junit.Test)

Example 17 with HTMLOptionElement

use of elemental2.dom.HTMLOptionElement 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 18 with HTMLOptionElement

use of elemental2.dom.HTMLOptionElement 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)

Example 19 with HTMLOptionElement

use of elemental2.dom.HTMLOptionElement in project kie-wb-common by kiegroup.

the class KieAssetsDropdownView method selectOption.

protected HTMLOptionElement selectOption() {
    final HTMLOptionElement option = makeHTMLOptionElement();
    option.text = translationService.format(KieAssetsDropdownView_Select);
    option.value = "";
    return option;
}
Also used : HTMLOptionElement(elemental2.dom.HTMLOptionElement)

Example 20 with HTMLOptionElement

use of elemental2.dom.HTMLOptionElement in project kie-wb-common by kiegroup.

the class KieAssetsDropdownViewTest method selectOption.

@Test
public void selectOption() {
    final HTMLOptionElement retrieved = kieAssetsDropdownView.selectOption();
    assertNotNull(retrieved);
    assertEquals(KIEASSETSDROPDOWNVIEW_SELECT, retrieved.text);
    assertEquals("", retrieved.value);
}
Also used : HTMLOptionElement(elemental2.dom.HTMLOptionElement) Test(org.junit.Test)

Aggregations

HTMLOptionElement (elemental2.dom.HTMLOptionElement)20 Test (org.junit.Test)11 HTMLOptGroupElement (elemental2.dom.HTMLOptGroupElement)3 DMNSimpleTimeZone (org.kie.workbench.common.dmn.api.editors.types.DMNSimpleTimeZone)3 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)3 Function (java.util.function.Function)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 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