From 6c0e638c9a276357c797f6c8bd5eb43699be3ffd Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Fri, 23 Feb 2024 16:56:07 +0000 Subject: [PATCH] Restore icon in views that use slim_header.html Previously removed in 8a7dd1f5a1272f3701cde369c3ea314baec1f2ca and 663f9603cad34915d49789aec2aa7ac1b1b377df --- .../templates/wagtailadmin/generic/base.html | 2 +- .../templates/wagtailadmin/generic/form.html | 1 + .../shared/headers/slim_header.html | 3 +- wagtail/snippets/tests/test_snippets.py | 9 ++++- wagtail/snippets/tests/test_viewset.py | 36 ++++++++++--------- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/wagtail/admin/templates/wagtailadmin/generic/base.html b/wagtail/admin/templates/wagtailadmin/generic/base.html index d6bc1bcb7f..943100e4e5 100644 --- a/wagtail/admin/templates/wagtailadmin/generic/base.html +++ b/wagtail/admin/templates/wagtailadmin/generic/base.html @@ -17,7 +17,7 @@ {% endfragment %} {# Ensure all necessary variables are passed explicitly here #} - {% include "wagtailadmin/shared/headers/slim_header.html" with breadcrumbs_items=breadcrumbs_items side_panels=side_panels history_url=history_url title=header_title search_url=index_results_url search_form=search_form filters=filters actions=actions only %} + {% include "wagtailadmin/shared/headers/slim_header.html" with breadcrumbs_items=breadcrumbs_items side_panels=side_panels history_url=history_url title=header_title search_url=index_results_url search_form=search_form filters=filters actions=actions icon_name=header_icon only %} {% endif %} {% endblock %} {% block main_header %} diff --git a/wagtail/admin/templates/wagtailadmin/generic/form.html b/wagtail/admin/templates/wagtailadmin/generic/form.html index 979c88ac59..e32e178887 100644 --- a/wagtail/admin/templates/wagtailadmin/generic/form.html +++ b/wagtail/admin/templates/wagtailadmin/generic/form.html @@ -6,6 +6,7 @@ {% if breadcrumbs_items %}

+ {% icon classname="w-header__glyph" name=header_icon %} {{ page_subtitle }}

diff --git a/wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html b/wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html index 2f7b42d89e..3f729a5cbe 100644 --- a/wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html +++ b/wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html @@ -11,6 +11,7 @@ - `search_url` - URL to the search view, should respond with a partial template for the results - `search_form` - form to be rendered for search - `filters` - filters to be rendered + - `icon_name` - name of the icon to be used in the header When including this template, use the `only` parameter whenever possible to ensure that the above variables are indeed the only ones needed for this @@ -40,7 +41,7 @@ {% block breadcrumbs %} {% if breadcrumbs_items %} - {% breadcrumbs breadcrumbs_items %} + {% breadcrumbs breadcrumbs_items icon_name=icon_name %} {% endif %} {% endblock %} diff --git a/wagtail/snippets/tests/test_snippets.py b/wagtail/snippets/tests/test_snippets.py index 74cdaba331..5c76aede47 100644 --- a/wagtail/snippets/tests/test_snippets.py +++ b/wagtail/snippets/tests/test_snippets.py @@ -2410,7 +2410,14 @@ class TestEditDraftStateSnippet(BaseTestSnippetEditView): # Should use the latest draft content for the title self.assertContains( response, - '

Draft-enabled Bar, In Draft

', + """ +

+ + Draft-enabled Bar, In Draft +

+ """, html=True, ) diff --git a/wagtail/snippets/tests/test_viewset.py b/wagtail/snippets/tests/test_viewset.py index 05058c3a95..e3addd7aa4 100644 --- a/wagtail/snippets/tests/test_viewset.py +++ b/wagtail/snippets/tests/test_viewset.py @@ -69,8 +69,6 @@ class BaseSnippetViewSetTests(WagtailTestUtils, TestCase): class TestCustomIcon(BaseSnippetViewSetTests): - # TODO: decide what to do with this test, since the new designs after - # Universal Listings and unified breadcrumbs/header don't have icons model = FullFeaturedSnippet def setUp(self): @@ -84,26 +82,28 @@ class TestCustomIcon(BaseSnippetViewSetTests): def test_get_views(self): pk = quote(self.object.pk) views = [ - # TODO: Some of these views have been migrated to use the slim_header - # only, so there is no header_icon anymore. - # ("list", []), - # ("add", []), - # ("edit", [pk]), - # ("delete", [pk]), - # ("usage", [pk]), - ("unpublish", [pk]), - ("workflow_history", [pk]), - # ("revisions_revert", [pk, self.revision_1.id]), - ("revisions_compare", [pk, self.revision_1.id, self.revision_2.id]), - ("revisions_unschedule", [pk, self.revision_2.id]), + ("list", [], "headers/slim_header.html"), + ("add", [], "headers/slim_header.html"), + ("edit", [pk], "headers/slim_header.html"), + ("delete", [pk], "header.html"), + ("usage", [pk], "headers/slim_header.html"), + ("unpublish", [pk], "header.html"), + ("workflow_history", [pk], "header.html"), + ("revisions_revert", [pk, self.revision_1.id], "headers/slim_header.html"), + ( + "revisions_compare", + [pk, self.revision_1.id, self.revision_2.id], + "header.html", + ), + ("revisions_unschedule", [pk, self.revision_2.id], "header.html"), ] - for view_name, args in views: + for view_name, args, header in views: with self.subTest(view_name=view_name): response = self.client.get(self.get_url(view_name, args)) self.assertEqual(response.status_code, 200) self.assertEqual(response.context["header_icon"], "cog") self.assertContains(response, "icon icon-cog", count=1) - self.assertTemplateUsed(response, "wagtailadmin/shared/header.html") + self.assertTemplateUsed(response, f"wagtailadmin/shared/{header}") def test_get_history(self): response = self.client.get(self.get_url("history", [quote(self.object.pk)])) @@ -112,6 +112,10 @@ class TestCustomIcon(BaseSnippetViewSetTests): response, "wagtailadmin/shared/headers/slim_header.html", ) + # History view icon is not configurable for consistency with pages + self.assertEqual(response.context["header_icon"], "history") + self.assertContains(response, "icon icon-history") + self.assertNotContains(response, "icon icon-cog") self.assertTemplateNotUsed(response, "wagtailadmin/shared/header.html") def test_get_workflow_history_detail(self):