diff --git a/common/lib/xmodule/xmodule/assets/library_content/public/js/library_content_reset.js b/common/lib/xmodule/xmodule/assets/library_content/public/js/library_content_reset.js index 81eb7d2105e7..e985d3c2a692 100644 --- a/common/lib/xmodule/xmodule/assets/library_content/public/js/library_content_reset.js +++ b/common/lib/xmodule/xmodule/assets/library_content/public/js/library_content_reset.js @@ -4,8 +4,14 @@ function LibraryContentReset(runtime, element) { e.preventDefault(); $.post({ url: runtime.handlerUrl(element, 'reset_selected_children'), - success() { - location.reload(); + success(data) { + edx.HtmlUtils.setHtml(element, edx.HtmlUtils.HTML(data)); + // Rebind the reset button for the block + XBlock.initializeBlock(element); + // Render the new set of problems (XBlocks) + $(".xblock", element).each(function(i, child) { + XBlock.initializeBlock(child); + }); }, }); }); diff --git a/common/lib/xmodule/xmodule/library_content_module.py b/common/lib/xmodule/xmodule/library_content_module.py index 29e772f8bee1..5e54ea9b201b 100644 --- a/common/lib/xmodule/xmodule/library_content_module.py +++ b/common/lib/xmodule/xmodule/library_content_module.py @@ -375,7 +375,7 @@ def reset_selected_children(self, _, __): block.save() self.selected = [] - return Response() + return Response(json.dumps(self.student_view({}).content)) def _get_selected_child_blocks(self): """ diff --git a/common/lib/xmodule/xmodule/tests/test_library_content.py b/common/lib/xmodule/xmodule/tests/test_library_content.py index a2d057b984c3..748a962f1d65 100644 --- a/common/lib/xmodule/xmodule/tests/test_library_content.py +++ b/common/lib/xmodule/xmodule/tests/test_library_content.py @@ -4,7 +4,7 @@ Higher-level tests are in `cms/djangoapps/contentstore/tests/test_libraries.py`. """ import ddt -from unittest.mock import Mock, patch +from unittest.mock import MagicMock, Mock, patch from bson.objectid import ObjectId from fs.memoryfs import MemoryFS @@ -405,13 +405,19 @@ def test_reset_selected_children_capa_blocks(self, allow_resetting_children, max self._create_capa_problems() self.lc_block.refresh_children() self.lc_block = self.store.get_item(self.lc_block.location) + # Mock the student view to return an empty dict to be returned as response + self.lc_block.student_view = MagicMock() + self.lc_block.student_view.return_value.content = {} with patch.object(ProblemBlock, 'reset_problem', return_value={'success': True}) as reset_problem: response = self.lc_block.reset_selected_children(None, None) if allow_resetting_children: + self.lc_block.student_view.assert_called_once_with({}) assert reset_problem.call_count == len(self.problem_types) assert response.status_code == status.HTTP_200_OK + assert response.content_type == "text/html" + assert response.body == b"{}" else: reset_problem.assert_not_called() assert response.status_code == status.HTTP_400_BAD_REQUEST