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