use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.
the class JsonPathPredicateGeneratorTest method fromLeafNode_predicateBasedOnSiblingRepeatedQuestion_generatesCorrectPath.
@Test
public void fromLeafNode_predicateBasedOnSiblingRepeatedQuestion_generatesCorrectPath() throws Exception {
ApplicantData applicantData = new ApplicantData();
EnumeratorQuestionDefinition enumerator = (EnumeratorQuestionDefinition) questionBank.applicantHouseholdMembers().getQuestionDefinition();
QuestionDefinition siblingQuestion = new QuestionDefinitionBuilder(questionBank.applicantHouseholdMemberName().getQuestionDefinition()).setEnumeratorId(Optional.of(enumerator.getId())).build();
// Put an entity at the enumerator path so we can generate repeated contexts.
ApplicantQuestion applicantEnumerator = new ApplicantQuestion(enumerator, applicantData, Optional.empty());
applicantData.putRepeatedEntities(applicantEnumerator.getContextualizedPath(), ImmutableList.of("Bernard", "Alice"));
// Just use a repeated entity for the first (index 0) entity.
ImmutableList<RepeatedEntity> repeatedEntities = RepeatedEntity.createRepeatedEntities(enumerator, Optional.empty(), applicantData);
Optional<RepeatedEntity> repeatedEntity = repeatedEntities.stream().findFirst();
generator = new JsonPathPredicateGenerator(ImmutableList.of(enumerator, siblingQuestion), repeatedEntity);
LeafOperationExpressionNode node = LeafOperationExpressionNode.create(// The predicate is based on the sibling "name" question.
siblingQuestion.getId(), Scalar.FIRST_NAME, Operator.EQUAL_TO, PredicateValue.of("Bernard"));
assertThat(generator.fromLeafNode(node)).isEqualTo(JsonPathPredicate.create("$.applicant.applicant_household_members[0].household_members_name" + "[?(@.first_name == \"Bernard\")]"));
}
use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.
the class ApplicantQuestionTest method questionTextAndHelpText_areContextualizedByRepeatedEntity.
@Test
public void questionTextAndHelpText_areContextualizedByRepeatedEntity() {
ApplicantData applicantData = new ApplicantData();
Path householdMembersPath = ApplicantData.APPLICANT_PATH.join(testQuestionBank.applicantHouseholdMembers().getQuestionDefinition().getQuestionPathSegment());
QuestionAnswerer.answerEnumeratorQuestion(applicantData, householdMembersPath, ImmutableList.of("Jonathan"));
Path householdMembersJobsPath = householdMembersPath.atIndex(0).join(testQuestionBank.applicantHouseholdMemberJobs().getQuestionDefinition().getQuestionPathSegment());
QuestionAnswerer.answerEnumeratorQuestion(applicantData, householdMembersJobsPath, ImmutableList.of("JonCo"));
RepeatedEntity jonathan = RepeatedEntity.createRepeatedEntities((EnumeratorQuestionDefinition) testQuestionBank.applicantHouseholdMembers().getQuestionDefinition(), Optional.empty(), applicantData).get(0);
RepeatedEntity jonCo = jonathan.createNestedRepeatedEntities((EnumeratorQuestionDefinition) testQuestionBank.applicantHouseholdMemberJobs().getQuestionDefinition(), Optional.empty(), applicantData).get(0);
ApplicantQuestion applicantQuestion = new ApplicantQuestion(testQuestionBank.applicantHouseholdMemberDaysWorked().getQuestionDefinition(), applicantData, Optional.of(jonCo));
assertThat(applicantQuestion.getQuestionText()).isEqualTo("How many days has Jonathan worked at JonCo?");
assertThat(applicantQuestion.getQuestionHelpText()).isEqualTo("How many days has Jonathan worked at JonCo?");
}
use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.
the class QuestionTest method canSerializeAndDeserializeEnumeratorQuestion.
@Test
public void canSerializeAndDeserializeEnumeratorQuestion() throws UnsupportedQuestionTypeException {
LocalizedStrings entityType = LocalizedStrings.of(Locale.US, "entity");
QuestionDefinition definition = new QuestionDefinitionBuilder().setQuestionType(QuestionType.ENUMERATOR).setName("").setDescription("").setEnumeratorId(Optional.of(123L)).setQuestionText(LocalizedStrings.of()).setQuestionHelpText(LocalizedStrings.empty()).setEntityType(entityType).build();
Question question = new Question(definition);
question.save();
Question found = repo.lookupQuestion(question.id).toCompletableFuture().join().get();
assertThat(found.getQuestionDefinition().getQuestionType()).isEqualTo(QuestionType.ENUMERATOR);
EnumeratorQuestionDefinition enumerator = (EnumeratorQuestionDefinition) found.getQuestionDefinition();
assertThat(enumerator.getEntityType()).isEqualTo(entityType);
}
use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.
the class EnumeratorQuestionTranslationFormTest method buildsQuestion_newLocale_savesUpdates.
@Test
public void buildsQuestion_newLocale_savesUpdates() throws Exception {
QuestionDefinition question = new EnumeratorQuestionDefinition("test", Optional.empty(), "desc", LocalizedStrings.withDefaultValue("existing"), LocalizedStrings.withDefaultValue("existing"), LocalizedStrings.withDefaultValue("existing"));
EnumeratorQuestionTranslationForm form = new EnumeratorQuestionTranslationForm();
form.setQuestionText("Canadian question text");
form.setEntityType("Canadian English");
EnumeratorQuestionDefinition updated = (EnumeratorQuestionDefinition) form.builderWithUpdates(question, Locale.CANADA).build();
assertThat(updated.getEntityType()).isEqualTo(LocalizedStrings.of(Locale.US, "existing", Locale.CANADA, "Canadian English"));
assertThat(updated.getQuestionText()).isEqualTo(LocalizedStrings.of(Locale.US, "existing", Locale.CANADA, "Canadian question text"));
}
use of services.question.types.EnumeratorQuestionDefinition in project civiform by seattle-uat.
the class EnumeratorQuestionFormTest method getBuilder_returnsCompleteBuilder.
@Test
public void getBuilder_returnsCompleteBuilder() throws Exception {
EnumeratorQuestionForm form = new EnumeratorQuestionForm();
form.setQuestionName("name");
form.setQuestionDescription("description");
form.setQuestionText("What is the question text?");
form.setQuestionHelpText("");
QuestionDefinitionBuilder builder = form.getBuilder();
EnumeratorQuestionDefinition expected = new EnumeratorQuestionDefinition("name", Optional.empty(), "description", LocalizedStrings.of(Locale.US, "What is the question text?"), LocalizedStrings.empty(), LocalizedStrings.empty());
QuestionDefinition actual = builder.build();
assertThat(actual).isEqualTo(expected);
}
Aggregations