Commit 40ff34ff by E. Kolpakov

Restoring feedback on reload for stadnard-mode mentoring + tests

parent 395c4034
...@@ -28,8 +28,6 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -28,8 +28,6 @@ function MentoringStandardView(runtime, element, mentoring) {
messagesDOM.prepend('<div class="title1">' + gettext('Feedback') + '</div>'); messagesDOM.prepend('<div class="title1">' + gettext('Feedback') + '</div>');
messagesDOM.show(); messagesDOM.show();
} }
submitDOM.attr('disabled', 'disabled');
} }
function handleSubmitError(jqXHR, textStatus, errorThrown) { function handleSubmitError(jqXHR, textStatus, errorThrown) {
...@@ -45,12 +43,10 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -45,12 +43,10 @@ function MentoringStandardView(runtime, element, mentoring) {
mentoring.setContent(messagesDOM, errMsg); mentoring.setContent(messagesDOM, errMsg);
messagesDOM.show(); messagesDOM.show();
submitDOM.attr('disabled', 'disabled');
} }
} }
function calculate_results(handler_name) { function calculate_results(handler_name, disable_submit) {
var data = {}; var data = {};
var children = mentoring.children; var children = mentoring.children;
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
...@@ -64,14 +60,19 @@ function MentoringStandardView(runtime, element, mentoring) { ...@@ -64,14 +60,19 @@ function MentoringStandardView(runtime, element, mentoring) {
submitXHR.abort(); submitXHR.abort();
} }
submitXHR = $.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults).error(handleSubmitError); submitXHR = $.post(handlerUrl, JSON.stringify(data)).success(handleSubmitResults).error(handleSubmitError);
if (disable_submit) {
var disable_submit_callback = function(){ submitDOM.attr('disabled', 'disabled'); };
submitXHR.success(disable_submit_callback).error(disable_submit_callback);
}
} }
function get_results(){ function get_results(){
calculate_results('get_results'); calculate_results('get_results', false);
} }
function submit() { function submit() {
calculate_results('submit'); calculate_results('submit', true);
} }
function clearResults() { function clearResults() {
......
...@@ -85,6 +85,13 @@ class ProblemBuilderBaseTest(SeleniumXBlockTest, PopupCheckMixin): ...@@ -85,6 +85,13 @@ class ProblemBuilderBaseTest(SeleniumXBlockTest, PopupCheckMixin):
submit.click() submit.click()
self.wait_until_disabled(submit) self.wait_until_disabled(submit)
def click_choice(self, container, choice_text):
""" Click on the choice label with the specified text """
for label in container.find_elements_by_css_selector('.choices .choice label'):
if choice_text in label.text:
label.click()
break
class MentoringBaseTest(SeleniumBaseTest, PopupCheckMixin): class MentoringBaseTest(SeleniumBaseTest, PopupCheckMixin):
module_name = __name__ module_name = __name__
......
...@@ -50,13 +50,6 @@ class MessagesTest(ProblemBuilderBaseTest): ...@@ -50,13 +50,6 @@ class MessagesTest(ProblemBuilderBaseTest):
message_text = message_text[8:].lstrip() message_text = message_text[8:].lstrip()
self.assertEqual(MESSAGES[msg_type], message_text) self.assertEqual(MESSAGES[msg_type], message_text)
def click_choice(self, container, choice_text):
""" Click on the choice label with the specified text """
for label in container.find_elements_by_css_selector('.choices .choice label'):
if choice_text in label.text:
label.click()
break
@ddt.data( @ddt.data(
("One", COMPLETED), ("One", COMPLETED),
("Two", COMPLETED), ("Two", COMPLETED),
......
...@@ -24,7 +24,7 @@ import ddt ...@@ -24,7 +24,7 @@ import ddt
from mock import patch, Mock from mock import patch, Mock
from problem_builder import MentoringBlock from problem_builder import MentoringBlock
from .base_test import MentoringBaseTest from .base_test import MentoringBaseTest, ProblemBuilderBaseTest
# Classes ########################################################### # Classes ###########################################################
...@@ -292,3 +292,35 @@ class QuestionnaireBlockAprosThemeTest(QuestionnaireBlockTest): ...@@ -292,3 +292,35 @@ class QuestionnaireBlockAprosThemeTest(QuestionnaireBlockTest):
Test MRQ/MCQ questions without the LMS theme which is on by default. Test MRQ/MCQ questions without the LMS theme which is on by default.
""" """
pass pass
@ddt.ddt
class ProblemBuilderQuestionnaireBlockTest(ProblemBuilderBaseTest):
def _get_choice_feedback_popup(self, mentoring, choice_index):
choices = mentoring.find_elements_by_css_selector(".choices-list .choice")
target_choice = choices[choice_index]
return target_choice.find_element_by_css_selector(".choice-tips")
def _get_messages_element(self, mentoring):
return mentoring.find_element_by_css_selector('.messages')
@ddt.data(("One", 0), ("Two", 1))
@ddt.unpack
def test_persists_feedback_on_page_reload(self, choice_value, choice_index):
mentoring = self.load_scenario("messages.xml", {"max_attempts": 1})
self.click_choice(mentoring, choice_value)
self.click_submit(mentoring)
feedback_popup = self._get_choice_feedback_popup(mentoring, choice_index)
messages = self._get_messages_element(mentoring)
self.assertTrue(feedback_popup.is_displayed())
self.assertTrue(messages.is_displayed())
# now, reload the page
mentoring = self.go_to_view("student_view")
feedback_popup = self._get_choice_feedback_popup(mentoring, choice_index)
messages = self._get_messages_element(mentoring)
self.assertTrue(feedback_popup.is_displayed())
self.assertTrue(messages.is_displayed())
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