Search in sources :

Example 26 with NodeList

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

the class DNDListDOMHelperTest method testGetDraggableElements.

@Test
public void testGetDraggableElements() {
    final String selector = ".kie-dnd-draggable";
    final HTMLElement element0 = mock(HTMLElement.class);
    final HTMLElement element1 = mock(HTMLElement.class);
    final HTMLElement element2 = mock(HTMLElement.class);
    final NodeList<Element> nodeList = spy(new NodeList<>());
    nodeList.length = 3;
    doReturn(element0).when(nodeList).getAt(0);
    doReturn(element1).when(nodeList).getAt(1);
    doReturn(element2).when(nodeList).getAt(2);
    doReturn(nodeList).when(element).querySelectorAll(selector);
    final List<HTMLElement> actualElements = querySelector(element).getDraggableElements();
    final List<HTMLElement> expectElements = asList(element0, element1, element2);
    assertEquals(expectElements, actualElements);
}
Also used : HTMLElement(elemental2.dom.HTMLElement) Element(elemental2.dom.Element) Factory.createGripElement(org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListDOMHelper.Factory.createGripElement) HTMLElement(elemental2.dom.HTMLElement) DNDListDOMHelper.isDraggingElement(org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListDOMHelper.isDraggingElement) Test(org.junit.Test)

Example 27 with NodeList

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

the class DNDListDOMHelperTest method testGetSortedDraggableElements.

@Test
public void testGetSortedDraggableElements() {
    final String selector = ".kie-dnd-draggable";
    final HTMLElement element0 = mock(HTMLElement.class);
    final HTMLElement element1 = mock(HTMLElement.class);
    final HTMLElement element2 = mock(HTMLElement.class);
    final NodeList<Element> nodeList = spy(new NodeList<>());
    nodeList.length = 3;
    doReturn(element0).when(nodeList).getAt(0);
    doReturn(element1).when(nodeList).getAt(1);
    doReturn(element2).when(nodeList).getAt(2);
    doReturn("1").when(element0).getAttribute(DATA_Y_POSITION);
    doReturn("0").when(element1).getAttribute(DATA_Y_POSITION);
    doReturn("-1").when(element2).getAttribute(DATA_Y_POSITION);
    doReturn(nodeList).when(element).querySelectorAll(selector);
    final List<HTMLElement> actualElements = querySelector(element).getSortedDraggableElements();
    final List<HTMLElement> expectElements = asList(element2, element1, element0);
    assertEquals(expectElements, actualElements);
}
Also used : HTMLElement(elemental2.dom.HTMLElement) Element(elemental2.dom.Element) Factory.createGripElement(org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListDOMHelper.Factory.createGripElement) HTMLElement(elemental2.dom.HTMLElement) DNDListDOMHelper.isDraggingElement(org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListDOMHelper.isDraggingElement) Test(org.junit.Test)

Example 28 with NodeList

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

the class DNDDataTypesHandlerContextTest method testGetReferenceWhenCurrentDataTypeIsPresent.

