Search in sources :

Example 11 with DataTypeListItem

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

the class DNDDataTypesHandler method shiftCurrentByReference.

void shiftCurrentByReference(final DataType current, final DataType reference, final DNDDataTypesHandlerShiftStrategy shiftStrategy) {
    final String referenceHash = getDataTypeList().calculateHash(reference);
    final DataType clone = cloneDataType(current);
    final Optional<DataTypeListItem> currentItem = getDataTypeList().findItem(current);
    final boolean isCurrentItemCollapsed = currentItem.map(DataTypeListItem::isCollapsed).orElse(false);
    // destroy current data type
    currentItem.ifPresent(item -> {
        if (isTopLevelShiftOperation(current, shiftStrategy)) {
            item.destroyWithoutDependentTypes();
        } else {
            item.destroyWithDependentTypes();
        }
    });
    // create new data type by using shift strategy
    getDataTypeList().findItemByDataTypeHash(referenceHash).ifPresent(ref -> {
        shiftStrategy.getConsumer().accept(ref, clone);
    });
    // keep the state of the new data type item consistent
    dataTypeList.findItemByDataTypeHash(getDataTypeList().calculateHash(clone)).ifPresent(item -> {
        if (isCurrentItemCollapsed) {
            item.collapse();
        } else {
            item.expand();
        }
        expandParents(item.getDataType());
        highlightLevel(item.getDragAndDropElement());
    });
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType)

Example 12 with DataTypeListItem

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

the class DataTypeConstraintTest method testOpenModal.

@Test
public void testOpenModal() {
    final DataTypeListItem listItem = mock(DataTypeListItem.class);
    final String constraint = "1,2,3";
    final String type = "string";
    final BiConsumer<String, ConstraintType> onShowConsumer = (s, c) -> {
    /* Nothing. */
    };
    doReturn(listItem).when(dataTypeConstraint).getListItem();
    doReturn(constraint).when(dataTypeConstraint).getValue();
    doReturn(onShowConsumer).when(dataTypeConstraint).getOnShowConsumer();
    when(listItem.getType()).thenReturn(type);
    dataTypeConstraint.openModal();
    constraintModal.load(type, constraint, ENUMERATION);
    constraintModal.show(onShowConsumer);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ENUMERATION(org.kie.workbench.common.dmn.api.definition.model.ConstraintType.ENUMERATION) Mock(org.mockito.Mock) Assert.assertNotNull(org.junit.Assert.assertNotNull) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.spy(org.mockito.Mockito.spy) DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) Mockito.verify(org.mockito.Mockito.verify) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertNull(org.junit.Assert.assertNull) HTMLElement(elemental2.dom.HTMLElement) Assert.assertFalse(org.junit.Assert.assertFalse) BiConsumer(java.util.function.BiConsumer) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Test(org.junit.Test)

Example 13 with DataTypeListItem

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

the class DataTypeSearchBarTest method testGetDataTypeListItemsSortedByPositionY.

@Test
public void testGetDataTypeListItemsSortedByPositionY() {
    final DataTypeListItem list0 = mock(DataTypeListItem.class);
    final DataTypeListItem list1 = mock(DataTypeListItem.class);
    final HTMLElement element0 = mock(HTMLElement.class);
    final HTMLElement element1 = mock(HTMLElement.class);
    final DNDListComponent dndListComponent = mock(DNDListComponent.class);
    final Integer positionY0 = 3;
    final Integer positionY1 = 2;
    final Map<String, Integer> store = new HashMap<>();
    when(dndListComponent.getPositionY(element0)).thenReturn(positionY0);
    when(dndListComponent.getPositionY(element1)).thenReturn(positionY1);
    when(list0.getDragAndDropElement()).thenReturn(element0);
    when(list1.getDragAndDropElement()).thenReturn(element1);
    when(dataTypeList.getItems()).thenReturn(asList(list0, list1));
    when(dataTypeList.getDNDListComponent()).thenReturn(dndListComponent);
    doReturn(store).when(searchBar).getDataTypeListPositionsStore();
    final List<DataTypeListItem> actualListItems = searchBar.getDataTypeListItemsSortedByPositionY();
    final List<DataTypeListItem> expectedListItems = asList(list1, list0);
    assertEquals(expectedListItems, actualListItems);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) HashMap(java.util.HashMap) DNDListComponent(org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListComponent) Test(org.junit.Test)

Example 14 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 testIsParentElementOnListWhenIsNotPresent.

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

Example 15 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 testExpandListItems.

@Test
public void testExpandListItems() {
    final DataTypeListItem item1 = mock(DataTypeListItem.class);
    final DataTypeListItem item2 = mock(DataTypeListItem.class);
    final List<DataTypeListItem> list = asList(item1, item2);
    view.expandListItems(list);
    verify(item1).expand();
    verify(item2).expand();
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) 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