Commit b3cb55c8 by Braden MacDonald

Fix JS error when display_submit is False

parent 8582e036
......@@ -83,11 +83,13 @@ function MentoringStandardView(runtime, element, mentoring) {
};
mentoring.initChildren(options);
mentoring.renderAttempts();
mentoring.renderDependency();
validateXBlock();
var submitPossible = submitDOM.length > 0;
if (submitPossible) {
mentoring.renderAttempts();
validateXBlock();
} // else display_submit is false and this is read-only
}
// validate all children
......
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014-2015 Harvard, edX & OpenCraft
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
import ddt
from .base_test import MentoringBaseTest
@ddt.ddt
class MultipleBlockTest(MentoringBaseTest):
"""
Test that multiple Problem Builder blocks can happily co-exist on a page.
"""
default_css_selector = 'div.vertical'
def test_answer_blocks(self, expect_answer=False):
"""
Make sure that the JavaScript is working fine even though there are many blocks on the
page. In this test we check the answer blocks.
"""
vertical = self.go_to_page("Multiple Problem Builders")
blocks = vertical.find_elements_by_css_selector('.mentoring')
block_a = blocks[0]
self.assertIn("First", block_a.text)
block_b = blocks[1]
self.assertIn("Recap", block_b.text)
answer_input = block_a.find_element_by_css_selector("textarea")
answer_output = block_b.find_element_by_css_selector("blockquote")
if not expect_answer:
self.assertEqual(answer_input.text, "")
self.assertEqual(answer_output.text, "No answer yet.")
answer_input.send_keys('Hello there')
submit = block_a.find_element_by_css_selector('.submit input.input-main')
self.assertTrue(submit.is_enabled())
submit.click()
self.wait_until_disabled(submit)
self.test_answer_blocks(expect_answer=True)
else:
self.assertEqual(answer_input.text, 'Hello there')
self.assertEqual(answer_output.text, 'Hello there')
def test_mcq_mrq(self):
"""
Make sure that the JavaScript is working fine even though there are many blocks on the
page. In this test we check the MCQ and MRQ.
"""
vertical = self.go_to_page("Multiple Problem Builders")
blocks = vertical.find_elements_by_css_selector('.mentoring')
block_c = blocks[2]
self.assertIn("Third", block_c.text)
block_d = blocks[3]
self.assertIn("Fourth", block_d.text)
# Ensure that both of the blocks C and D are both working simultaneously:
for block in (block_c, block_d):
submit = block.find_element_by_css_selector('.submit input.input-main')
self.assertFalse(submit.is_enabled())
block.find_elements_by_css_selector('.choices .choice label')[0].click()
self.assertTrue(submit.is_enabled())
submit.click()
self.wait_until_disabled(submit)
<vertical_demo>
<html_demo>
<p>This tests that multiple Problem Builder blocks can happily co-exist on a page.</p>
</html_demo>
<problem-builder url_name="a" display_name="First: An Answer Block">
<pb-answer name="q-a" question="What is your goal?" />
</problem-builder>
<problem-builder url_name="b" display_name="Recap" display_submit="false">
<html_demo>
<p>Your answer should now appear here:</p>
</html_demo>
<pb-answer-recap name="q-a"/>
<html_demo>There should be no submit button here.</html_demo>
</problem-builder>
<problem-builder url_name="c" display_name="Third: An MCQ">
<pb-mcq name="mcq_3_1" question="Do you like this MCQ?" correct_choices='["yes"]'>
<pb-choice value="yes">Yes</pb-choice>
<pb-choice value="maybenot">Maybe not</pb-choice>
<pb-choice value="understand">I don't understand</pb-choice>
</pb-mcq>
</problem-builder>
<problem-builder url_name="d" display_name="Fourth: An MRQ Assessment" mode="assessment">
<pb-mrq name="mrq_1_1" question="What do you like in this MRQ?"
required_choices='["gracefulness","elegance","beauty"]'
>
<pb-choice value="elegance">Its elegance</pb-choice>
<pb-choice value="beauty">Its beauty</pb-choice>
<pb-choice value="gracefulness">Its gracefulness</pb-choice>
<pb-choice value="bugs">Its bugs</pb-choice>
</pb-mrq>
</problem-builder>
</vertical_demo>
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