@Test
public void testGetReferenceWhenCurrentDataTypeIsPresent() {
    final Element firstElement = mock(Element.class);
    final Element hiddenElement = mock(Element.class);
    final Element wrongFirstElement = mock(Element.class);
    final HTMLElement dragArea = mock(HTMLElement.class);
    final Optional<DataType> currentDataType = Optional.of(mock(DataType.class));
    final Optional<DataType> firstDataType = Optional.of(mock(DataType.class));
    final String currentUUID = "0000-0000-0000-0000";
    final String firstUUID = "1111-1111-1111-1111";
    dragArea.childNodes = spy(new NodeList<>());
    dragArea.childNodes.length = 4;
    currentElement.classList = mock(DOMTokenList.class);
    wrongFirstElement.classList = mock(DOMTokenList.class);
    firstElement.classList = mock(DOMTokenList.class);
    doReturn(hiddenElement).when(dragArea.childNodes).getAt(0);
    doReturn(currentElement).when(dragArea.childNodes).getAt(1);
    doReturn(wrongFirstElement).when(dragArea.childNodes).getAt(2);
    doReturn(firstElement).when(dragArea.childNodes).getAt(3);
    when(hiddenElement.getAttribute(DATA_Y_POSITION)).thenReturn("-1");
    when(currentElement.getAttribute(DATA_Y_POSITION)).thenReturn("0");
    when(wrongFirstElement.getAttribute(DATA_Y_POSITION)).thenReturn("1");
    when(firstElement.getAttribute(DATA_Y_POSITION)).thenReturn("2");
    when(hiddenElement.getAttribute(DATA_X_POSITION)).thenReturn("0");
    when(currentElement.getAttribute(DATA_X_POSITION)).thenReturn("0");
    when(wrongFirstElement.getAttribute(DATA_X_POSITION)).thenReturn("0");
    when(firstElement.getAttribute(DATA_X_POSITION)).thenReturn("0");
    when(dndListComponent.getDragArea()).thenReturn(dragArea);
    when(dndListComponent.getPreviousElement(any(), any())).thenReturn(Optional.empty());
    when(dataTypeStore.get(currentUUID)).thenReturn(currentDataType.get());
    when(dataTypeStore.get(firstUUID)).thenReturn(firstDataType.get());
    when(currentDataType.get().getName()).thenReturn("Current Data Type");
    when(firstDataType.get().getName()).thenReturn("First Data Type");
    when(currentElement.getAttribute(UUID_ATTR)).thenReturn(currentUUID);
    when(firstElement.getAttribute(UUID_ATTR)).thenReturn(firstUUID);
    when(wrongFirstElement.classList.contains(DRAGGING)).thenReturn(true);
    when(firstElement.classList.contains(DRAGGING)).thenReturn(false);
    // The current element is loaded into constructor.
    // So re-instantiating context here, since this test mock the current element behavior.
    final DNDDataTypesHandlerContext context = new DNDDataTypesHandlerContext(dndDataTypesHandler, currentElement, hoverElement);
    final Optional<DataType> reference = context.getReference();
    assertEquals(firstDataType, reference);
}
Also used : DOMTokenList(elemental2.dom.DOMTokenList) HTMLElement(elemental2.dom.HTMLElement) Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) NodeList(elemental2.dom.NodeList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 29 with NodeList

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

the class DataTypeListItemViewTest method testExpand.

@Test
public void testExpand() {
    // Mock arrow element
    final HTMLElement arrow = mock(HTMLElement.class);
    final DOMTokenList arrowClassList = mock(DOMTokenList.class);
    doReturn(arrow).when(view).getArrow();
    doReturn(false).when(view).isCollapsed(any());
    arrow.classList = arrowClassList;
    // Mock Parent data type with 2 dependent elements
    final DataType parentDataType = mock(DataType.class);
    final String parentDataTypeUUID = "parentDataTypeUUID";
    final Element parentElement = mock(Element.class);
    final Element child1 = makeChildElement("child1UUID");
    final Element child2 = makeChildElement("child2UUID");
    final NodeList<Element> children = spy(new NodeList<>());
    when(parentDataType.getUUID()).thenReturn(parentDataTypeUUID);
    when(parentElement.getAttribute("data-row-uuid")).thenReturn(parentDataTypeUUID);
    doReturn(parentDataType).when(view).getDataType();
    doReturn(child1).when(children).getAt(0);
    doReturn(child2).when(children).getAt(1);
    mockDOMElementByUUID(parentDataTypeUUID, parentElement);
    mockDOMElementsByParentUUID(parentDataTypeUUID, children);
    children.length = 2;
    view.expand();
    verify(arrowClassList).add(DOWN_ARROW_CSS_CLASS);
    verify(arrowClassList).remove(RIGHT_ARROW_CSS_CLASS);
    verify(child1.classList).remove(HIDDEN_CSS_CLASS);
    verify(child2.classList).remove(HIDDEN_CSS_CLASS);
}
Also used : DOMTokenList(elemental2.dom.DOMTokenList) HTMLElement(elemental2.dom.HTMLElement) Element(elemental2.dom.Element) HTMLInputElement(elemental2.dom.HTMLInputElement) 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)

Example 30 with NodeList

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

the class DataTypeListViewTest method testGetLastSubDataTypeElementWithElement.

@Test
public void testGetLastSubDataTypeElementWithElement() {
    final String parentUUID = "parentUUID";
    final Element parentElement = makeElement(parentUUID);
    final NodeList<Element> children = spy(new NodeList<>());
    final Element child1 = makeElement("uuid1");
    final Element child2 = makeElement("uuid2");
    final Element child3 = makeElement("uuid3");
    child1.parentNode = parentElement;
    child2.parentNode = parentElement;
    when(dndListComponent.getPositionY(child1)).thenReturn(0);
    when(dndListComponent.getPositionY(child2)).thenReturn(0);
    when(dndListComponent.getPositionY(child3)).thenReturn(-1);
    doReturn(child1).when(children).getAt(0);
    doReturn(child2).when(children).getAt(1);
    doReturn(child3).when(children).getAt(2);
    children.length = 3;
    mockDOMElementsByParentUUID(parentUUID, children);
    final Element lastElement = view.getLastSubDataTypeElement(parentElement);
    assertEquals(child2, lastElement);
}
Also used : Element(elemental2.dom.Element) HTMLAnchorElement(elemental2.dom.HTMLAnchorElement) HTMLElement(elemental2.dom.HTMLElement) HTMLDivElement(elemental2.dom.HTMLDivElement) HTMLButtonElement(elemental2.dom.HTMLButtonElement) Test(org.junit.Test)

Aggregations

Element (elemental2.dom.Element)36 HTMLElement (elemental2.dom.HTMLElement)33 Test (org.junit.Test)24 HTMLDivElement (elemental2.dom.HTMLDivElement)18 HTMLButtonElement (elemental2.dom.HTMLButtonElement)16 DOMTokenList (elemental2.dom.DOMTokenList)15 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)9 HTMLInputElement (elemental2.dom.HTMLInputElement)8 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)7 NodeList (elemental2.dom.NodeList)4 Factory.createGripElement (org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListDOMHelper.Factory.createGripElement)4 DNDListDOMHelper.isDraggingElement (org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListDOMHelper.isDraggingElement)4 HTMLDocument (elemental2.dom.HTMLDocument)3 HTMLBodyElement (elemental2.dom.HTMLBodyElement)2 Node (elemental2.dom.Node)2 CSSStyleDeclaration (elemental2.dom.CSSStyleDeclaration)1 Window (elemental2.dom.Window)1 ArrayList (java.util.ArrayList)1 DataTypeConstraint (org.kie.workbench.common.dmn.client.editors.types.listview.constraint.DataTypeConstraint)1