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