Search in sources :

Example 46 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormEditorHelperTest method testSwitchToField.

protected void testSwitchToField(FieldDefinition originalField, FieldDefinition expectedField) {
    FieldDefinition result = formEditorHelper.switchToField(originalField, expectedField.getBinding());
    Assertions.assertThat(result).isNotNull().isEqualToComparingOnlyGivenFields(expectedField, "name", "binding", "standaloneClassName");
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition)

Example 47 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormEditorHelperTest method testSwitchToFieldType.

@Test
public void testSwitchToFieldType() {
    content.getDefinition().getFields().addAll(employeeFields);
    formEditorHelper.getAvailableFields().clear();
    FieldDefinition fieldDefinition = formEditorHelper.switchToFieldType(nameField, TextAreaFieldDefinition.FIELD_TYPE.getTypeName());
    assertEquals(TextAreaFieldDefinition.class, fieldDefinition.getClass());
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) Test(org.junit.Test)

Example 48 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormEditorHelperTest method testSwitchToDynamicBinding.

@Test
public void testSwitchToDynamicBinding() {
    FieldDefinition result = formEditorHelper.switchToField(nameField, DYNAMIC_BINDING);
    Assertions.assertThat(result.getId()).isNotEqualTo(nameField.getId());
    Assertions.assertThat(result.getName()).isEqualTo(DYNAMIC_BINDING);
    Assertions.assertThat(result.getBinding()).isEqualTo(DYNAMIC_BINDING);
    Assertions.assertThat(result.getStandaloneClassName()).isEqualTo(nameField.getStandaloneClassName());
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) Test(org.junit.Test)

Example 49 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormEditorHelperTest method testGetFormFieldAvailable.

@Test
public void testGetFormFieldAvailable() {
    FieldDefinition resultField = formEditorHelper.getAvailableFields().values().stream().filter(fieldDefinition -> fieldDefinition.getBinding().equals(nameField.getBinding())).findFirst().get();
    formEditorHelper.saveFormField(nameField, resultField);
    Assertions.assertThat(resultField).isNotNull().isEqualToComparingOnlyGivenFields(nameField, "name", "binding", "standaloneClassName");
    Assertions.assertThat(content.getDefinition().getFieldById(resultField.getId())).isNotNull();
    Assertions.assertThat(content.getDefinition().getFields()).contains(resultField).doesNotContain(nameField);
    Assertions.assertThat(formEditorHelper.getAvailableFields().size()).isEqualTo(employeeFields.size() - 1);
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) Test(org.junit.Test)

Example 50 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormEditorPresenterTest method testFieldProperties.

protected void testFieldProperties(String fieldId, boolean bound) {
    FormDefinition form = editorHelper.getFormDefinition();
    addField(editorHelper.getAvailableFields().values().stream().filter(fieldDefinition -> fieldDefinition.getBinding().equals(fieldId)).findFirst().get());
    checkExpectedFields(editorHelper.getAvailableFields().size(), 1, bound);
    FieldDefinition field = editorHelper.getFormDefinition().getFields().get(0);
    checkFieldType(field, TextBoxFieldDefinition.class);
    Collection<String> compatibleTypes = editorHelper.getCompatibleFieldTypes(field);
    assertNotNull("No compatibles types found!", compatibleTypes);
    assertTrue("There should exist more than one compatible types for TextBoxFieldDefinition!", compatibleTypes.size() > 1);
    assertTrue("Missing TextAreaFieldDefinition as a compatible type for TextBoxFieldDefinition", compatibleTypes.contains(TextAreaFieldDefinition.FIELD_TYPE.getTypeName()));
    field = editorHelper.switchToFieldType(field, TextAreaFieldDefinition.FIELD_TYPE.getTypeName());
    checkFieldType(field, TextAreaFieldDefinition.class);
    List<String> compatibleFields = editorHelper.getCompatibleModelFields(field);
    assertNotNull("No compatibles fields found!", compatibleFields);
    assertEquals("There should exist 1 compatible fields for " + field.getName() + "!", 1, compatibleFields.size());
    String expectedBindingExpression = "lastName";
    field = editorHelper.switchToField(field, expectedBindingExpression);
    assertEquals("Wrong binding expression after switch field!", field.getBinding(), expectedBindingExpression);
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) FormEditorSyncPaletteEvent(org.kie.workbench.common.forms.editor.client.editor.events.FormEditorSyncPaletteEvent) FormEditorConstants(org.kie.workbench.common.forms.editor.client.resources.i18n.FormEditorConstants) FileNameAndCommitMessage(org.uberfire.ext.editor.commons.client.file.FileNameAndCommitMessage) RunWith(org.junit.runner.RunWith) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Matchers.eq(org.mockito.Matchers.eq) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) Matchers.anyInt(org.mockito.Matchers.anyInt) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) ComponentRemovedEvent(org.uberfire.ext.layout.editor.client.api.ComponentRemovedEvent) Mockito.anyString(org.mockito.Mockito.anyString) Mockito.doReturn(org.mockito.Mockito.doReturn) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) FieldLayoutComponent(org.kie.workbench.common.forms.dynamic.client.rendering.FieldLayoutComponent) RenamePopUpPresenter(org.uberfire.ext.editor.commons.client.file.popups.RenamePopUpPresenter) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) CommandWithFileNameAndCommitMessage(org.uberfire.ext.editor.commons.client.file.CommandWithFileNameAndCommitMessage) Mockito.verify(org.mockito.Mockito.verify) VerificationMode(org.mockito.verification.VerificationMode) List(java.util.List) Mockito.never(org.mockito.Mockito.never) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) AssetUpdateValidator(org.kie.workbench.common.widgets.metadata.client.validation.AssetUpdateValidator) DefaultFileNameValidator(org.uberfire.ext.editor.commons.client.validation.DefaultFileNameValidator) Mockito.any(org.mockito.Mockito.any) Mockito.reset(org.mockito.Mockito.reset) Assert.assertEquals(org.junit.Assert.assertEquals) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) Mockito.mock(org.mockito.Mockito.mock) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) Mockito.anyString(org.mockito.Mockito.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Aggregations

FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)85 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)42 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)29 Test (org.junit.Test)27 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)24 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)22 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)21 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)20 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)18 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)17 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)14 DatePickerFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition)13 ArrayList (java.util.ArrayList)11 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)8 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)7 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)7 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)7 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)7 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)7