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