Search in sources :

Example 61 with DataType

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

the class DataTypeListItemTest method testEnableEditMode.

@Test
public void testEnableEditMode() {
    final DataType dataType = mock(DataType.class);
    final String expectedName = "name";
    final String expectedType = "type";
    final String expectedConstraint = "constraint";
    final boolean expectedIsList = true;
    final String expectedConstraintType = "";
    doReturn(dataType).when(listItem).getDataType();
    when(dataType.getName()).thenReturn(expectedName);
    when(dataType.getType()).thenReturn(expectedType);
    when(dataType.getConstraint()).thenReturn(expectedConstraint);
    when(dataType.isList()).thenReturn(expectedIsList);
    when(view.isOnFocusMode()).thenReturn(false);
    listItem.enableEditMode();
    assertEquals(expectedName, listItem.getOldName());
    assertEquals(expectedType, listItem.getOldType());
    assertEquals(expectedConstraint, listItem.getOldConstraint());
    assertEquals(expectedIsList, listItem.getOldIsList());
    assertEquals(expectedConstraintType, listItem.getOldConstraintType());
    verify(view).showSaveButton();
    verify(view).showDataTypeNameInput();
    verify(view).enableFocusMode();
    verify(view).hideListYesLabel();
    verify(view).showListContainer();
    verify(dataTypeSelectComponent).enableEditMode();
    verify(dataTypeConstraintComponent).enableEditMode();
    verify(editModeToggleEvent).fire(eventArgumentCaptor.capture());
    verify(dataTypeList).fireOnDataTypeListItemUpdateCallback(listItem);
    assertTrue(eventArgumentCaptor.getValue().isEditModeEnabled());
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 62 with DataType

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

the class DataTypeListItemTest method testInsertNewFieldIfDataTypeIsStructureWhenDataTypeIsStructureButHasFields.

@Test
public void testInsertNewFieldIfDataTypeIsStructureWhenDataTypeIsStructureButHasFields() {
    final DataTypeListItem newListItem = mock(DataTypeListItem.class);
    final DataType dataType = mock(DataType.class);
    final String hash = "hash";
    when(newListItem.getDataType()).thenReturn(dataType);
    when(dataType.hasSubDataTypes()).thenReturn(true);
    when(newListItem.isStructureType()).thenReturn(true);
    when(dataTypeList.findItemByDataTypeHash(hash)).thenReturn(Optional.of(newListItem));
    listItem.insertNewFieldIfDataTypeIsStructure(hash);
    verify(dataTypeList, never()).insertNestedField(Mockito.<String>any());
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 63 with DataType

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

the class DataTypeListItemTest method testSetupDataType.

@Test
public void testSetupDataType() {
    final DataType expectedDataType = this.dataType;
    final int expectedLevel = 1;
    doNothing().when(listItem).setupDragAndDropComponent();
    doNothing().when(listItem).setupView();
    listItem.setupDataType(expectedDataType, expectedLevel);
    final InOrder inOrder = inOrder(listItem);
    inOrder.verify(listItem).setupDragAndDropComponent();
    inOrder.verify(listItem).setupSelectComponent();
    inOrder.verify(listItem).setupListComponent();
    inOrder.verify(listItem).setupConstraintComponent();
    inOrder.verify(listItem).setupView();
    assertEquals(expectedDataType, listItem.getDataType());
    assertEquals(expectedLevel, listItem.getLevel());
}
Also used : InOrder(org.mockito.InOrder) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) DataTypeConstraint(org.kie.workbench.common.dmn.client.editors.types.listview.constraint.DataTypeConstraint) Test(org.junit.Test)

Example 64 with DataType

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

the class DataTypeListItemTest method testSaveAndCloseEditModeWhenDataTypeIsValid.

@Test
public void testSaveAndCloseEditModeWhenDataTypeIsValid() {
    final DataType dataType = spy(makeDataType());
    final DataType updatedDataType = spy(makeDataType());
    final Command doSaveAndCloseCommand = mock(Command.class);
    final Command doDisableEditMode = mock(Command.class);
    doReturn(dataType).when(listItem).getDataType();
    doReturn(updatedDataType).when(listItem).updateProperties(dataType);
    doReturn(true).when(updatedDataType).isValid();
    doReturn(doSaveAndCloseCommand).when(listItem).doValidateDataTypeNameAndSave(updatedDataType);
    doReturn(doDisableEditMode).when(listItem).doDisableEditMode();
    listItem.saveAndCloseEditMode();
    verify(confirmation).ifDataTypeDoesNotHaveLostSubDataTypes(updatedDataType, doSaveAndCloseCommand, doDisableEditMode);
}
Also used : Command(org.uberfire.mvp.Command) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 65 with DataType

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

the class DataTypeListItemTest method testRefresh.

@Test
public void testRefresh() {
    final DataType dataType = spy(makeDataType());
    final String expectedConstraint = "constraint";
    final String expectedName = "name";
    doReturn(expectedConstraint).when(dataType).getConstraint();
    doReturn(expectedName).when(dataType).getName();
    doReturn(dataType).when(listItem).getDataType();
    doNothing().when(listItem).hideTooltips();
    listItem.refresh();
    verify(dataTypeSelectComponent).refresh();
    verify(dataTypeSelectComponent).init(listItem, dataType);
    verify(dataTypeConstraintComponent).refreshView();
    verify(view).setName(expectedName);
    verify(listItem).setupListComponent();
    verify(listItem).setupConstraintComponent();
    verify(listItem).hideTooltips();
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Aggregations

DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)274 Test (org.junit.Test)245 HTMLElement (elemental2.dom.HTMLElement)44 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)39 Element (elemental2.dom.Element)30 ArrayList (java.util.ArrayList)26 DOMTokenList (elemental2.dom.DOMTokenList)24 DataTypeListItem (org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem)14 HTMLDivElement (elemental2.dom.HTMLDivElement)13 HTMLButtonElement (elemental2.dom.HTMLButtonElement)12 Command (org.uberfire.mvp.Command)12 FlashMessage (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage)9 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)9 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)8 DNDListComponent (org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListComponent)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)6 HTMLInputElement (elemental2.dom.HTMLInputElement)6 DataObject (org.kie.workbench.common.dmn.api.editors.types.DataObject)6