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