Search in sources :

Example 6 with DataTypeListItem

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

the class DataTypeListShortcutsTest method testOnEscapeWhenCurrentDataTypeListItemIsNotPresent.

@Test
public void testOnEscapeWhenCurrentDataTypeListItemIsNotPresent() {
    final DataTypeListItem listItem1 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem2 = mock(DataTypeListItem.class);
    final List<DataTypeListItem> items = asList(listItem1, listItem2);
    when(view.getCurrentDataTypeListItem()).thenReturn(Optional.empty());
    when(view.getVisibleDataTypeListItems()).thenReturn(items);
    shortcuts.onEscape();
    verify(listItem1).disableEditMode();
    verify(listItem2).disableEditMode();
    verify(shortcuts, never()).highlight(any());
    verify(shortcuts).reset();
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) Test(org.junit.Test)

Example 7 with DataTypeListItem

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

the class DataTypeListShortcutsTest method testInit.

@Test
public void testInit() {
    // The 'init' method is being called during the setup.
    final DataTypeListItem listItem = mock(DataTypeListItem.class);
    final HTMLElement htmlElement = mock(HTMLElement.class);
    final DataTypeList actualDataTypeList = shortcuts.getDataTypeList();
    final DataTypeList expectedDataTypeList = shortcuts.getDataTypeList();
    when(listItem.getDragAndDropElement()).thenReturn(htmlElement);
    assertEquals(expectedDataTypeList, actualDataTypeList);
    verify(expectedDataTypeList).registerDataTypeListItemUpdateCallback(onDataTypeListItemUpdateArgumentCaptor.capture());
    onDataTypeListItemUpdateArgumentCaptor.getValue().accept(listItem);
    verify(view).highlight(htmlElement);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) DataTypeList(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeList) HTMLElement(elemental2.dom.HTMLElement) Test(org.junit.Test)

Example 8 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 testGroupElementWithItsParentWhenParentIsAtTheEndOfList.

@Test
public void testGroupElementWithItsParentWhenParentIsAtTheEndOfList() {
    final DataTypeListItem item = mock(DataTypeListItem.class);
    final DataTypeListItem parent = mock(DataTypeListItem.class);
    final List<DataTypeListItem> groupedElements = new ArrayList<>();
    groupedElements.add(parent);
    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(2, groupedElements.size());
    assertEquals(parent, groupedElements.get(0));
    assertEquals(item, groupedElements.get(1));
    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 9 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 testGroupElementWithItsParentWhenParentIsNotOnList.

@Test
public void testGroupElementWithItsParentWhenParentIsNotOnList() {
    final DataTypeListItem item = mock(DataTypeListItem.class);
    final DataTypeListItem parent = mock(DataTypeListItem.class);
    final List<DataTypeListItem> groupedElements = new ArrayList<>();
    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(false).when(view).isParentElementOnList(groupedElements, parentUuid);
    doNothing().when(view).groupElementWithItsParent(groupedElements, allElements, parent);
    view.groupElementWithItsParent(groupedElements, allElements, item);
    assertEquals(1, groupedElements.size());
    assertEquals(item, groupedElements.get(0));
    verify(view).groupElementWithItsParent(groupedElements, allElements, parent);
    verify(view, never()).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 10 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 testGetIndexOfParentOrLastElementInGroup.

@Test
public void testGetIndexOfParentOrLastElementInGroup() {
    final DataTypeListItem parent = mock(DataTypeListItem.class);
    final HTMLElement parentElement = mock(HTMLElement.class);
    final String parentId = "parentId";
    final List<DataTypeListItem> groupedElements = new ArrayList<>();
    groupedElements.add(parent);
    final int expectedIndex = 0;
    when(parentElement.getAttribute(UUID_ATTR)).thenReturn(parentId);
    when(parent.getDragAndDropElement()).thenReturn(parentElement);
    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)

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