Adding trailing_text to formulaequationinput
This commit is contained in:
@@ -1214,9 +1214,11 @@ class FormulaEquationInput(InputTypeBase):
|
||||
|
||||
Example:
|
||||
|
||||
<formulaequationinput size="50" label="Enter the equation for motion"/>
|
||||
<formulaequationinput size="50" label="Enter the equation for motion" />
|
||||
|
||||
options: size -- width of the textbox.
|
||||
trailing_text -- text to show after the input textbox when
|
||||
rendered, same as textline (useful for units)
|
||||
"""
|
||||
|
||||
template = "formulaequationinput.html"
|
||||
@@ -1231,6 +1233,7 @@ class FormulaEquationInput(InputTypeBase):
|
||||
Attribute('size', '20'),
|
||||
Attribute('inline', False),
|
||||
Attribute('label', ''),
|
||||
Attribute('trailing_text', ''),
|
||||
]
|
||||
|
||||
def _extra_context(self):
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
size="${size}"
|
||||
% endif
|
||||
/>
|
||||
${trailing_text | h}
|
||||
|
||||
<span class="status" id="${id}_status" data-tooltip="${status.display_tooltip}">
|
||||
<span class="sr">
|
||||
|
||||
@@ -486,6 +486,7 @@ class FormulaEquationInputTemplateTest(TemplateTestCase):
|
||||
'label': 'test',
|
||||
'previewer': 'file.js',
|
||||
'reported_status': 'REPORTED_STATUS',
|
||||
'trailing_text': None,
|
||||
}
|
||||
super(FormulaEquationInputTemplateTest, self).setUp()
|
||||
|
||||
|
||||
@@ -1126,9 +1126,53 @@ class FormulaEquationTest(unittest.TestCase):
|
||||
'size': self.size,
|
||||
'previewer': '/dummy-static/js/capa/src/formula_equation_preview.js',
|
||||
'inline': False,
|
||||
'trailing_text': '',
|
||||
}
|
||||
self.assertEqual(context, expected)
|
||||
|
||||
def test_trailing_text_rendering(self):
|
||||
"""
|
||||
Verify that the render context matches the expected render context with trailing_text
|
||||
"""
|
||||
size = "42"
|
||||
# store (xml_text, expected)
|
||||
trailing_text = []
|
||||
# standard trailing text
|
||||
trailing_text.append(('m/s', 'm/s'))
|
||||
# unicode trailing text
|
||||
trailing_text.append((u'\xc3', u'\xc3'))
|
||||
# html escaped trailing text
|
||||
# this is the only one we expect to change
|
||||
trailing_text.append(('a < b', 'a < b'))
|
||||
|
||||
for xml_text, expected_text in trailing_text:
|
||||
xml_str = u"""<formulaequationinput id="prob_1_2"
|
||||
size="{size}"
|
||||
trailing_text="{tt}"
|
||||
/>""".format(size=size, tt=xml_text)
|
||||
|
||||
element = etree.fromstring(xml_str)
|
||||
|
||||
state = {'value': 'x^2+1/2', }
|
||||
the_input = lookup_tag('formulaequationinput')(test_capa_system(), element, state)
|
||||
|
||||
context = the_input._get_render_context() # pylint: disable=protected-access
|
||||
|
||||
expected = {
|
||||
'STATIC_URL': '/dummy-static/',
|
||||
'id': 'prob_1_2',
|
||||
'value': 'x^2+1/2',
|
||||
'status': inputtypes.Status('unanswered'),
|
||||
'label': '',
|
||||
'msg': '',
|
||||
'size': size,
|
||||
'previewer': '/dummy-static/js/capa/src/formula_equation_preview.js',
|
||||
'inline': False,
|
||||
'trailing_text': expected_text,
|
||||
}
|
||||
|
||||
self.assertEqual(context, expected)
|
||||
|
||||
def test_formcalc_ajax_sucess(self):
|
||||
"""
|
||||
Verify that using the correct dispatch and valid data produces a valid response
|
||||
|
||||
Reference in New Issue
Block a user