Commit 25063576 by E. Kolpakov

Added boilerplate parameter for Nested blocks spec + test

parent 817791ed
......@@ -355,7 +355,7 @@ class XBlockWithNested(StudioContainerWithNestedXBlocksMixin, XBlock):
def allowed_nested_blocks(self):
return [
EditableXBlock,
NestedXBlockSpec(FancyBlockShim, single_instance=True)
NestedXBlockSpec(FancyBlockShim, single_instance=True, boilerplate="fancy-boiler")
]
......@@ -378,12 +378,13 @@ class StudioContainerWithNestedXBlocksTest(StudioContainerWithNestedXBlocksBaseT
self.addCleanup(patcher.stop)
def _check_button(self, button, category, label, single, disabled, disabled_reason=''):
def _check_button(self, button, category, label, single, disabled, disabled_reason='', boilerplate=None):
self.assertEqual(button.get_attribute('data-category'), category)
self.assertEqual(button.text, label)
self.assertEqual(button.get_attribute('data-single-instance'), str(single).lower())
self._assert_disabled(button, disabled)
self.assertEqual(button.get_attribute('title'), disabled_reason)
self.assertEqual(button.get_attribute('data-boilerplate'), boilerplate)
def _assert_disabled(self, button, disabled):
if disabled:
......@@ -405,7 +406,9 @@ class StudioContainerWithNestedXBlocksTest(StudioContainerWithNestedXBlocksBaseT
self.assertEqual(len(add_buttons), 2)
button_editable, button_fancy = add_buttons
self._check_button(button_editable, EditableXBlock.CATEGORY, EditableXBlock.STUDIO_LABEL, False, False)
self._check_button(button_fancy, FancyBlockShim.CATEGORY, FancyBlockShim.STUDIO_LABEL, True, False)
self._check_button(
button_fancy, FancyBlockShim.CATEGORY, FancyBlockShim.STUDIO_LABEL, True, False, boilerplate="fancy-boiler"
)
@XBlock.register_temp_plugin(XBlockWithDisabledNested, "nested")
def test_author_edit_view_nested_with_disabled(self):
......
......@@ -335,11 +335,12 @@ class NestedXBlockSpec(object):
Class that allows detailed specification of allowed nested XBlocks. For use with
StudioContainerWithNestedXBlocksMixin.allowed_nested_blocks
"""
def __init__(self, block, single_instance=False, disabled=False, disabled_reason=None):
def __init__(self, block, single_instance=False, disabled=False, disabled_reason=None, boilerplate=None):
self._block = block
self._single_instance = single_instance
self._disabled = disabled
self._disabled_reason = disabled_reason
self._boilerplate = boilerplate
@property
def category(self):
......@@ -371,6 +372,11 @@ class NestedXBlockSpec(object):
"""
return self._disabled_reason
@property
def boilerplate(self):
""" Boilerplate - if not None and not empty used as data-boilerplate attribute value """
return self._boilerplate
class XBlockWithPreviewMixin(object):
"""
......
......@@ -11,6 +11,7 @@
{% if block_spec.disabled %}
disabled="disabled" title="{{ block_spec.disabled_reason }}"
{% endif %}
{% if block_spec.boilerplate %} data-boilerplate="{{ block_spec.boilerplate }}" {% endif %}
>
{{ block_spec.label }}
</a>
......
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