use of org.uberfire.ext.layout.editor.api.editor.LayoutColumn in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyUserForm.
protected void verifyUserForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(2);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(2);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", USER_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(2);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, USER_LOGIN, "login", "login", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, USER_PASSWORD, "password", "password", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
}
LayoutRow fieldRow = formLayout.getRows().get(index);
assertNotNull(fieldRow);
Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(1);
LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(0);
assertNotNull(fieldColumn);
assertEquals("12", fieldColumn.getSpan());
Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
});
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutColumn in project kie-wb-common by kiegroup.
the class FormLayoutTemplateGeneratorTest method testGeneratedLayout.
protected void testGeneratedLayout() {
LayoutTemplate layout = form.getLayoutTemplate();
assertNotNull(layout);
assertNotNull(layout.getRows());
assertEquals(form.getFields().size(), layout.getRows().size());
for (LayoutRow row : layout.getRows()) {
assertEquals(1, row.getLayoutColumns().size());
for (LayoutColumn col : row.getLayoutColumns()) {
assertEquals("12", col.getSpan());
assertEquals(0, col.getRows().size());
assertEquals(1, col.getLayoutComponents().size());
for (LayoutComponent component : col.getLayoutComponents()) {
assertEquals(templateGenerator.getDraggableType(), component.getDragTypeName());
assertEquals(form.getId(), component.getProperties().get(FormLayoutComponent.FORM_ID));
String fieldId = component.getProperties().get(FormLayoutComponent.FIELD_ID);
assertNotNull(fieldId);
assertNotNull(form.getFieldById(fieldId));
}
}
}
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutColumn in project kie-wb-common by kiegroup.
the class LayoutGeneratorTest method checkTwoColumnsRowWraps.
protected void checkTwoColumnsRowWraps(LayoutRow row) {
assertNotNull(row);
assertNotNull(row.getLayoutColumns());
assertEquals(2, row.getLayoutColumns().size());
LayoutColumn column = row.getLayoutColumns().get(0);
assertNotNull(column);
assertEquals("6", column.getSpan());
assertNotNull(column.getLayoutComponents());
assertEquals(1, column.getLayoutComponents().size());
assertTrue(settingsMap.containsKey(column.getLayoutComponents().get(0)));
// the first element is wrapped so check if the next column is empty
column = row.getLayoutColumns().get(1);
assertNotNull(column);
assertEquals("6", column.getSpan());
assertNotNull(column.getLayoutComponents());
assertNotNull(column.getLayoutComponents());
assertEquals(0, column.getLayoutComponents().size());
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutColumn in project kie-wb-common by kiegroup.
the class AbstractFormGenerationTest method testGeneratedForm.
protected void testGeneratedForm(FormDefinition form, String modelName) {
assertNotNull(form);
FormDefinitionSettings settings = resourcesProvider.getDefinitionSettings().get(modelName);
assertEquals(settings.getModelType(), form.getId());
assertEquals(settings.getModelType(), form.getName());
assertEquals(settings.getFormElements().size(), form.getFields().size());
settings.getFormElements().forEach(element -> {
FieldElement fieldElement = (FieldElement) element;
FieldDefinition field = form.getFieldByBinding(fieldElement.getBinding());
assertNotNull(field);
assertEquals(fieldElement.getName(), field.getName());
if (!fieldElement.getPreferredType().equals(FieldType.class)) {
assertEquals(fieldElement.getPreferredType(), field.getFieldType().getClass());
}
assertEquals(fieldElement.getTypeInfo().getClassName(), field.getStandaloneClassName());
assertEquals(fieldElement.isReadOnly(), field.getReadOnly());
assertEquals(fieldElement.isRequired(), field.getRequired());
assertEquals(fieldElement.getBinding(), field.getBinding());
verify(i18nHelper, atLeast(1)).getTranslation(field.getName() + ".label");
});
assertNotNull(form.getLayoutTemplate());
assertEquals(settings.getFormElements().size(), form.getLayoutTemplate().getRows().size());
form.getLayoutTemplate().getRows().forEach(row -> {
assertNotNull(row);
assertEquals(1, row.getLayoutColumns().size());
LayoutColumn column = row.getLayoutColumns().get(0);
assertNotNull(column);
assertEquals("12", column.getSpan());
assertEquals(1, column.getLayoutComponents().size());
LayoutComponent layoutComponent = column.getLayoutComponents().get(0);
String formId = layoutComponent.getProperties().get(FormLayoutComponent.FORM_ID);
assertNotNull(formId);
assertEquals(form.getId(), formId);
String fieldId = layoutComponent.getProperties().get(FormLayoutComponent.FIELD_ID);
assertNotNull(fieldId);
FieldDefinition field = form.getFieldById(fieldId);
assertNotNull(field);
});
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutColumn in project kie-wb-common by kiegroup.
the class AbstractFormLayoutTemplateGenerator method addFieldsToTemplate.
protected void addFieldsToTemplate(LayoutTemplate template, List<FieldDefinition> fields, String formId) {
fields.forEach(field -> {
LayoutComponent layoutComponent = new LayoutComponent(getDraggableType());
layoutComponent.addProperty(FormLayoutComponent.FORM_ID, formId);
layoutComponent.addProperty(FormLayoutComponent.FIELD_ID, field.getId());
LayoutColumn column = new LayoutColumn("12");
column.add(layoutComponent);
LayoutRow row = new LayoutRow();
row.add(column);
template.addRow(row);
});
}
Aggregations