Aids styleability of CAPA checkbox and radio problems

by making CAPA <input> elements siblings of their <label>s, instead of children.

Also:

* Moves radio submitted status block down below the problem
  to match the checkbox problem status blocks.
* Marks submitted choicegroup answers with a class
This commit is contained in:
Jillian Vogel
2019-07-23 16:23:40 +09:30
parent 3e4e027234
commit fb981bfbbe
6 changed files with 149 additions and 123 deletions

View File

@@ -489,30 +489,39 @@ class ProblemPage(PageObject):
solution_selector = '.solution-span div.detailed-solution'
return self.q(css=solution_selector).is_present()
def is_choice_highlighted(self, choice, choices_list):
def is_choice_highlighted(self, choice, choices_list, show_answer=True):
"""
Check if the given answer/choice is highlighted for choice group.
show_answer: if set, then requires each choice to be marked with a status.
If not set, then the status can be elswhere in the problem.
"""
choice_status_xpath = (u'//fieldset/div[contains(@class, "field")][{{0}}]'
u'/label[contains(@class, "choicegroup_{choice}")]'
u'/span[contains(@class, "status {choice}")]'.format(choice=choice))
any_status_xpath = u'//fieldset/div[contains(@class, "field")][{0}]/label/span'
for choice in choices_list:
if not self.q(xpath=choice_status_xpath.format(choice)).is_present():
if show_answer:
choice_status_xpath = (u'//fieldset/div[contains(@class, "field")][{{0}}]'
u'/label[contains(@class, "choicegroup_{choice}")]'
u'/span[contains(@class, "status {choice}")]'.format(choice=choice))
any_status_xpath = u'//fieldset/div[contains(@class, "field")][{0}]/label/span'
else:
choice_status_xpath = (u'//fieldset/div[contains(@class, "field")][{{0}}]'
u'/label[contains(@class, "choicegroup_{choice}")]'.format(choice=choice))
any_status_xpath = u'//div[contains(@class, "indicator-container")]/span[contains(@class, "status")]'
for possible_choice in choices_list:
if not self.q(xpath=choice_status_xpath.format(possible_choice)).is_present():
return False
# Check that there is only a single status span, as there were some bugs with multiple
# spans (with various classes) being appended.
if not len(self.q(xpath=any_status_xpath.format(choice)).results) == 1:
if not len(self.q(xpath=any_status_xpath.format(possible_choice)).results) == 1:
return False
return True
def is_correct_choice_highlighted(self, correct_choices):
def is_correct_choice_highlighted(self, correct_choices, show_answer=True):
"""
Check if correct answer/choice highlighted for choice group.
"""
return self.is_choice_highlighted('correct', correct_choices)
return self.is_choice_highlighted('correct', correct_choices, show_answer)
def is_submitted_choice_highlighted(self, correct_choices):
"""

View File

@@ -786,7 +786,7 @@ class MultipleChoiceProblemTypeTest(MultipleChoiceProblemTypeBase, ProblemTypeTe
# After submit, the answer should be marked as correct.
self.problem_page.click_submit()
self.assertTrue(self.problem_page.is_correct_choice_highlighted(correct_choices=[3]))
self.assertTrue(self.problem_page.is_correct_choice_highlighted(correct_choices=[3], show_answer=False))
# Switch to an incorrect answer. This will hide the correctness indicator.
self.answer_problem('incorrect')