Search in sources :

Example 26 with DataTypeListItem

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

the class DNDDataTypesHandlerTest method testDeleteKeepingReferences.

@Test
public void testDeleteKeepingReferences() {
    final DataType existing = mock(DataType.class);
    final DataTypeListItem dtListItem = mock(DataTypeListItem.class);
    final Optional<DataTypeListItem> item = Optional.of(dtListItem);
    when(dataTypeList.findItem(existing)).thenReturn(item);
    handler.deleteKeepingReferences(existing);
    verify(dtListItem).destroyWithoutDependentTypes();
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 27 with DataTypeListItem

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

the class DNDDataTypesHandlerTest method testDeleteKeepingReferencesItemNotPresent.

@Test
public void testDeleteKeepingReferencesItemNotPresent() {
    final DataType existing = mock(DataType.class);
    final DataTypeListItem dtListItem = mock(DataTypeListItem.class);
    final Optional<DataTypeListItem> item = Optional.empty();
    when(dataTypeList.findItem(existing)).thenReturn(item);
    handler.deleteKeepingReferences(existing);
    verify(dtListItem, never()).destroyWithoutDependentTypes();
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 28 with DataTypeListItem

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

the class DNDDataTypesHandlerTest method testShiftCurrentByReferenceWhenCurrentIsNotCollapsedAndItIsNotTopLevelShiftOperation.

@Test
public void testShiftCurrentByReferenceWhenCurrentIsNotCollapsedAndItIsNotTopLevelShiftOperation() {
    final DataType current = mock(DataType.class);
    final DataType clone = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType cloneParent1 = mock(DataType.class);
    final DataType cloneParent2 = mock(DataType.class);
    final DNDDataTypesHandlerShiftStrategy strategy = INSERT_INTO_HOVERED_DATA_TYPE;
    final String referenceHash = "referenceHash";
    final String cloneHash = "cloneHash";
    final DataTypeListItem oldItem = mock(DataTypeListItem.class);
    final DataTypeListItem referenceItem = mock(DataTypeListItem.class);
    final DataTypeListItem cloneItem = mock(DataTypeListItem.class);
    final HTMLElement cloneHTMLElement = mock(HTMLElement.class);
    final String cloneParent1UUID = "cloneParent1UUID";
    final String cloneParent2UUID = "cloneParent2UUID";
    final DataTypeListItem cloneParent1Item = mock(DataTypeListItem.class);
    final DataTypeListItem cloneParent2Item = mock(DataTypeListItem.class);
    doReturn(clone).when(handler).cloneDataType(current);
    doReturn(false).when(handler).isTopLevelShiftOperation(current, strategy);
    when(dataTypeList.calculateHash(reference)).thenReturn(referenceHash);
    when(dataTypeList.calculateHash(clone)).thenReturn(cloneHash);
    when(dataTypeList.findItem(current)).thenReturn(Optional.of(oldItem));
    when(dataTypeList.findItemByDataTypeHash(referenceHash)).thenReturn(Optional.of(referenceItem));
    when(dataTypeList.findItemByDataTypeHash(cloneHash)).thenReturn(Optional.of(cloneItem));
    when(cloneItem.getDragAndDropElement()).thenReturn(cloneHTMLElement);
    when(oldItem.isCollapsed()).thenReturn(false);
    when(cloneItem.getDataType()).thenReturn(clone);
    when(clone.getParentUUID()).thenReturn(cloneParent1UUID);
    when(cloneParent1.getParentUUID()).thenReturn(cloneParent2UUID);
    when(cloneParent1.getUUID()).thenReturn(cloneParent1UUID);
    when(cloneParent2.getUUID()).thenReturn(cloneParent2UUID);
    when(dataTypeStore.get(cloneParent1UUID)).thenReturn(cloneParent1);
    when(dataTypeStore.get(cloneParent2UUID)).thenReturn(cloneParent2);
    when(dataTypeList.findItem(cloneParent1)).thenReturn(Optional.of(cloneParent1Item));
    when(dataTypeList.findItem(cloneParent2)).thenReturn(Optional.of(cloneParent2Item));
    handler.shiftCurrentByReference(current, reference, strategy);
    verify(cloneItem).expand();
    verify(oldItem).destroyWithDependentTypes();
    verify(referenceItem).insertNestedField(clone);
    verify(dataTypeList).highlightLevel(cloneHTMLElement);
    verify(cloneParent1Item).expand();
    verify(cloneParent2Item).expand();
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 29 with DataTypeListItem

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

the class StructureTypesTooltipTest method testGoToDataType.

@Test
public void testGoToDataType() {
    final String typeName = "tPerson";
    final HTMLElement refElement = mock(HTMLElement.class);
    final DataType dataType = mock(DataType.class);
    final Optional<DataType> optDataType = Optional.of(dataType);
    final DataTypeListItem dataTypeListItem = mock(DataTypeListItem.class);
    final Optional<DataTypeListItem> optDataTypeListItem = Optional.of(dataTypeListItem);
    when(dataTypeManager.getTopLevelDataTypeWithName(typeName)).thenReturn(optDataType);
    when(dataTypeList.findItem(dataType)).thenReturn(optDataTypeListItem);
    presenter.show(refElement, typeName);
    presenter.goToDataType();
    verify(dataTypeListItem).enableShortcutsHighlight();
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 30 with DataTypeListItem

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

the class DMNDataTypesSubIndexTest method testGetSearchableElements.

@Test
public void testGetSearchableElements() {
    final DataTypeListItem listItem1 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem2 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem3 = mock(DataTypeListItem.class);
    final DataType dataType1 = mock(DataType.class);
    final DataType dataType2 = mock(DataType.class);
    final DataType dataType3 = mock(DataType.class);
    final String dataTypeName1 = "data type 1";
    final String dataTypeName2 = "data type 2";
    final String dataTypeName3 = "data type 3";
    final HTMLElement htmlElement1 = mock(HTMLElement.class);
    final HTMLElement htmlElement2 = mock(HTMLElement.class);
    final HTMLElement htmlElement3 = mock(HTMLElement.class);
    final List<DataTypeListItem> dataTypeListItems = asList(listItem1, listItem2, listItem3);
    when(listItem1.getDragAndDropElement()).thenReturn(htmlElement1);
    when(listItem2.getDragAndDropElement()).thenReturn(htmlElement2);
    when(listItem3.getDragAndDropElement()).thenReturn(htmlElement3);
    when(listItem1.getDataType()).thenReturn(dataType1);
    when(listItem2.getDataType()).thenReturn(dataType2);
    when(listItem3.getDataType()).thenReturn(dataType3);
    when(dataType1.getName()).thenReturn(dataTypeName1);
    when(dataType2.getName()).thenReturn(dataTypeName2);
    when(dataType3.getName()).thenReturn(dataTypeName3);
    when(dataTypeList.getItems()).thenReturn(dataTypeListItems);
    final List<DMNSearchableElement> elements = index.getSearchableElements();
    final DMNSearchableElement element1 = elements.get(0);
    final DMNSearchableElement element2 = elements.get(1);
    final DMNSearchableElement element3 = elements.get(2);
    elements.forEach(e -> e.onFound().execute());
    assertEquals(3, elements.size());
    assertEquals(dataTypeName1, element1.getText());
    assertEquals(dataTypeName2, element2.getText());
    assertEquals(dataTypeName3, element3.getText());
    verify(index).highlight(listItem1);
    verify(index).highlight(listItem2);
    verify(index).highlight(listItem3);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) 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