Skip to content

Commit

Permalink
Added test to ensure snippet name is displayed when plugin is added t…
Browse files Browse the repository at this point in the history
…o a page
  • Loading branch information
Bernardvdv committed Jan 7, 2022
1 parent b0a0559 commit 95600b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
Unreleased
==========

* fix: Snippet plugin added to a page now displays name instead of ID

4.0.0.dev2 (2021-12-22)
=======================
Expand Down
4 changes: 4 additions & 0 deletions djangocms_snippet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class SnippetPtr(CMSPlugin):

search_fields = ['snippet__html'] if SEARCH_ENABLED else []

def get_short_description(self):
snippet_label = SnippetGrouper.objects.filter(pk=self.snippet_grouper.pk).first()
return snippet_label

class Meta:
verbose_name = _('Snippet Ptr')
verbose_name_plural = _('Snippet Ptrs')
20 changes: 19 additions & 1 deletion tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from cms.api import add_plugin, create_page
from cms.models import PageContent
from cms.test_utils.testcases import CMSTestCase
from cms.toolbar.utils import get_object_edit_url
from cms.toolbar.utils import get_object_edit_url, get_object_structure_url

from djangocms_snippet.models import Snippet, SnippetGrouper
from djangocms_versioning.models import Version
Expand Down Expand Up @@ -290,3 +290,21 @@ def test_published_snippet_and_page_live_url_rendering(self):

self.assertContains(response, "<p>Published snippet</p>")
self.assertNotIn("Draft snippet", str(response.content))

def test_correct_name_is_displayed_for_snippet_component_on_page(self):
"""
If a component is added to the page, it should show the snippet name and not ID
"""
add_plugin(
self.draft_pagecontent.placeholders.get(slot="content"),
"SnippetPlugin",
self.language,
snippet_grouper=self.draft_snippet.snippet_grouper,
)

# Request structure endpoint on page
request_url = get_object_structure_url(self.draft_pagecontent, "en")
with self.login_user_context(self.superuser):
response = self.client.get(request_url)

self.assertContains(response, "<strong>Snippet</strong> plugin_snippet</span>")

0 comments on commit 95600b1

Please sign in to comment.