fix: revert discussion xblock from MFE view to legacy view. (#30141)

Co-authored-by: SaadYousaf <saadyousaf@A006-00314.local>
This commit is contained in:
Saad Yousaf
2022-03-30 11:31:45 +05:00
committed by GitHub
parent 4a7719e73f
commit fd60d8c8cf
2 changed files with 7 additions and 55 deletions

View File

@@ -12,9 +12,7 @@ import uuid
from unittest import mock
import ddt
from django.test import override_settings
from django.urls import reverse
from edx_toggles.toggles.testutils import override_waffle_flag
from opaque_keys.edx.keys import CourseKey
from web_fragments.fragment import Fragment
from xblock.field_data import DictFieldData
@@ -26,7 +24,6 @@ from xmodule.modulestore.tests.factories import ItemFactory, ToyCourseFactory
from lms.djangoapps.course_api.blocks.tests.helpers import deserialize_usage_key
from lms.djangoapps.courseware.module_render import get_module_for_descriptor_internal
from lms.djangoapps.courseware.tests.helpers import XModuleRenderingTestBase
from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
@@ -308,34 +305,6 @@ class TestXBlockInCourse(SharedModuleStoreTestCase):
assert 'data-user-create-comment="false"' in html
assert 'data-user-create-subcomment="false"' in html
@override_settings(DISCUSSIONS_MICROFRONTEND_URL="http://test.url")
@override_waffle_flag(ENABLE_DISCUSSIONS_MFE, True)
def test_embed_mfe_in_course(self):
"""
Test that the xblock embeds the MFE UI when the flag is enabled
"""
discussion_xblock = get_module_for_descriptor_internal(
user=self.user,
descriptor=self.discussion,
student_data=mock.Mock(name='student_data'),
course_id=self.course.id,
track_function=mock.Mock(name='track_function'),
request_token='request_token',
)
fragment = discussion_xblock.render('student_view')
html = fragment.content
self.assertInHTML(
"""
<iframe
id='discussions-mfe-tab-embed'
title='Discussions'
src='http://test.url/edX/toy/2012_Fall/topics/test_discussion_xblock_id'
/>
""",
html,
)
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_discussion_render_successfully_with_orphan_parent(self, default_store):
"""
@@ -431,14 +400,13 @@ class TestXBlockQueryLoad(SharedModuleStoreTestCase):
discussion_target='Target Discussion',
))
# 7 queries are required to do first discussion xblock render:
# 4 queries are required to do first discussion xblock render:
# * split_modulestore_django_splitmodulestorecourseindex x2
# * waffle_utils_wafflecourseoverridemodel
# * waffle_utils_waffleorgoverridemodel
# * waffle_flag
# * django_comment_client_role
# * lms_xblock_xblockasidesconfig
num_queries = 7
num_queries = 4
for discussion in discussions:
discussion_xblock = get_module_for_descriptor_internal(
user=user,
@@ -451,9 +419,9 @@ class TestXBlockQueryLoad(SharedModuleStoreTestCase):
with self.assertNumQueries(num_queries):
fragment = discussion_xblock.render('student_view')
# Permissions are cached, so only 1 query required for subsequent renders
# to check the waffle flag
num_queries = 1
# Permissions are cached, so no queries required for subsequent renders
num_queries = 0
html = fragment.content
assert 'data-user-create-comment="false"' in html

View File

@@ -169,22 +169,6 @@ class DiscussionXBlock(XBlock, StudioEditableXBlockMixin, XmlParserMixin): # li
Renders student view for LMS.
"""
fragment = Fragment()
mfe_url = get_discussions_mfe_topic_url(self.course_key, self.discussion_id)
if ENABLE_DISCUSSIONS_MFE.is_enabled(self.course_key) and mfe_url:
fragment.add_content(HTML(
"<iframe id='discussions-mfe-tab-embed' src='{src}' title='{title}'></iframe>"
).format(src=mfe_url, title=_("Discussions")))
fragment.add_css(
"""
#discussions-mfe-tab-embed {
width: 100%;
height: 800px;
border: none;
}
"""
)
return fragment
self.add_resource_urls(fragment)
login_msg = ''