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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations