Search in sources :

Example 16 with DataTypeListItem

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

the class DataTypeSearchBarViewTest method testGroupElementWithItsParentWhenParentIsOnList.

@Test
public void testGroupElementWithItsParentWhenParentIsOnList() {
    final DataTypeListItem item = mock(DataTypeListItem.class);
    final DataTypeListItem parent = mock(DataTypeListItem.class);
    final DataTypeListItem dummy = mock(DataTypeListItem.class);
    final List<DataTypeListItem> groupedElements = new ArrayList<>();
    groupedElements.add(parent);
    groupedElements.add(dummy);
    final List<DataTypeListItem> allElements = Arrays.asList(parent);
    final String parentUuid = "parent_uuid";
    final HTMLElement itemDragAndDropElement = mock(HTMLElement.class);
    final HTMLElement parentDragAndDropElement = mock(HTMLElement.class);
    when(parent.getDragAndDropElement()).thenReturn(parentDragAndDropElement);
    when(item.getDragAndDropElement()).thenReturn(itemDragAndDropElement);
    when(itemDragAndDropElement.getAttribute(PARENT_UUID_ATTR)).thenReturn(parentUuid);
    when(parentDragAndDropElement.getAttribute(UUID_ATTR)).thenReturn(parentUuid);
    doReturn(true).when(view).isParentElementOnList(groupedElements, parentUuid);
    doReturn(0).when(view).getIndexOfParentOrLastElementInGroup(groupedElements, parent);
    view.groupElementWithItsParent(groupedElements, allElements, item);
    assertEquals(3, groupedElements.size());
    assertEquals(parent, groupedElements.get(0));
    assertEquals(item, groupedElements.get(1));
    assertEquals(dummy, groupedElements.get(2));
    verify(view, never()).groupElementWithItsParent(groupedElements, allElements, parent);
    verify(view).getIndexOfParentOrLastElementInGroup(groupedElements, parent);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with DataTypeListItem

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

the class DataTypeSearchBarViewTest method testGroupElementsWithItsParents.

@Test
public void testGroupElementsWithItsParents() {
    final List<DataTypeListItem> groupedElementsList = mock(List.class);
    final DataTypeListItem element1 = mock(DataTypeListItem.class);
    final DataTypeListItem element2 = mock(DataTypeListItem.class);
    final List<DataTypeListItem> allElements = Arrays.asList(element1, element2);
    doReturn(groupedElementsList).when(view).getGroupedElementsList();
    doNothing().when(view).groupElementWithItsParent(groupedElementsList, allElements, element1);
    doNothing().when(view).groupElementWithItsParent(groupedElementsList, allElements, element2);
    final List<DataTypeListItem> actual = view.groupElementsWithItsParents(allElements);
    verify(view).groupElementWithItsParent(groupedElementsList, allElements, element1);
    verify(view).groupElementWithItsParent(groupedElementsList, allElements, element2);
    assertEquals(actual, groupedElementsList);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) Test(org.junit.Test)

Example 18 with DataTypeListItem

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

the class DataTypeSearchBarViewTest method testIsParentElementOnListWhenIsPresent.

@Test
public void testIsParentElementOnListWhenIsPresent() {
    final DataTypeListItem item = mock(DataTypeListItem.class);
    final HTMLElement element = mock(HTMLElement.class);
    final String id = "id";
    when(element.getAttribute(UUID_ATTR)).thenReturn(id);
    when(item.getDragAndDropElement()).thenReturn(element);
    final List<DataTypeListItem> groupedElements = Arrays.asList(item);
    boolean isPresent = view.isParentElementOnList(groupedElements, id);
    assertTrue(isPresent);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) Test(org.junit.Test)

Example 19 with DataTypeListItem

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

the class DataTypeSearchBarViewTest method testGetIndexOfParentOrLastElementInGroupWhenHaveMoreElements.

@Test
public void testGetIndexOfParentOrLastElementInGroupWhenHaveMoreElements() {
    final DataTypeListItem parent = mock(DataTypeListItem.class);
    final DataTypeListItem listItem1 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem2 = mock(DataTypeListItem.class);
    final HTMLElement parentElement = mock(HTMLElement.class);
    final HTMLElement listItemElement1 = mock(HTMLElement.class);
    final HTMLElement listItemElement2 = mock(HTMLElement.class);
    final String parentId = "parentId";
    final List<DataTypeListItem> groupedElements = new ArrayList<>();
    groupedElements.add(parent);
    groupedElements.add(listItem1);
    groupedElements.add(listItem2);
    final int expectedIndex = 2;
    when(parentElement.getAttribute(UUID_ATTR)).thenReturn(parentId);
    when(parent.getDragAndDropElement()).thenReturn(parentElement);
    when(listItem1.getDragAndDropElement()).thenReturn(listItemElement1);
    when(listItem2.getDragAndDropElement()).thenReturn(listItemElement2);
    when(listItemElement1.getAttribute(PARENT_UUID_ATTR)).thenReturn(parentId);
    when(listItemElement2.getAttribute(PARENT_UUID_ATTR)).thenReturn(parentId);
    final int index = view.getIndexOfParentOrLastElementInGroup(groupedElements, parent);
    assertEquals(expectedIndex, index);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 20 with DataTypeListItem

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

the class DataTypeSearchBarViewTest method testShowSearchResults.

@Test
public void testShowSearchResults() {
    final DNDListComponent dndListComponent = mock(DNDListComponent.class);
    final DataType dataType0 = mock(DataType.class);
    final DataType dataType1 = mock(DataType.class);
    final DataType dataType2 = mock(DataType.class);
    final DataTypeListItem listItem0 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem1 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem2 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem3 = mock(DataTypeListItem.class);
    final HTMLElement element0 = mock(HTMLElement.class);
    final HTMLElement element1 = mock(HTMLElement.class);
    final HTMLElement element2 = mock(HTMLElement.class);
    final HTMLElement element3 = mock(HTMLElement.class);
    final List<DataType> results = asList(dataType0, dataType1, dataType2);
    final List<DataTypeListItem> listItems = asList(listItem0, listItem1, listItem2, listItem3);
    element0.classList = mock(DOMTokenList.class);
    element1.classList = mock(DOMTokenList.class);
    element2.classList = mock(DOMTokenList.class);
    element3.classList = mock(DOMTokenList.class);
    when(listItem0.getDataType()).thenReturn(dataType0);
    when(listItem1.getDataType()).thenReturn(dataType1);
    when(listItem2.getDataType()).thenReturn(dataType2);
    when(listItem0.getDragAndDropElement()).thenReturn(element0);
    when(listItem1.getDragAndDropElement()).thenReturn(element1);
    when(listItem2.getDragAndDropElement()).thenReturn(element2);
    when(listItem3.getDragAndDropElement()).thenReturn(element3);
    when(presenter.getDataTypeListItemsSortedByPositionY()).thenReturn(listItems);
    when(presenter.getDNDListComponent()).thenReturn(dndListComponent);
    doNothing().when(view).enableSearch();
    view.showSearchResults(results);
    verify(element0.classList).remove(HIDDEN_CSS_CLASS);
    verify(element1.classList).remove(HIDDEN_CSS_CLASS);
    verify(element2.classList).remove(HIDDEN_CSS_CLASS);
    verify(element3.classList).add(HIDDEN_CSS_CLASS);
    verify(dndListComponent).setPositionY(element0, 0);
    verify(dndListComponent).setPositionY(element1, 1);
    verify(dndListComponent).setPositionY(element2, 2);
    verify(dndListComponent).setPositionY(element3, -1);
    verify(dndListComponent).refreshItemsPosition();
    verify(dndListComponent).refreshDragAreaSize();
    verify(listItem0).expand();
    verify(listItem1).expand();
    verify(listItem2).expand();
    verify(view).enableSearch();
    verify(view).groupElementsWithItsParents(listItems);
    verify(view).expandListItems(listItems);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) DOMTokenList(elemental2.dom.DOMTokenList) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) DNDListComponent(org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListComponent) Test(org.junit.Test)

Aggregations

DataTypeListItem (org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem)30 Test (org.junit.Test)27 HTMLElement (elemental2.dom.HTMLElement)22 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)15 ArrayList (java.util.ArrayList)5 DNDListComponent (org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListComponent)4 DataTypeList (org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeList)3 DOMTokenList (elemental2.dom.DOMTokenList)2 Element (elemental2.dom.Element)2 HashMap (java.util.HashMap)2 ConstraintType (org.kie.workbench.common.dmn.api.definition.model.ConstraintType)2 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiConsumer (java.util.function.BiConsumer)1 ManagedInstance (org.jboss.errai.ioc.client.api.ManagedInstance)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertSame (org.junit.Assert.assertSame)1