Skip to content

Commit

Permalink
Merge branch 'main' into generic-index-page-CMS-180
Browse files Browse the repository at this point in the history
  • Loading branch information
kacperpONS authored Jan 24, 2025
2 parents 5b538cd + 49f95e6 commit ba22f44
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions cms/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ArticleSeriesPage(RoutablePageMixin, Page):
subpage_types: ClassVar[list[str]] = ["StatisticalArticlePage"]
preview_modes: ClassVar[list[str]] = [] # Disabling the preview mode due to it being a container page.
page_description = _("A container for statistical article series.")
exclude_from_breadcrumbs = True

content_panels: ClassVar[list["Panel"]] = [
*Page.content_panels,
Expand Down
18 changes: 18 additions & 0 deletions cms/articles/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ def test_cite_this_page_is_not_shown_when_unticked(self):
response = self.client.get(self.basic_page_url)
self.assertNotContains(response, expected)

def test_breadcrumb_doesnt_containt_series_url(self):
response = self.client.get(self.basic_page_url)
# confirm that current breadcrumb is there
article_series = self.basic_page.get_parent()
self.assertNotContains(
response,
f'<a class="ons-breadcrumbs__link" href="{article_series.url}">{article_series.title}</a>',
html=True,
)

# confirm that current breadcrumb points to the parent page
topics_page = article_series.get_parent()
self.assertContains(
response,
f'<a class="ons-breadcrumbs__link" href="{topics_page.url}">{topics_page.title}</a>',
html=True,
)

@override_settings(IS_EXTERNAL_ENV=True)
def test_load_in_external_env(self):
"""Test the page loads in external env."""
Expand Down
6 changes: 2 additions & 4 deletions cms/jinja2/templates/components/navigation/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

{% set breadcrumbs=[] %}

{% for ancestor_page in page.get_ancestors() %}
{% for ancestor_page in page.get_ancestors().specific().defer_streamfields() %}
{% if not ancestor_page.is_root() %}
{% if ancestor_page.depth <= 2 %}
{% do breadcrumbs.append({"url": "/", "text": _("Home")}) %}
{% else %}
{% elif not ancestor_page.exclude_from_breadcrumbs %}
{% do breadcrumbs.append({"url": pageurl(ancestor_page), "text": ancestor_page.title}) %}
{% endif %}
{% endif %}
{% endfor %}

{% do breadcrumbs.append({"text": page.title}) %}
{# fmt:off #}
{{
onsBreadcrumbs({
Expand Down
7 changes: 7 additions & 0 deletions cms/jinja2/templates/pages/release_index.html
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{% extends "templates/base_page.html" %}
{% block header_area %}
<div class="ons-container">
<h1 class="ons-u-fs-3xl common-header__heading">
{{ page.title }}
</h1>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions functional_tests/features/home_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Feature: There is a default home page
Scenario: External user can see the homepage
When An external user navigates to the ONS beta site homepage
Then they can see the beta homepage
And they cannot see the breadcrumbs
2 changes: 2 additions & 0 deletions functional_tests/features/information_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ Feature: A general use information page
And the user clicks publish page
And the user clicks "View Live" on the publish confirmation banner
Then the new information page with the added content is displayed
And the user can see the breadcrumbs

1 change: 1 addition & 0 deletions functional_tests/features/release_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Feature: CMS users can draft, edit, and publish release pages
And the user clicks publish page
And the user clicks "View Live" on the publish confirmation banner
Then the new published release page with the example content is displayed
And the user can see the breadcrumbs
13 changes: 13 additions & 0 deletions functional_tests/steps/breadcrumb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from behave import then # pylint: disable=no-name-in-module
from behave.runner import Context
from playwright.sync_api import expect


@then("they cannot see the breadcrumbs")
def user_does_not_see_breadcrumbs_on_the_page(context: Context) -> None:
expect(context.page.get_by_label("Breadcrumbs")).not_to_be_visible()


@then("the user can see the breadcrumbs")
def user_does_see_breadcrumbs_on_the_page(context: Context) -> None:
expect(context.page.get_by_label("Breadcrumbs")).to_be_visible()

0 comments on commit ba22f44

Please sign in to comment.