Search in sources :

Example 21 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 testRestoreDataTypeListPositionsWhenSearchBarHasDataTypeListPositionsStored.

@Test
public void testRestoreDataTypeListPositionsWhenSearchBarHasDataTypeListPositionsStored() {
    final DataType dataType0 = mock(DataType.class);
    final DataType dataType1 = mock(DataType.class);
    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 List<DataTypeListItem> items = asList(list0, list1);
    final String uuid0 = "0000-0000-0000-0000";
    final String uuid1 = "1111-1111-1111-1111";
    final Integer positionY0 = 2;
    final Integer positionY1 = -1;
    final Map<String, Integer> store = spy(new Maps.Builder<String, Integer>().put(uuid0, positionY0).put(uuid1, positionY1).build());
    final Map<String, Boolean> collapsedStore = spy(new Maps.Builder<String, Boolean>().put(uuid0, false).put(uuid1, true).build());
    element0.classList = mock(DOMTokenList.class);
    element1.classList = mock(DOMTokenList.class);
    when(dndListComponent.getPositionY(element0)).thenReturn(positionY0);
    when(dndListComponent.getPositionY(element1)).thenReturn(positionY1);
    when(list0.getDragAndDropElement()).thenReturn(element0);
    when(list1.getDragAndDropElement()).thenReturn(element1);
    when(list0.getDataType()).thenReturn(dataType0);
    when(list1.getDataType()).thenReturn(dataType1);
    when(dataType0.getUUID()).thenReturn(uuid0);
    when(dataType1.getUUID()).thenReturn(uuid1);
    when(dataTypeList.getItems()).thenReturn(items);
    when(dataTypeList.getDNDListComponent()).thenReturn(dndListComponent);
    doReturn(store).when(searchBar).getDataTypeListPositionsStore();
    doReturn(collapsedStore).when(searchBar).getDataTypeListCollapsedStatusStore();
    searchBar.restoreDataTypeListPositions();
    verify(dndListComponent).setPositionY(element0, positionY0);
    verify(dndListComponent).setPositionY(element1, positionY1);
    verify(element0.classList).remove(HIDDEN_CSS_CLASS);
    verify(element1.classList).add(HIDDEN_CSS_CLASS);
    verify(dndListComponent).refreshItemsPosition();
    verify(list0, never()).collapse();
    verify(list1).collapse();
    verify(store).clear();
    verify(collapsedStore).clear();
}
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)

Example 22 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 testStoreDataTypeListPositionsWhenSearchBarDoesNotHaveDataTypeListPositionsStored.

@Test
public void testStoreDataTypeListPositionsWhenSearchBarDoesNotHaveDataTypeListPositionsStored() {
    final DataType dataType0 = mock(DataType.class);
    final DataType dataType1 = mock(DataType.class);
    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 List<DataTypeListItem> items = asList(list0, list1);
    final String uuid0 = "0000-0000-0000-0000";
    final String uuid1 = "1111-1111-1111-1111";
    final Integer positionY0 = 2;
    final Integer positionY1 = 4;
    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(list0.getDataType()).thenReturn(dataType0);
    when(list1.getDataType()).thenReturn(dataType1);
    when(dataType0.getUUID()).thenReturn(uuid0);
    when(dataType1.getUUID()).thenReturn(uuid1);
    when(dataTypeList.getItems()).thenReturn(items);
    when(dataTypeList.getDNDListComponent()).thenReturn(dndListComponent);
    doReturn(store).when(searchBar).getDataTypeListPositionsStore();
    searchBar.storeDataTypeListPositions();
    assertEquals(2, store.size());
    assertEquals(positionY0, store.get(uuid0));
    assertEquals(positionY1, store.get(uuid1));
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) HashMap(java.util.HashMap) 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)

Example 23 with DataTypeListItem

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

the class DataTypeListShortcutsViewTest method testGetVisibleDataTypeListItems.

