fix: Render Word cloud block editor in libraries [FC-0076] (#36199)
* fix: Render Word cloud and conditional block editor - The xmodule-type to render is MetadataOnlyEditingDescriptor - The xmodule type `MetadataOnlyEditingDescriptor` renders a `<div>` with the block metadata in the `data-metadata` attribute. But is necessary to call `XBlockEditorView.xblockReady()` to run the scripts to build the editor using the metadata. - To call XBlockEditorView.xblockReady() we need a specific require.config * fix: Adding save and cancel button * fix: save with studio_submit of conditional_block and word_cloud_block * test: Tests for studio_submit of conditional and word cloud * revert: Delete studio_submit of conditional block. It is not supported * style: Fix lint --------- Co-authored-by: Navin Karkera <navin@opencraft.com>
This commit is contained in:
@@ -6,6 +6,7 @@ from unittest.mock import Mock
|
||||
from django.test import TestCase
|
||||
from fs.memoryfs import MemoryFS
|
||||
from lxml import etree
|
||||
from webob import Request
|
||||
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
|
||||
from webob.multidict import MultiDict
|
||||
from xblock.field_data import DictFieldData
|
||||
@@ -115,3 +116,29 @@ class WordCloudBlockTest(TestCase):
|
||||
{'content_type': 'Word Cloud',
|
||||
'content': {'display_name': 'Word Cloud Block',
|
||||
'instructions': 'Enter some random words that comes to your mind'}}
|
||||
|
||||
def test_studio_submit_handler(self):
|
||||
"""
|
||||
Test studio_submint handler
|
||||
"""
|
||||
TEST_SUBMIT_DATA = {
|
||||
'display_name': "New Word Cloud",
|
||||
'instructions': "This is a Test",
|
||||
'num_inputs': 5,
|
||||
'num_top_words': 10,
|
||||
'display_student_percents': 'False',
|
||||
}
|
||||
module_system = get_test_system()
|
||||
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())
|
||||
body = json.dumps(TEST_SUBMIT_DATA)
|
||||
request = Request.blank('/')
|
||||
request.method = 'POST'
|
||||
request.body = body.encode('utf-8')
|
||||
res = block.handle('studio_submit', request)
|
||||
assert json.loads(res.body.decode('utf8')) == {'result': 'success'}
|
||||
|
||||
assert block.display_name == TEST_SUBMIT_DATA['display_name']
|
||||
assert block.instructions == TEST_SUBMIT_DATA['instructions']
|
||||
assert block.num_inputs == TEST_SUBMIT_DATA['num_inputs']
|
||||
assert block.num_top_words == TEST_SUBMIT_DATA['num_top_words']
|
||||
assert block.display_student_percents == (TEST_SUBMIT_DATA['display_student_percents'] == "True")
|
||||
|
||||
@@ -315,6 +315,26 @@ class _BuiltInWordCloudBlock( # pylint: disable=abstract-method
|
||||
|
||||
return xblock_body
|
||||
|
||||
@XBlock.json_handler
|
||||
def studio_submit(self, submissions, suffix=''): # pylint: disable=unused-argument
|
||||
"""
|
||||
Change the settings for this XBlock given by the Studio user
|
||||
"""
|
||||
if 'display_name' in submissions:
|
||||
self.display_name = submissions['display_name']
|
||||
if 'instructions' in submissions:
|
||||
self.instructions = submissions['instructions']
|
||||
if 'num_inputs' in submissions:
|
||||
self.num_inputs = submissions['num_inputs']
|
||||
if 'num_top_words' in submissions:
|
||||
self.num_top_words = submissions['num_top_words']
|
||||
if 'display_student_percents' in submissions:
|
||||
self.display_student_percents = submissions['display_student_percents'] == 'True'
|
||||
|
||||
return {
|
||||
'result': 'success',
|
||||
}
|
||||
|
||||
|
||||
WordCloudBlock = (
|
||||
_ExtractedWordCloudBlock if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK
|
||||
|
||||
Reference in New Issue
Block a user