Skip to content

Commit

Permalink
fix: float " " symbol in the preview_body (#32489)
Browse files Browse the repository at this point in the history
Co-authored-by: Edward Zarecor <ezarecor@tcril.org>
  • Loading branch information
DmytroAlipov and e0d authored Sep 5, 2023
1 parent bbd7e28 commit 1699d14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lms/djangoapps/discussion/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,9 @@ def get_unread_comment_count(self, obj):

def get_preview_body(self, obj):
"""
Returns a cleaned and truncated version of the thread's body to display in a
preview capacity.
Returns a cleaned version of the thread's body to display in a preview capacity.
"""
return strip_tags(self.get_rendered_body(obj)).replace('\n', ' ')
return strip_tags(self.get_rendered_body(obj)).replace('\n', ' ').replace('&nbsp;', ' ')

def get_close_reason(self, obj):
"""
Expand Down
15 changes: 15 additions & 0 deletions lms/djangoapps/discussion/rest_api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ def test_response_count_missing(self):
serialized = self.serialize(thread_data)
assert 'response_count' not in serialized

def test_get_preview_body(self):
"""
Test for the 'get_preview_body' method.
This test verifies that the 'get_preview_body' method returns a cleaned
version of the thread's body that is suitable for display as a preview.
The test specifically focuses on handling the presence of multiple
spaces within the body.
"""
thread_data = self.make_cs_content(
{"body": "<p>This is a test thread body with some text.</p>"}
)
serialized = self.serialize(thread_data)
assert serialized['preview_body'] == "This is a test thread body with some text."


@ddt.ddt
class CommentSerializerTest(SerializerTestMixin, SharedModuleStoreTestCase):
Expand Down

0 comments on commit 1699d14

Please sign in to comment.