@Test
public void testGetVisibleDataTypeListItems() {
    final DataTypeList dataTypeList = mock(DataTypeList.class);
    final DataTypeListItem item1 = mock(DataTypeListItem.class);
    final DataTypeListItem item2 = mock(DataTypeListItem.class);
    final DataTypeListItem item3 = mock(DataTypeListItem.class);
    final DataType dataType1 = fakeDataType("123");
    final DataType dataType2 = fakeDataType("456");
    final DataType dataType3 = fakeDataType("789");
    final Element dataTypeRow1 = fakeDataTypeRow("123");
    final Element dataTypeRow2 = fakeDataTypeRow("456");
    final Element dataTypeRow3 = fakeDataTypeRow("789");
    final List<DataTypeListItem> items = asList(item1, item2, item3);
    final JQueryList<Element> jQueryList = mock(JQueryList.class);
    when(item1.getDataType()).thenReturn(dataType1);
    when(item2.getDataType()).thenReturn(dataType2);
    when(item3.getDataType()).thenReturn(dataType3);
    when(dataTypeList.getItems()).thenReturn(items);
    when(presenter.getDataTypeList()).thenReturn(dataTypeList);
    jQueryList.length = 3;
    when(jQueryList.get(0)).thenReturn(dataTypeRow1);
    when(jQueryList.get(1)).thenReturn(dataTypeRow2);
    when(jQueryList.get(2)).thenReturn(dataTypeRow3);
    doReturn(jQueryList).when(view).filterVisible();
    final List<DataTypeListItem> actual = view.getVisibleDataTypeListItems();
    final List<DataTypeListItem> expected = asList(item1, item2, item3);
    assertEquals(expected, actual);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) DataTypeList(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeList) Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 24 with DataTypeListItem

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

the class DataTypeListShortcutsViewTest method testFocusInWhenCurrentUUIDIsBlank.

@Test
public void testFocusInWhenCurrentUUIDIsBlank() {
    final DataTypeListItem listItem = mock(DataTypeListItem.class);
    final HTMLElement element = mock(HTMLElement.class);
    when(listItem.getDragAndDropElement()).thenReturn(element);
    doReturn("").when(view).getCurrentUUID();
    doReturn("uuid").when(view).getPreviousUUID();
    doReturn(Optional.of(listItem)).when(view).getDataTypeListItem("uuid");
    doNothing().when(view).highlight(any());
    view.focusIn();
    verify(view).highlight(element);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) Test(org.junit.Test)

Example 25 with DataTypeListItem

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

the class DataTypeListShortcutsViewTest method testGetCurrentDataTypeListItem.

@Test
public void testGetCurrentDataTypeListItem() {
    final DataTypeList dataTypeList = mock(DataTypeList.class);
    final DataTypeListItem item = mock(DataTypeListItem.class);
    final DataType dataType = fakeDataType("123");
    final Element dataTypeRow1 = fakeDataTypeRow("123");
    final Element dataTypeRow2 = fakeDataTypeRow("456");
    final Element dataTypeRow3 = fakeDataTypeRow("789");
    final JQueryList<Element> jQueryList = mock(JQueryList.class);
    final List<DataTypeListItem> items = singletonList(item);
    when(item.getDataType()).thenReturn(dataType);
    when(dataTypeList.getItems()).thenReturn(items);
    when(presenter.getDataTypeList()).thenReturn(dataTypeList);
    jQueryList.length = 3;
    when(jQueryList.get(0)).thenReturn(dataTypeRow1);
    when(jQueryList.get(1)).thenReturn(dataTypeRow2);
    when(jQueryList.get(2)).thenReturn(dataTypeRow3);
    doReturn(jQueryList).when(view).filterVisible();
    doReturn("123").when(view).getCurrentUUID();
    final DataTypeListItem actual = view.getCurrentDataTypeListItem().orElseThrow(RuntimeException::new);
    assertEquals(item, actual);
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) DataTypeList(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeList) Element(elemental2.dom.Element) 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