Search in sources :

Example 11 with FlashMessage

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

the class DataTypeNameValidatorTest method testIsValidWhenDataTypeNameIsDefault.

@Test
public void testIsValidWhenDataTypeNameIsDefault() {
    final DataType dataType = mock(DataType.class);
    final FlashMessage nameIsDefaultMessage = mock(FlashMessage.class);
    doReturn(false).when(validator).isBlank(dataType);
    doReturn(false).when(validator).isNotUnique(dataType);
    doReturn(true).when(validator).isDefault(dataType);
    when(nameIsDefaultTypeMessage.getFlashMessage(dataType)).thenReturn(nameIsDefaultMessage);
    final boolean isValid = validator.isValid(dataType);
    verify(flashMessageEvent).fire(nameIsDefaultMessage);
    assertFalse(isValid);
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) Test(org.junit.Test)

Example 12 with FlashMessage

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

the class DataTypeConfirmationTest method testIfDataTypeDoesNotHaveLostSubDataTypesWhenItemDefinitionItemComponentIsNotEmpty.

@Test
public void testIfDataTypeDoesNotHaveLostSubDataTypesWhenItemDefinitionItemComponentIsNotEmpty() {
    final DataType dataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final List<ItemDefinition> itemComponent = singletonList(mock(ItemDefinition.class));
    final Command onSuccess = mock(Command.class);
    final Command onError = mock(Command.class);
    final FlashMessage warningMessage = mock(FlashMessage.class);
    final String uuid = "uuid";
    when(dataType.getUUID()).thenReturn(uuid);
    when(dataType.getType()).thenReturn("tCity");
    when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition);
    when(itemDefinition.getItemComponent()).thenReturn(itemComponent);
    when(dataTypeHasFieldsWarningMessage.getFlashMessage(dataType, onSuccess, onError)).thenReturn(warningMessage);
    confirmation.ifDataTypeDoesNotHaveLostSubDataTypes(dataType, onSuccess, onError);
    verify(onSuccess, never()).execute();
    verify(flashMessageEvent).fire(warningMessage);
}
Also used : Command(org.uberfire.mvp.Command) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) Test(org.junit.Test)

Example 13 with FlashMessage

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

the class DataTypeNameValidatorTest method testIsValidWhenDataTypeNameIsNotUnique.

@Test
public void testIsValidWhenDataTypeNameIsNotUnique() {
    final DataType dataType = mock(DataType.class);
    final FlashMessage notUniqueMessage = mock(FlashMessage.class);
    doReturn(false).when(validator).isBlank(dataType);
    doReturn(true).when(validator).isNotUnique(dataType);
    when(notUniqueErrorMessage.getFlashMessage(dataType)).thenReturn(notUniqueMessage);
    final boolean isValid = validator.isValid(dataType);
    verify(flashMessageEvent).fire(notUniqueMessage);
    assertFalse(isValid);
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) Test(org.junit.Test)

Example 14 with FlashMessage

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

the class ErrorMessageTest method testGetFlashMessage.

@Test
public void testGetFlashMessage() {
    final String uuid = "uuid";
    final FlashMessage.Type expectedType = ERROR;
    final String expectedStrongMessage = "expectedStrongMessage";
    final String expectedRegularMessage = "expectedRegularMessage";
    final String expectedErrorElementSelector = "[data-row-uuid=\"uuid\"] [data-type-field=\"name-input\"]";
    final DataType dataType = mock(DataType.class);
    final ErrorMessage errorMessage = new ErrorMessage(translationService) {

        @Override
        String getStrongMessage(final DataType dataType) {
            return expectedStrongMessage;
        }

        @Override
        String getRegularMessage() {
            return expectedRegularMessage;
        }
    };
    when(dataType.getUUID()).thenReturn(uuid);
    final FlashMessage flashMessage = errorMessage.getFlashMessage(dataType);
    final FlashMessage.Type actualType = flashMessage.getType();
    final String actualStrongMessage = flashMessage.getStrongMessage();
    final String actualRegularMessage = flashMessage.getRegularMessage();
    final String actualErrorElementSelector = flashMessage.getElementSelector();
    assertEquals(expectedType, actualType);
    assertEquals(expectedStrongMessage, actualStrongMessage);
    assertEquals(expectedRegularMessage, actualRegularMessage);
    assertEquals(expectedErrorElementSelector, actualErrorElementSelector);
}
Also used : FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 15 with FlashMessage

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

the class IncludedModelErrorMessageFactoryTest method testGetNameIsNotUniqueFlashMessage.

@Test
public void testGetNameIsNotUniqueFlashMessage() {
    final BaseIncludedModelActiveRecord includedModel = mock(BaseIncludedModelActiveRecord.class);
    final Type expectedType = ERROR;
    final String expectedStrongMessage = "StrongMessage";
    final String expectedRegularMessage = "RegularMessage";
    final String expectedElementSelector = "[data-card-uuid=\"1234\"] [data-field=\"title-input\"]";
    when(includedModel.getUUID()).thenReturn("1234");
    when(includedModel.getName()).thenReturn("file");
    when(translationService.format(IncludedModelNameIsNotUniqueErrorMessage_StrongMessage, "file")).thenReturn(expectedStrongMessage);
    when(translationService.format(IncludedModelNameIsNotUniqueErrorMessage_RegularMessage)).thenReturn(expectedRegularMessage);
    final FlashMessage flashMessage = factory.getNameIsNotUniqueFlashMessage(includedModel);
    assertEquals(expectedType, flashMessage.getType());
    assertEquals(expectedStrongMessage, flashMessage.getStrongMessage());
    assertEquals(expectedRegularMessage, flashMessage.getRegularMessage());
    assertEquals(expectedElementSelector, flashMessage.getElementSelector());
}
Also used : Type(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage.Type) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 FlashMessage (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage)16 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)9 BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)6 Command (org.uberfire.mvp.Command)5 ArrayList (java.util.ArrayList)4 Import (org.kie.workbench.common.dmn.api.definition.model.Import)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 Type (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage.Type)2 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)1