Search in sources :

Example 31 with ReferenceValue

use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.

the class FormInputViewModelTest method requiredSubFormFields.

@Test
public void requiredSubFormFields() {
    BioDataForm bioDataForm = setup.getCatalog().getBioDataForm();
    IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
    ReferralSubForm referralSubForm = setup.getCatalog().getReferralSubForm();
    FormInputViewModelBuilder builder = builderFor(incidentForm);
    FormInputModel inputModel = new FormInputModel(new RecordRef(incidentForm.getFormId(), ResourceId.generateId()));
    // Fill in required fields
    inputModel = inputModel.update(IncidentForm.PROTECTION_CODE_FIELD_ID, new ReferenceValue(bioDataForm.getRecordRef(0)));
    // Should be valid as we have only a placeholder sub form...
    FormInputViewModel viewModel = builder.build(inputModel);
    FormInputViewModel referralRecord = viewModel.getSubForm(IncidentForm.REFERRAL_FIELD_ID).getSubRecords().get(0);
    assertTrue(referralRecord.isPlaceholder());
    assertThat(viewModel.isValid(), equalTo(true));
    // Now add a new referral sub form
    // Without completing all required fields, and make sure the form is invalid
    inputModel = inputModel.update(referralRecord.getRecordRef(), referralSubForm.getContactNumber().getId(), FieldInput.EMPTY);
    viewModel = builder.build(inputModel);
    referralRecord = viewModel.getSubForm(IncidentForm.REFERRAL_FIELD_ID).getSubRecords().get(0);
    assertFalse("subform is invalid", referralRecord.isValid());
    assertFalse("parent is invalid", viewModel.isValid());
}
Also used : ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) Test(org.junit.Test)

Aggregations

ReferenceValue (org.activityinfo.model.type.ReferenceValue)31 RecordRef (org.activityinfo.model.type.RecordRef)26 ResourceId (org.activityinfo.model.resource.ResourceId)17 Test (org.junit.Test)11 FormInstance (org.activityinfo.model.form.FormInstance)7 FieldValue (org.activityinfo.model.type.FieldValue)7 LocalDate (org.activityinfo.model.type.time.LocalDate)4 ResultSet (java.sql.ResultSet)3 OnDataSet (org.activityinfo.server.database.OnDataSet)3 ForeignKeyBuilder (org.activityinfo.store.query.server.join.ForeignKeyBuilder)3 ForeignKey (org.activityinfo.store.query.shared.columns.ForeignKey)3 SQLException (java.sql.SQLException)2 Set (java.util.Set)2 FormClass (org.activityinfo.model.form.FormClass)2 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)2 RecordTree (org.activityinfo.model.formTree.RecordTree)2 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)2 Maybe (org.activityinfo.promise.Maybe)2 ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)2 BitSet (java.util.BitSet)1