Commit aa9fa671 by Matjaz Gregoric

Make MRQs behave like MCQs when hide_previous_answer is True.

When the pb_mcq_hide_previous_answer is set to True, MRQs should behave
the same way as MCQs behave - previous choices should not be displayed
and the checkmarks should be hidden.
parent 1c49b875
...@@ -374,7 +374,7 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM ...@@ -374,7 +374,7 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
return Score(score, int(round(score * 100)), correct, incorrect, partially_correct) return Score(score, int(round(score * 100)), correct, incorrect, partially_correct)
def student_view(self, context): def student_view(self, context):
from .mcq import MCQBlock # Import here to avoid circular dependency from .questionnaire import QuestionnaireAbstractBlock # Import here to avoid circular dependency
# Migrate stored data if necessary # Migrate stored data if necessary
self.migrate_fields() self.migrate_fields()
...@@ -398,7 +398,7 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM ...@@ -398,7 +398,7 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
if self.is_assessment and isinstance(child, QuestionMixin): if self.is_assessment and isinstance(child, QuestionMixin):
child_fragment = child.render('assessment_step_view', context) child_fragment = child.render('assessment_step_view', context)
else: else:
if mcq_hide_previous_answer and isinstance(child, MCQBlock): if mcq_hide_previous_answer and isinstance(child, QuestionnaireAbstractBlock):
context['hide_prev_answer'] = True context['hide_prev_answer'] = True
else: else:
context['hide_prev_answer'] = False context['hide_prev_answer'] = False
......
...@@ -302,7 +302,8 @@ function MentoringWithStepsBlock(runtime, element) { ...@@ -302,7 +302,8 @@ function MentoringWithStepsBlock(runtime, element) {
var step = steps[i]; var step = steps[i];
var mentoring = { var mentoring = {
setContent: setContent, setContent: setContent,
publish_event: publishEvent publish_event: publishEvent,
step_builder: true
}; };
options.mentoring = mentoring; options.mentoring = mentoring;
step.initChildren(options); step.initChildren(options);
......
...@@ -210,7 +210,11 @@ function MRQBlock(runtime, element) { ...@@ -210,7 +210,11 @@ function MRQBlock(runtime, element) {
var questionnaireDOM = $('fieldset.questionnaire', element); var questionnaireDOM = $('fieldset.questionnaire', element);
var data = questionnaireDOM.data(); var data = questionnaireDOM.data();
var hide_results = (data.hide_results === 'True'); var hide_results = (data.hide_results === 'True' ||
(data.hide_prev_answer === 'True' && !mentoring.step_builder));
// hide_prev_answer should only take effect when we initially render (previous) results,
// so set hide_prev_answer to False after initial render.
questionnaireDOM.data('hide_prev_answer', 'False');
$.each(result.choices, function(index, choice) { $.each(result.choices, function(index, choice) {
var choiceInputDOM = $('.choice input[value='+choice.value+']', element); var choiceInputDOM = $('.choice input[value='+choice.value+']', element);
......
<fieldset class="choices questionnaire" data-hide_results="{{self.hide_results}}"> <fieldset class="choices questionnaire" data-hide_results="{{self.hide_results}}" data-hide_prev_answer="{{hide_prev_answer}}">
<legend class="question"> <legend class="question">
{% if not hide_header %}<h3 class="question-title">{{ self.display_name_with_default }}</h3>{% endif %} {% if not hide_header %}<h3 class="question-title">{{ self.display_name_with_default }}</h3>{% endif %}
<p>{{ self.question|safe }}</p> <p>{{ self.question|safe }}</p>
......
...@@ -164,7 +164,8 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest): ...@@ -164,7 +164,8 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest):
choice_input = choice.find_element_by_css_selector('input') choice_input = choice.find_element_by_css_selector('input')
self.assertFalse(choice_input.is_selected()) self.assertFalse(choice_input.is_selected())
def _assert_mrq(self, mrq): def _assert_mrq(self, mrq, previous_answer_shown=True):
if previous_answer_shown:
self._assert_feedback_shown( self._assert_feedback_shown(
mrq, 0, "This is something everyone has to like about this MRQ", mrq, 0, "This is something everyone has to like about this MRQ",
click_choice_result=True click_choice_result=True
...@@ -175,6 +176,10 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest): ...@@ -175,6 +176,10 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest):
) )
self._assert_feedback_shown(mrq, 2, "This MRQ is indeed very graceful", click_choice_result=True) self._assert_feedback_shown(mrq, 2, "This MRQ is indeed very graceful", click_choice_result=True)
self._assert_feedback_shown(mrq, 3, "Nah, there aren't any!", click_choice_result=True, success=False) self._assert_feedback_shown(mrq, 3, "Nah, there aren't any!", click_choice_result=True, success=False)
else:
for i in range(3):
self._assert_feedback_hidden(mrq, i)
self._assert_not_checked(mrq, i)
def _assert_messages(self, messages, shown=True): def _assert_messages(self, messages, shown=True):
if shown: if shown:
...@@ -227,8 +232,8 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest): ...@@ -227,8 +232,8 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest):
self._assert_answer(answer) self._assert_answer(answer)
# MCQ: Previous answer and results hidden # MCQ: Previous answer and results hidden
self._assert_mcq(mcq, previous_answer_shown=False) self._assert_mcq(mcq, previous_answer_shown=False)
# MRQ: Previous answer and results visible # MRQ: Previous answer and results hidden
self._assert_mrq(mrq) self._assert_mrq(mrq, previous_answer_shown=False)
# Rating: Previous answer and results hidden # Rating: Previous answer and results hidden
self._assert_rating(rating, previous_answer_shown=False) self._assert_rating(rating, previous_answer_shown=False)
# Messages visible # Messages visible
...@@ -251,8 +256,8 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest): ...@@ -251,8 +256,8 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest):
self._assert_answer(answer, results_shown=False) self._assert_answer(answer, results_shown=False)
# MCQ: Previous answer and results hidden # MCQ: Previous answer and results hidden
self._assert_mcq(mcq, previous_answer_shown=False) self._assert_mcq(mcq, previous_answer_shown=False)
# MRQ: Previous answer and results visible # MRQ: Previous answer and results hidden
self._assert_mrq(mrq) self._assert_mrq(mrq, previous_answer_shown=False)
# Rating: Previous answer and feedback hidden # Rating: Previous answer and feedback hidden
self._assert_rating(rating, previous_answer_shown=False) self._assert_rating(rating, previous_answer_shown=False)
# Messages hidden # Messages hidden
...@@ -338,11 +343,19 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest): ...@@ -338,11 +343,19 @@ class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest):
# ... and see if previous answers, results, feedback are shown/hidden correctly # ... and see if previous answers, results, feedback are shown/hidden correctly
getattr(self, after_reload_checks)(answer, mcq, mrq, rating, messages) getattr(self, after_reload_checks)(answer, mcq, mrq, rating, messages)
# After reloading, submit is disabled... # After reloading, submit is enabled only when:
# - feedback is hidden; and
# - previous MCQ/MRQ answers are visible.
# When feedback is visible there's no need to resubmit the same answer;
# and when previous MCQ/MRQ answers are hidden, submit is disabled until you select some options.
if options['pb_hide_feedback_if_attempts_remain'] and not options['pb_mcq_hide_previous_answer']:
self.assertTrue(submit.is_enabled())
else:
self.assertFalse(submit.is_enabled()) self.assertFalse(submit.is_enabled())
# ... until student makes changes # When student makes changes, submit is enabled again.
self.click_choice(mcq, "Maybe not") self.click_choice(mcq, "Maybe not")
self.click_choice(mrq, "Its elegance")
self.click_choice(rating, "2") self.click_choice(rating, "2")
self.assertTrue(submit.is_enabled()) self.assertTrue(submit.is_enabled())
......
...@@ -227,7 +227,8 @@ class TestMentoringBlockOptions(unittest.TestCase): ...@@ -227,7 +227,8 @@ class TestMentoringBlockOptions(unittest.TestCase):
self.block.get_xblock_settings = Mock(return_value={}) self.block.get_xblock_settings = Mock(return_value={})
with patch.object(self.block, 'get_option') as patched_get_option: with patch.object(self.block, 'get_option') as patched_get_option:
self.block.student_view({}) self.block.student_view({})
patched_get_option.assert_called_with('pb_mcq_hide_previous_answer') patched_get_option.assert_any_call('pb_mcq_hide_previous_answer')
patched_get_option.assert_any_call('pb_hide_feedback_if_attempts_remain')
def test_get_standard_results_calls_get_option(self): def test_get_standard_results_calls_get_option(self):
with patch.object(self.block, 'get_option') as patched_get_option: with patch.object(self.block, 'get_option') as patched_get_option:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment