Search in sources :

Example 1 with Question

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

the class QuestionController method validateSmartChoice.

private boolean validateSmartChoice(QuestionForm questionForm, MessageContext context, int choiceIndex) {
    boolean result = true;
    Question question = questionForm.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 2 with Question

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

the class QuestionFormTest method testAddCurrentMultiSelectQuestion.

@Test
public void testAddCurrentMultiSelectQuestion() {
    QuestionForm questionForm = getQuestionForm("title", "multiSelect", "choice2");
    List<Question> questionList = questionForm.getQuestions();
    assertThat(questionList.size(), is(1));
    String text = questionList.get(0).getText();
    String type = questionList.get(0).getType();
    List<ChoiceDto> choices = questionList.get(0).getChoices();
    assertNotSame(type, questionForm.getCurrentQuestion().getType());
    assertNotSame(text, questionForm.getCurrentQuestion().getText());
    assertThat(type, is("multiSelect"));
    assertThat(text, is("title"));
    assertThat(choices.get(0).getValue(), is("choice2"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) Test(org.junit.Test)

Example 3 with Question

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

the class QuestionControllerTest method getQuestion.

private Question getQuestion(String id, String title, String type) {
    Question question = new Question(new QuestionDetail());
    question.setText(title);
    question.setId(id);
    question.setType(type);
    return question;
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail)

Example 4 with Question

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

the class QuestionTest method testAddSmartChoiceTag.

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

Example 5 with Question

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

the class QuestionTest method testAddAnswerChoice.

@Test
public void testAddAnswerChoice() {
    Question question = new Question(new QuestionDetail());
    question.setCurrentChoice("choice1");
    question.addAnswerChoice();
    question.setCurrentChoice("choice2");
    question.addAnswerChoice();
    question.setCurrentChoice("choice1");
    question.addAnswerChoice();
    question.setCurrentChoice("choice3");
    question.addAnswerChoice();
    assertThat(question.getChoices().size(), is(4));
    assertThat(question.getCurrentSmartChoiceTags().size(), is(4));
    assertEquals("choice1", question.getChoices().get(0).getValue());
    assertEquals("choice2", question.getChoices().get(1).getValue());
    assertEquals("choice1", question.getChoices().get(2).getValue());
    assertEquals("choice3", question.getChoices().get(3).getValue());
    assertEquals("choice1, choice2, choice1, choice3", question.getCommaSeparateChoices());
}
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