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());
}
Aggregations