Search in sources :

Example 36 with DataType

use of org.kie.workbench.common.dmn.client.editors.types.common.DataType in project kie-wb-common by kiegroup.

the class DNDDataTypesHandlerTest method testOnDropDataTypeWhenReferenceIsNotPresent.

@Test
public void testOnDropDataTypeWhenReferenceIsNotPresent() {
    final Element currentElement = mock(Element.class);
    final Element hoverElement = mock(Element.class);
    final DataType current = mock(DataType.class);
    final DNDDataTypesHandlerContext context = mock(DNDDataTypesHandlerContext.class);
    doNothing().when(handler).logError(Mockito.<String>any());
    doReturn(context).when(handler).makeDndContext(currentElement, hoverElement);
    when(context.getCurrentDataType()).thenReturn(Optional.of(current));
    when(context.getReference()).thenReturn(Optional.empty());
    handler.onDropDataType(currentElement, hoverElement);
    verify(handler, never()).shiftCurrentByReference(any(), any(), any());
}
Also used : Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 37 with DataType

use of org.kie.workbench.common.dmn.client.editors.types.common.DataType in project kie-wb-common by kiegroup.

the class DNDDataTypesHandlerTest method testGetReferenceWhenDNDListComponentIsNotInitialized.

@Test
public void testGetReferenceWhenDNDListComponentIsNotInitialized() {
    final Element currentElement = mock(Element.class);
    final Element hoverElement = mock(Element.class);
    final Element previousElement = mock(Element.class);
    final Optional<DataType> previousDataType = Optional.of(mock(DataType.class));
    final String uuid = "0000-1111-2222-3333";
    when(dndListComponent.getPreviousElement(any(), any())).thenReturn(Optional.of(previousElement));
    when(dataTypeStore.get(uuid)).thenReturn(previousDataType.get());
    when(previousElement.getAttribute(UUID_ATTR)).thenReturn(uuid);
    when(dataTypeList.getDNDListComponent()).thenReturn(null);
    assertThatThrownBy(() -> handler.makeDndContext(currentElement, hoverElement).getReference()).isInstanceOf(UnsupportedOperationException.class).hasMessage("'DNDDataTypesHandler' must be initialized with a 'DNDListComponent' instance.");
}
Also used : Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 38 with DataType

use of org.kie.workbench.common.dmn.client.editors.types.common.DataType in project kie-wb-common by kiegroup.

the class DNDDataTypesHandlerTest method testOnDropDataType.

@Test
public void testOnDropDataType() {
    final Element currentElement = mock(Element.class);
    final Element hoverElement = mock(Element.class);
    final DataType current = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DNDDataTypesHandlerContext context = mock(DNDDataTypesHandlerContext.class);
    final DNDDataTypesHandlerShiftStrategy strategy = INSERT_INTO_HOVERED_DATA_TYPE;
    doNothing().when(handler).logError(Mockito.<String>any());
    doReturn(context).when(handler).makeDndContext(currentElement, hoverElement);
    when(context.getCurrentDataType()).thenReturn(Optional.of(current));
    when(context.getReference()).thenReturn(Optional.of(reference));
    when(context.getStrategy()).thenReturn(strategy);
    handler.onDropDataType(currentElement, hoverElement);
    verify(handler).shiftCurrentByReference(current, reference, strategy);
}
Also used : Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 39 with DataType

use of org.kie.workbench.common.dmn.client.editors.types.common.DataType in project kie-wb-common by kiegroup.

the class DataTypeListViewTest method testShowArrowIconIfDataTypeHasChildrenWhenDataTypeDoesNotHaveChildren.

@Test
public void testShowArrowIconIfDataTypeHasChildrenWhenDataTypeDoesNotHaveChildren() {
    final DataType dataType = mock(DataType.class);
    final NodeList<Element> elementNodeList = new NodeList<>();
    final Element dataTypeRow = mock(Element.class);
    final Element dataTypeRowArrow = mock(Element.class);
    final DOMTokenList arrowClassList = mock(DOMTokenList.class);
    final String uuid = "uuid";
    dataTypeRowArrow.classList = arrowClassList;
    elementNodeList.length = 0;
    when(dataType.getUUID()).thenReturn(uuid);
    when(listItems.querySelectorAll("[" + PARENT_UUID_ATTR + "=\"uuid\"]")).thenReturn(elementNodeList);
    when(listItems.querySelector("[" + UUID_ATTR + "=\"uuid\"]")).thenReturn(dataTypeRow);
    when(dataTypeRow.querySelector(ARROW_BUTTON_SELECTOR)).thenReturn(dataTypeRowArrow);
    view.showArrowIconIfDataTypeHasChildren(dataType);
    verify(arrowClassList).add(HIDDEN_CSS_CLASS);
}
Also used : DOMTokenList(elemental2.dom.DOMTokenList) Element(elemental2.dom.Element) HTMLAnchorElement(elemental2.dom.HTMLAnchorElement) HTMLElement(elemental2.dom.HTMLElement) HTMLDivElement(elemental2.dom.HTMLDivElement) HTMLButtonElement(elemental2.dom.HTMLButtonElement) NodeList(elemental2.dom.NodeList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 40 with DataType

use of org.kie.workbench.common.dmn.client.editors.types.common.DataType in project kie-wb-common by kiegroup.

the class DataTypeListViewTest method testInsertBelow.

@Test
public void testInsertBelow() {
    final DataTypeListItem listItem = mock(DataTypeListItem.class);
    final DataType reference = mock(DataType.class);
    final HTMLElement listItemElement = mock(HTMLElement.class);
    final Element lastElement = spy(new Element());
    final Element parentElement = mock(Element.class);
    final Element siblingElement = mock(Element.class);
    lastElement.parentNode = parentElement;
    lastElement.nextSibling = siblingElement;
    when(listItem.getDragAndDropElement()).thenReturn(listItemElement);
    doReturn(lastElement).when(view).getLastSubDataTypeElement(reference);
    view.insertBelow(listItem, reference);
    verify(parentElement).insertBefore(listItemElement, siblingElement);
    verify(view).setNewElementYPosition(lastElement, listItemElement);
}
Also used : HTMLElement(elemental2.dom.HTMLElement) Element(elemental2.dom.Element) HTMLAnchorElement(elemental2.dom.HTMLAnchorElement) HTMLElement(elemental2.dom.HTMLElement) HTMLDivElement(elemental2.dom.HTMLDivElement) HTMLButtonElement(elemental2.dom.HTMLButtonElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Aggregations

DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)274 Test (org.junit.Test)245 HTMLElement (elemental2.dom.HTMLElement)44 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)39 Element (elemental2.dom.Element)30 ArrayList (java.util.ArrayList)26 DOMTokenList (elemental2.dom.DOMTokenList)24 DataTypeListItem (org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem)14 HTMLDivElement (elemental2.dom.HTMLDivElement)13 HTMLButtonElement (elemental2.dom.HTMLButtonElement)12 Command (org.uberfire.mvp.Command)12 FlashMessage (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage)9 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)9 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)8 DNDListComponent (org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListComponent)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)6 HTMLInputElement (elemental2.dom.HTMLInputElement)6 DataObject (org.kie.workbench.common.dmn.api.editors.types.DataObject)6