Search in sources :

Example 6 with Question

use of org.mifos.platform.questionnaire.ui.model.Question in project head by mifos.

the class QuestionTest method assertQuestion.

private void assertQuestion(String text, QuestionType questionType, String questionTypeString, List<String> choices) {
    QuestionDetail questionDetail = new QuestionDetail(123, text, questionType, true, true);
    List<ChoiceDto> choiceDtos = getChoiceDetails(choices);
    questionDetail.setAnswerChoices(choiceDtos);
    Question question = new Question(questionDetail);
    assertThat(question.getText(), is(text));
    assertThat(question.getType(), is(questionTypeString));
    assertEquals(question.getChoices(), choiceDtos);
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail)

Example 7 with Question

use of org.mifos.platform.questionnaire.ui.model.Question in project head by mifos.

the class QuestionTest method testAddSmartChoiceTagDoesnotAllowDuplicates.

@Test
public void testAddSmartChoiceTagDoesnotAllowDuplicates() {
    QuestionDetail questionDetail = new QuestionDetail();
    Question question = new Question(questionDetail);
    question.setCurrentSmartChoice("Choice1");
    question.addAnswerSmartChoice();
    question.getCurrentSmartChoiceTags().set(0, "Tag_1");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "Tag_1");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "Tag_2");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "TAg_2");
    question.addSmartChoiceTag(0);
    assertThat(questionDetail.getAnswerChoices().get(0).getTags().size(), is(2));
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 8 with Question

use of org.mifos.platform.questionnaire.ui.model.Question in project head by mifos.

the class QuestionTest method testRemoveChoiceTag.

@Test
public void testRemoveChoiceTag() {
    Question question = new Question(new QuestionDetail());
    question.setCurrentSmartChoice("Choice1");
    question.addAnswerSmartChoice();
    question.getCurrentSmartChoiceTags().set(0, "Tag1");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "Tag2");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "Tag3");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "Tag4");
    question.addSmartChoiceTag(0);
    question.removeChoiceTag("0_2");
    assertThat(question.getQuestionDetail().getAnswerChoices().size(), is(1));
    assertThat(question.getQuestionDetail().getAnswerChoices().get(0).getTags().size(), is(3));
    assertThat(question.getQuestionDetail().getAnswerChoices().get(0).getTags().get(0), is("Tag1"));
    assertThat(question.getQuestionDetail().getAnswerChoices().get(0).getTags().get(1), is("Tag2"));
    assertThat(question.getQuestionDetail().getAnswerChoices().get(0).getTags().get(2), is("Tag4"));
    question.removeChoiceTag("0_0");
    question.removeChoiceTag("0_0");
    question.removeChoiceTag("0_0");
    assertThat(question.getQuestionDetail().getAnswerChoices().size(), is(1));
    assertThat(question.getQuestionDetail().getAnswerChoices().get(0).getTags().size(), is(0));
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 9 with Question

use of org.mifos.platform.questionnaire.ui.model.Question in project head by mifos.

the class QuestionGroupController method validateSmartChoice.

private boolean validateSmartChoice(QuestionGroupForm questionGroupForm, MessageContext context, int choiceIndex) {
    boolean result = true;
    Question question = questionGroupForm.getCurrentQuestion();
    if (context.hasErrorMessages()) {
        result = false;
    } else if (question.isSmartChoiceDuplicated(choiceIndex)) {
        constructErrorMessage(context, "questionnaire.error.question.tags.duplicate", "currentQuestion.answerChoices", "The tag with the same name already exists.");
        result = false;
    } else if (question.isTagsLimitReached(choiceIndex)) {
        constructErrorMessage(context, "questionnaire.error.question.tags.limit", "currentQuestion.answerChoices", "You cannot add more than five tags.");
        result = false;
    }
    return result;
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question)

Example 10 with Question

use of org.mifos.platform.questionnaire.ui.model.Question in project head by mifos.

the class QuestionTest method testRemoveAnswerChoice.

@Test
public void testRemoveAnswerChoice() {
    Question question = new Question(new QuestionDetail());
    question.setCurrentChoice("choice1");
    question.addAnswerChoice();
    question.setCurrentChoice("choice2");
    question.addAnswerChoice();
    question.setCurrentChoice("choice1");
    question.addAnswerChoice();
    assertEquals("choice1", question.getChoices().get(0).getValue());
    assertEquals("choice2", question.getChoices().get(1).getValue());
    assertEquals("choice1", question.getChoices().get(2).getValue());
    question.removeChoice(0);
    assertEquals("choice2", question.getChoices().get(0).getValue());
    assertEquals("choice1", question.getChoices().get(1).getValue());
    question.removeChoice(1);
    assertEquals("choice2", question.getChoices().get(0).getValue());
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Aggregations

Question (org.mifos.platform.questionnaire.ui.model.Question)23 Test (org.junit.Test)18 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)16 QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)8 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)2 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)2 ArrayList (java.util.ArrayList)1 SectionDetailForm (org.mifos.platform.questionnaire.ui.model.SectionDetailForm)1