Commit 9699d0a5 by Braden MacDonald

Fix more tests

parent 7eadc3f8
...@@ -155,6 +155,7 @@ class AnswerBlock(XBlock, StepMixin): ...@@ -155,6 +155,7 @@ class AnswerBlock(XBlock, StepMixin):
if not self.student_input_shared.get(course_id): if not self.student_input_shared.get(course_id):
self.student_input_shared[course_id] = {} self.student_input_shared[course_id] = {}
self.student_input_shared[course_id][self.name] = self.student_input_raw self.student_input_shared[course_id][self.name] = self.student_input_raw
self.save()
log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input)) log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input))
return { return {
'student_input': self.student_input, 'student_input': self.student_input,
......
...@@ -13,6 +13,9 @@ function MentoringAssessmentView(runtime, element, mentoring) { ...@@ -13,6 +13,9 @@ function MentoringAssessmentView(runtime, element, mentoring) {
checkmark.removeClass('checkmark-partially-correct icon-ok fa-check'); checkmark.removeClass('checkmark-partially-correct icon-ok fa-check');
checkmark.removeClass('checkmark-incorrect icon-exclamation fa-exclamation'); checkmark.removeClass('checkmark-incorrect icon-exclamation fa-exclamation');
// Clear all selections
$('input[type=radio], input[type=checkbox]').prop('checked', false);
// hide all children // hide all children
mentoring.hideAllChildren(); mentoring.hideAllChildren();
......
...@@ -3,7 +3,7 @@ from .base_test import MentoringBaseTest ...@@ -3,7 +3,7 @@ from .base_test import MentoringBaseTest
CORRECT, INCORRECT, PARTIAL = "correct", "incorrect", "partially-correct" CORRECT, INCORRECT, PARTIAL = "correct", "incorrect", "partially-correct"
class MentoringAssessmentTest(MentoringBaseTest): class MentoringAssessmentTest(MentoringBaseTest):
def _selenium_bug_workaround_scroll_to(self, mentoring): def _selenium_bug_workaround_scroll_to(self, mentoring, question):
"""Workaround for selenium bug: """Workaround for selenium bug:
Some version of Selenium has a bug that prevents scrolling Some version of Selenium has a bug that prevents scrolling
...@@ -20,8 +20,9 @@ class MentoringAssessmentTest(MentoringBaseTest): ...@@ -20,8 +20,9 @@ class MentoringAssessmentTest(MentoringBaseTest):
hopefully, this gives us enough room for the full step with the hopefully, this gives us enough room for the full step with the
control buttons to fit. control buttons to fit.
""" """
self.browser.execute_script("$('header.banner').remove();") # Hide the Workbench header which can obscure other elements we need
controls = mentoring.find_element_by_css_selector("div.submit") controls = mentoring.find_element_by_css_selector("div.submit")
title = mentoring.find_element_by_css_selector("h3.question-title") title = question.find_element_by_css_selector("h3.question-title")
controls.click() controls.click()
title.click() title.click()
...@@ -45,8 +46,8 @@ class MentoringAssessmentTest(MentoringBaseTest): ...@@ -45,8 +46,8 @@ class MentoringAssessmentTest(MentoringBaseTest):
self.assertFalse(elem.is_enabled()) self.assertFalse(elem.is_enabled())
class _GetChoices(object): class _GetChoices(object):
def __init__(self, mentoring, selector=".choices"): def __init__(self, question, selector=".choices"):
self._mcq = mentoring.find_element_by_css_selector(selector) self._mcq = question.find_element_by_css_selector(selector)
@property @property
def text(self): def text(self):
...@@ -101,9 +102,9 @@ class MentoringAssessmentTest(MentoringBaseTest): ...@@ -101,9 +102,9 @@ class MentoringAssessmentTest(MentoringBaseTest):
return "QUESTION" return "QUESTION"
def freeform_answer(self, number, mentoring, controls, text_input, result, saved_value="", last=False): def freeform_answer(self, number, mentoring, controls, text_input, result, saved_value="", last=False):
self.wait_until_text_in(self.question_text(number), mentoring) question = self.expect_question_visible(number, mentoring)
self.assert_persistent_elements_present(mentoring) self.assert_persistent_elements_present(mentoring)
self._selenium_bug_workaround_scroll_to(mentoring) self._selenium_bug_workaround_scroll_to(mentoring, question)
answer = mentoring.find_element_by_css_selector("textarea.answer.editable") answer = mentoring.find_element_by_css_selector("textarea.answer.editable")
...@@ -161,16 +162,17 @@ class MentoringAssessmentTest(MentoringBaseTest): ...@@ -161,16 +162,17 @@ class MentoringAssessmentTest(MentoringBaseTest):
controls.next_question.click() controls.next_question.click()
def single_choice_question(self, number, mentoring, controls, choice_name, result, last=False): def single_choice_question(self, number, mentoring, controls, choice_name, result, last=False):
self.wait_until_text_in(self.question_text(number), mentoring) question = self.expect_question_visible(number, mentoring)
self.assert_persistent_elements_present(mentoring) self.assert_persistent_elements_present(mentoring)
self._selenium_bug_workaround_scroll_to(mentoring)
self.assertIn("Do you like this MCQ?", mentoring.text) self.assertIn("Do you like this MCQ?", question.text)
self.assert_disabled(controls.submit) self.assert_disabled(controls.submit)
self.ending_controls(controls, last) self.ending_controls(controls, last)
self.assert_hidden(controls.try_again) self.assert_hidden(controls.try_again)
choices = self._GetChoices(mentoring) choices = self._GetChoices(question)
expected_state = {"Yes": False, "Maybe not": False, "I don't understand": False} expected_state = {"Yes": False, "Maybe not": False, "I don't understand": False}
self.assertEquals(choices.state, expected_state) self.assertEquals(choices.state, expected_state)
...@@ -188,9 +190,9 @@ class MentoringAssessmentTest(MentoringBaseTest): ...@@ -188,9 +190,9 @@ class MentoringAssessmentTest(MentoringBaseTest):
self.do_post(controls, last) self.do_post(controls, last)
def rating_question(self, number, mentoring, controls, choice_name, result, last=False): def rating_question(self, number, mentoring, controls, choice_name, result, last=False):
self.wait_until_text_in(self.question_text(number), mentoring) question = self.expect_question_visible(number, mentoring)
self.assert_persistent_elements_present(mentoring) self.assert_persistent_elements_present(mentoring)
self._selenium_bug_workaround_scroll_to(mentoring) self._selenium_bug_workaround_scroll_to(mentoring, question)
self.assertIn("How much do you rate this MCQ?", mentoring.text) self.assertIn("How much do you rate this MCQ?", mentoring.text)
self.assert_disabled(controls.submit) self.assert_disabled(controls.submit)
...@@ -218,19 +220,37 @@ class MentoringAssessmentTest(MentoringBaseTest): ...@@ -218,19 +220,37 @@ class MentoringAssessmentTest(MentoringBaseTest):
self._assert_checkmark(mentoring, result) self._assert_checkmark(mentoring, result)
self.do_post(controls, last) self.do_post(controls, last)
def peek_at_multiple_choice_question(self, number, mentoring, controls, last=False): def expect_question_visible(self, number, mentoring):
question_text = self.question_text(number)
self.wait_until_text_in(self.question_text(number), mentoring) self.wait_until_text_in(self.question_text(number), mentoring)
question_div = None
for xblock_div in mentoring.find_elements_by_css_selector('div.xblock-v1'):
header_text = xblock_div.find_elements_by_css_selector('h3.question-title')
if header_text and question_text in header_text[0].text:
question_div = xblock_div
self.assertTrue(xblock_div.is_displayed())
elif header_text:
self.assertFalse(xblock_div.is_displayed())
# else this is an HTML block or something else, not a question step
self.assertIsNotNone(question_div)
return question_div
def peek_at_multiple_choice_question(self, number, mentoring, controls, last=False):
question = self.expect_question_visible(number, mentoring)
self.assert_persistent_elements_present(mentoring) self.assert_persistent_elements_present(mentoring)
self._selenium_bug_workaround_scroll_to(mentoring) self._selenium_bug_workaround_scroll_to(mentoring, question)
self.assertIn("What do you like in this MRQ?", mentoring.text) self.assertIn("What do you like in this MRQ?", mentoring.text)
self.assert_disabled(controls.submit) self.assert_disabled(controls.submit)
self.ending_controls(controls, last) self.ending_controls(controls, last)
return question
def multiple_choice_question(self, number, mentoring, controls, choice_names, result, last=False): def multiple_choice_question(self, number, mentoring, controls, choice_names, result, last=False):
self.peek_at_multiple_choice_question(number, mentoring, controls, last=last) question = self.peek_at_multiple_choice_question(number, mentoring, controls, last=last)
choices = self._GetChoices(mentoring) choices = self._GetChoices(question)
expected_choices = { expected_choices = {
"Its elegance": False, "Its elegance": False,
"Its beauty": False, "Its beauty": False,
......
...@@ -176,6 +176,7 @@ class MCQBlockTest(MentoringBaseTest): ...@@ -176,6 +176,7 @@ class MCQBlockTest(MentoringBaseTest):
choice_wrapper = choices_list.find_elements_by_css_selector(".choice")[index] choice_wrapper = choices_list.find_elements_by_css_selector(".choice")[index]
choice_wrapper.find_element_by_css_selector(".choice-selector").click() # clicking on actual radio button choice_wrapper.find_element_by_css_selector(".choice-selector").click() # clicking on actual radio button
submit.click() submit.click()
self.wait_until_disabled(submit)
item_feedback_icon = choice_wrapper.find_element_by_css_selector(".choice-result") item_feedback_icon = choice_wrapper.find_element_by_css_selector(".choice-result")
choice_wrapper.click() choice_wrapper.click()
item_feedback_icon.click() # clicking on item feedback icon item_feedback_icon.click() # clicking on item feedback icon
...@@ -193,9 +194,8 @@ class MCQBlockTest(MentoringBaseTest): ...@@ -193,9 +194,8 @@ class MCQBlockTest(MentoringBaseTest):
result = [] result = []
# this could be a list comprehension, but a bit complicated one - hence explicit loop # this could be a list comprehension, but a bit complicated one - hence explicit loop
for choice_wrapper in questionnaire.find_elements_by_css_selector(".choice"): for choice_wrapper in questionnaire.find_elements_by_css_selector(".choice"):
choice_label = choice_wrapper.find_element_by_css_selector(".choice-label .choice-text") choice_label = choice_wrapper.find_element_by_css_selector("label .choice-text")
light_child = choice_label.find_element_by_css_selector(".xblock-light-child") result.append(choice_label.find_element_by_css_selector("div.html_child").get_attribute('innerHTML'))
result.append(light_child.find_element_by_css_selector("div").get_attribute('innerHTML'))
return result return result
......
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