Search in sources :

Example 11 with FieldInput

use of org.activityinfo.ui.client.input.model.FieldInput in project activityinfo by bedatadriven.

the class MonthWidget method input.

private FieldInput input() {
    try {
        int year = Integer.parseInt(yearBox.getText());
        int monthOfYear = MONTHS.indexOf(monthBox.getText()) + 1;
        return new FieldInput(new Month(year, monthOfYear));
    } catch (Exception e) {
        return FieldInput.INVALID_INPUT;
    }
}
Also used : Month(org.activityinfo.model.type.time.Month) FieldInput(org.activityinfo.ui.client.input.model.FieldInput)

Example 12 with FieldInput

use of org.activityinfo.ui.client.input.model.FieldInput in project activityinfo by bedatadriven.

the class FormInputViewModelTest method testSurveyRelevance.

@Test
public void testSurveyRelevance() {
    Survey survey = setup.getCatalog().getSurvey();
    FormInputViewModelBuilder builder = builderFor(survey);
    // Start with no input
    FormInputModel inputModel = new FormInputModel(new RecordRef(survey.getFormId(), ResourceId.generateId()));
    // Is this valid?
    FormInputViewModel viewModel = builder.build(inputModel);
    // Fields with invalid relevance are considered relevant
    assertTrue("field with bad relevance is relevant", viewModel.isRelevant(survey.getAgeFieldId()));
    assertThat("pregnant is not yet relevant", viewModel.isRelevant(survey.getPregnantFieldId()), equalTo(false));
    assertThat("prenatale care is not relevant", viewModel.isRelevant(survey.getPrenataleCareFieldId()), equalTo(false));
    assertThat("form is valid", viewModel.isValid(), equalTo(false));
    // Answer the gender
    inputModel = inputModel.update(survey.getGenderFieldId(), new FieldInput(new EnumValue(survey.getFemaleId())));
    viewModel = builder.build(inputModel);
    assertThat("pregnant is now relevant", viewModel.isRelevant(survey.getPregnantFieldId()), equalTo(true));
    assertThat("prenatale care is still not relevant", viewModel.isRelevant(survey.getPrenataleCareFieldId()), equalTo(false));
    // Answer pregnant = yes
    inputModel = inputModel.update(survey.getPregnantFieldId(), new FieldInput(new EnumValue(survey.getPregnantId())));
    viewModel = builder.build(inputModel);
    assertThat("pregnant is still relevant", viewModel.isRelevant(survey.getPregnantFieldId()), equalTo(true));
    assertThat("prenatale is now relevant", viewModel.isRelevant(survey.getPrenataleCareFieldId()), equalTo(true));
    // Change gender = Male
    inputModel = inputModel.update(survey.getGenderFieldId(), new FieldInput(new EnumValue(survey.getMaleId())));
    viewModel = builder.build(inputModel);
    assertThat("pregnant is not relevant", viewModel.isRelevant(survey.getPregnantFieldId()), equalTo(false));
    assertThat("prenatale is not relevant", viewModel.isRelevant(survey.getPrenataleCareFieldId()), equalTo(false));
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FieldInput(org.activityinfo.ui.client.input.model.FieldInput) Test(org.junit.Test)

Aggregations

FieldInput (org.activityinfo.ui.client.input.model.FieldInput)12 RecordRef (org.activityinfo.model.type.RecordRef)6 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)5 Test (org.junit.Test)5 LocalDate (org.activityinfo.model.type.time.LocalDate)4 FormTree (org.activityinfo.model.formTree.FormTree)2 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)2 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)2 Quantity (org.activityinfo.model.type.number.Quantity)2 Date (java.util.Date)1 Set (java.util.Set)1 FormInstance (org.activityinfo.model.form.FormInstance)1 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 ReferenceValue (org.activityinfo.model.type.ReferenceValue)1 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)1 Month (org.activityinfo.model.type.time.Month)1 PeriodValue (org.activityinfo.model.type.time.PeriodValue)1