Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 58446be

Browse files
committedNov 23, 2022
Add byline support to Text Introductions
This commit adds support for bylines to the Text Introduction block in the same way that Item Introduction blocks support them. To avoid duplication, the common byline functionality has been pulled out into a new byline template (although not into a new Wagtail block). All three of the affected templates (byline, item introduction, text introduction) can be previewed using this repository's template debug functionality at these URLs: - http://localhost:8000/admin/template_debug/v1/byline/ - http://localhost:8000/admin/template_debug/v1/item_introduction/ - http://localhost:8000/admin/template_debug/v1/text_introduction/ Like Item Introduction bylines, Text Introduction bylines can have zero or more authors and an optional date. This commit also includes some minor cleanup around the way that item introduction blocks have been manually rendered on various page types. As far as I can tell this special handling is no longer needed, if it ever was. Affected page types and example pages to verify this: - BlogPage: http://localhost:8000/about-us/blog/why-were-modernizing-how-we-collect-credit-card-data/ - DocumentDetailPage: http://localhost:8000/compliance/supervisory-guidance/bulletin-phone-pay-fees/ - EnforcementActionPage: http://localhost:8000/enforcement/actions/capital-one-bank/ - LearnPage: http://localhost:8000/enforcement/information-industry-whistleblowers/privacy-act-statement/ - NewsroomPage: http://localhost:8000/about-us/newsroom/cfpb-issues-guidance-to-address-shoddy-investigation-practices-by-consumer-reporting-companies/ - HMDAHistoricDataPage: http://localhost:8000/data-research/hmda/historic-data/ This commit also adds a few new Python unit tests to validate the intended template rendering.
1 parent e71bfa2 commit 58446be

File tree

19 files changed

+379
-167
lines changed

19 files changed

+379
-167
lines changed
 

‎cfgov/hmda/jinja2/hmda/hmda-explorer.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{% import 'hmda-explorer-controls.html' as controls with context %}
44
{% import 'hmda-explorer-results.html' as results with context %}
55
{% import 'hmda-explorer-institutions.html' as institutions with context %}
6-
{% import 'organisms/item-introduction.html' as item_introduction with context %}
76
{% import 'templates/render_block.html' as render_block with context %}
87
{% import 'templates/streamfield-sidefoot.html' as streamfield_sidefoot with context %}
98

@@ -13,11 +12,7 @@
1312

1413
{% block content_main %}
1514
{% for block in page.header -%}
16-
{% if block.block_type == 'item_introduction' %}
17-
{{ item_introduction.render(block.value) }}
18-
{% else %}
19-
{{ render_block.render(block, loop.index) }}
20-
{% endif %}
15+
{{ render_block.render(block, loop.index) }}
2116
{%- endfor %}
2217

2318
<div class="hmda-historic-data" style="margin-top: -20px">

‎cfgov/jinja2/v1/_includes/article.html

+9-10
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,20 @@
3838

3939
<article class="post">
4040
<header>
41-
{% set data = {
42-
'category': page.categories.all(),
41+
{% with value = {
4342
'heading': page.title,
4443
'date': page.date_published,
45-
'has_social': True,
44+
'has_social': true,
4645
'social_options': { 'is_printable': true }
4746
} %}
47+
{% for block in page.header -%}
48+
{% if block.block_type == 'article_subheader' %}
49+
{% do value.update( { 'paragraph': block.value } ) %}
50+
{% endif %}
51+
{% endfor %}
4852

49-
{% for block in page.header -%}
50-
{% if block.block_type == 'article_subheader' %}
51-
{% do data.update({'paragraph': block.value}) %}
52-
{% endif %}
53-
{% endfor %}
54-
55-
{{ item_introduction.render(data) }}
53+
{% include 'organisms/item-introduction.html' with context %}
54+
{% endwith %}
5655
</header>
5756

5857
<div class="post_body">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{# ==========================================================================
2+
3+
Create a byline when given:
4+
5+
value.authors: List of author names.
6+
7+
value.date: Publication date.
8+
9+
========================================================================== #}
10+
11+
{%- macro render( value ) %}
12+
{%- if value.authors or value.date -%}
13+
<div class="a-byline">
14+
{% if value.authors %}
15+
<span class="byline">
16+
{%- for author in value.authors -%}
17+
{% if loop.first %}By {% elif loop.last %} and {% endif -%}
18+
{{ author }}
19+
{%- if loop.length > 2 and loop.index < loop.length %}, {% endif %}
20+
{%- endfor -%}
21+
</span>
22+
{% endif -%}
23+
24+
{% if value.authors and value.date -%}
25+
&ndash;
26+
{%- endif %}
27+
28+
{%- if value.date %}
29+
<span class="a-date">
30+
{% import 'macros/time.html' as time %}
31+
{{ time.render( value.date, { 'date': true } ) }}
32+
</span>
33+
{% endif %}
34+
</div>
35+
{%- endif %}
36+
{%- endmacro %}
37+
38+
39+
{%- if value %}
40+
41+
{% if page and not "authors" in value %}
42+
{% do value.update(
43+
{ "authors": page.authors.values_list( "name", flat=True ) }
44+
) %}
45+
{% endif %}
46+
47+
{{- render( value ) -}}
48+
49+
{% endif -%}

‎cfgov/jinja2/v1/_includes/macros/category-slug.html

+15-25
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,35 @@
99

1010
Render a category slug when given:
1111

12-
category: A string.
12+
category: A category slug, e.g. "press-release".
1313

14-
href (optional): If present creates a link with
15-
a path to which the category filter applies.
16-
For example, if the slug is used on a blog article
17-
then path should be '/about-us/blog/'.
18-
Remember to leverage vars.path instead of
19-
using the literal string '/about-us/blog/'.
20-
Path is used to create the filtered URL:
21-
{{ href }}?category={{ category }}
14+
href (optional): If present creates a link with
15+
a path to which the category filter applies.
16+
For example, if the slug is used on a blog article
17+
then path should be '/about-us/blog/'.
18+
Path is used to create the filtered URL:
19+
{{ href }}?categories={{ category }}
2220

2321
classes (optional): Space separated list of class names.
2422

25-
use_blog_category (optional): Whether to use the blog category filter or not.
26-
Defaults to false.
27-
2823
========================================================================== #}
2924

30-
{% macro render(category, href, classes='', use_blog_category=false) %}
25+
{% macro render( category, href, classes='' ) %}
3126
{% import 'macros/category-icon.html' as category_icon %}
3227

3328
{% if href %}
34-
{# TODO: Remove use_blog_category parameter when this element becomes atomic. #}
35-
{% if use_blog_category %}
36-
{% set href = href + '?blog_category=' + category | urlencode | replace('%20', '+') %}
37-
{% else %}
38-
{% set href = href + '?categories=' + category | urlencode | replace('%20', '+') %}
39-
{% endif %}
29+
{% set href = href + '?categories=' + category | urlencode %}
4030
{% endif %}
4131

42-
{% call _category_link(href, classes) %}
43-
{% set cat = category_label(category) or category %}
44-
{{ category_icon.render(cat) }}
32+
{% call _category_link( href, classes ) -%}
33+
{% set category_name = category_label( category ) or category %}
34+
{{- category_icon.render( category_name ) }}
4535
<span class="u-visually-hidden">Category:</span>
46-
{{ cat | safe }}
47-
{% endcall %}
36+
{{ category_name }}
37+
{%- endcall %}
4838
{% endmacro %}
4939

50-
{% macro _category_link(href, classes) %}
40+
{% macro _category_link( href, classes ) %}
5141
{% if href %}
5242
<a href="{{ href }}"
5343
class="a-heading a-heading__icon {{ classes }}">

‎cfgov/jinja2/v1/_includes/molecules/text-introduction.html

+17-40
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,56 @@
44

55
=========================================================================
66

7-
Description:
8-
97
Create a Text Introduction molecule.
10-
See [GHE]/flapjack/Modules-V1/wiki/Text-Introduction
118

12-
value: Object defined from a StreamField block.
9+
https://cfpb.github.io/design-system/patterns/text-introductions
1310

1411
value.eyebrow: (Optional) Text to display above heading.
1512

1613
value.heading: (Optional) String for heading text.
1714

18-
value.intro: (Optional) String for body introduction text.
15+
value.authors: (Optional) A list of author names to be included
16+
on a byline.
17+
18+
value.date: (Optional) A date to be included on a byline.
1919

20-
value.intro.source: TODO: add type and description.
20+
value.intro: (Optional) String for body introduction text.
2121

2222
value.body: (Optional) String for body text.
2323

24-
value.links: A tuple to create a list of links, containing:
24+
value.links: A list of links, containing:
2525

26-
value.links[i].text: (Optional) A string for the text of the link.
26+
value.links[i].text: A string for the text of the link.
2727

2828
value.links[i].url: A string for the URL of the link.
2929

3030
value.links[i].aria_label: (Optional) An aria-label for the link.
3131

32-
value.date: (Optional) A date to be included on a byline.
33-
3432
value.has_rule: Whether or not to render a rule line
3533
(border-bottom) at the bottom of the molecule.
3634

3735
========================================================================== #}
38-
{% set published_date = value.date %}
39-
{% set has_authors = page.authors.exists() %}
4036

41-
{% if value.eyebrow %}
37+
{% if value.eyebrow -%}
4238
<div class="eyebrow">{{ value.eyebrow }}</div>
43-
{% endif %}
44-
{% if value.heading %}
39+
{%- endif %}
40+
41+
{% if value.heading -%}
4542
<h1>{{ value.heading }}</h1>
46-
{% endif %}
43+
{%- endif %}
4744

48-
{% if published_date or has_authors %}
49-
<div class="meta">
50-
{% endif %}
51-
{% if has_authors %}
52-
<span class="byline">
53-
{%- for author in page.get_authors() -%}
54-
{% if loop.first %}By {% elif loop.last %}and {% endif %}
55-
{{ author.name }}
56-
{%- if loop.length > 2 and loop.index < loop.length %}, {% endif %}
57-
{% endfor %}
58-
&ndash;
59-
</span>
60-
{% endif %}
61-
{% if published_date %}
62-
<span class="a-date">
63-
{% import 'macros/time.html' as time %}
64-
{{ time.render(published_date, {'date':true}) }}
65-
</span>
66-
{% endif %}
67-
{% if published_date or has_authors %}
68-
</div>
69-
{% endif %}
45+
{% include 'atoms/byline.html' with context %}
7046

71-
{% if value.intro.source %}
47+
{% if value.intro -%}
7248
<div class="lead-paragraph">
7349
{{ value.intro | safe }}
7450
</div>
75-
{% endif %}
51+
{%- endif %}
7652

7753
{% if value.body %}
7854
{{ value.body | safe }}
7955
{% endif %}
56+
8057
{% for link in value.links %}
8158
{% if link.text %}
8259
{% if loop.first %}<ul class="m-list m-list__links">{% endif %}

‎cfgov/jinja2/v1/_includes/organisms/item-introduction.html

+50-49
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,73 @@
44

55
==========================================================================
66

7-
Description:
7+
Create an Item Introduction organism.
88

9-
Create an Item Introduction molecule.
10-
See [GHE]/flapjack/Modules-V1/wiki/Item-Introduction
9+
https://cfpb.github.io/design-system/patterns/item-introductions
1110

12-
value: An object with the following options for value.
11+
value.show_category: (Optional) Whether to show category.
1312

14-
value.show_category: Whether to show the category or not.
15-
value.heading: Heading text.
16-
value.paragraph.source: Body introduction text.
17-
value.authors: Array of author names and associated URLs.
13+
value.category: (Optional) Category to show above heading.
1814

19-
value.date: A datetime for the post.
20-
value.has_social: Whether to show the share icons or not.
21-
value.social_options: An object with options for the share icons
15+
value.category_url: (Optional) URL to link category to.
16+
17+
value.heading: Heading text.
18+
19+
value.paragraph: (Optional) Subheader paragraph.
20+
21+
value.authors: (Optional) A list of author names to be included
22+
on a byline.
23+
24+
value.date: (Optional) A date to be included on a byline.
25+
26+
value.has_social: Whether to show the share icons or not.
27+
28+
value.social_options: (Optional) Share icon options.
2229

2330
========================================================================== #}
2431

2532

2633
{% import 'molecules/social-media.html' as social_media with context %}
2734
{% import 'macros/category-slug.html' as category_slug %}
2835

29-
{% macro render(value) %}
30-
31-
{% set filter_page = page.get_filter_data() %}
32-
{% set filter_page_url = pageurl(filter_page) if filter_page else none %}
33-
{% set published_date = value.date %}
34-
{% set has_authors = page.authors.exists() %}
35-
{% set social_options = value.social_options or {} %}
36-
36+
{%- macro render( value ) %}
3737
<div class="o-item-introduction">
38-
{% if filter_page_url and page.categories.count() > 0 and value.show_category %}
39-
{{ category_slug.render(category=page.categories.first().name, href=filter_page_url) }}
40-
{% endif %}
38+
{% if value.show_category and value.category -%}
39+
{{ category_slug.render( value.category, href=value.category_url ) }}
40+
{%- endif %}
41+
4142
<h1>{{ value.heading | safe }}</h1>
4243

43-
{% if value.paragraph %}
44+
{% if value.paragraph -%}
4445
<div class="lead-paragraph">{{ value.paragraph | safe }}</div>
45-
{% endif %}
46+
{%- endif %}
4647

47-
{% if published_date or has_authors %}
48-
<div class="meta">
49-
{% endif %}
50-
{% if filter_page_url and has_authors %}
51-
<span class="byline">
52-
{%- for author in page.get_authors() -%}
53-
{% if loop.first %}By {% elif loop.last %}and {% endif %}
54-
{{ author.name }}
55-
{%- if loop.length > 2 and loop.index < loop.length %}, {% endif %}
56-
{% endfor %}
57-
&ndash;
58-
</span>
59-
{% endif %}
60-
{% if published_date %}
61-
<span class="a-date">
62-
{% import 'macros/time.html' as time %}
63-
{{ time.render(published_date, {'date':true}) }}
64-
</span>
48+
{% include 'atoms/byline.html' with context %}
49+
50+
{% if value.has_social -%}
51+
{{ social_media.render( value.social_options or {} ) }}
52+
{%- endif %}
53+
</div>
54+
{% endmacro -%}
55+
56+
{%- if value %}
57+
58+
{% if page %}
59+
{% if not "category" in value %}
60+
{% set category = page.categories.values_list("name", flat=True).first() %}
61+
{% if category %}
62+
{% do value.update( { "category": category } ) %}
63+
64+
{% set filter_page = page.get_filter_data() %}
65+
{% if filter_page %}
66+
{% do value.update(
67+
{ "category_url": pageurl( filter_page ) }
68+
) %}
69+
{% endif %}
6570
{% endif %}
66-
{% if published_date or has_authors %}
67-
</div>
6871
{% endif %}
72+
{% endif %}
6973

70-
{% if value.has_social %}
71-
{{ social_media.render(social_options) }}
72-
{% endif %}
73-
</div>
74+
{{- render( value ) -}}
7475

75-
{% endmacro %}
76+
{% endif -%}

‎cfgov/jinja2/v1/document-detail/index.html

+3-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@
99

1010
{% block content_main %}
1111
{% for block in page.header -%}
12-
{% if block.block_type == 'item_introduction' %}
13-
{% import 'organisms/item-introduction.html' as item_introduction with context %}
14-
{{ item_introduction.render(block.value) }}
15-
{% else %}
16-
<div class="block
17-
block__flush-top">
18-
{{ render_stream_child(block) }}
19-
</div>
20-
{% endif %}
12+
<div class="block block__flush-top">
13+
{{ render_stream_child(block) }}
14+
</div>
2115
{%- endfor %}
2216

2317
{% for block in page.content -%}

‎cfgov/jinja2/v1/enforcement-action/index.html

+3-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@
1010

1111
{% block content_main %}
1212
{% for block in page.header -%}
13-
{% if block.block_type == 'item_introduction' %}
14-
{% import 'organisms/item-introduction.html' as item_introduction with context %}
15-
{{ item_introduction.render(block.value) }}
16-
{% else %}
17-
<div class="block
18-
block__flush-top">
19-
{{ render_stream_child(block) }}
20-
</div>
21-
{% endif %}
13+
<div class="block block__flush-top">
14+
{{ render_stream_child(block) }}
15+
</div>
2216
{%- endfor %}
2317

2418
{% for block in page.content -%}

‎cfgov/jinja2/v1/learn-page/index.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{% extends 'layout-2-1.html' %}
22

3-
{% import 'organisms/item-introduction.html' as item_introduction with context %}
43
{% import 'templates/render_block.html' as render_block with context %}
54
{% import 'templates/streamfield-sidefoot.html' as streamfield_sidefoot with context %}
65

@@ -10,11 +9,7 @@
109

1110
{% block content_main %}
1211
{% for block in page.header -%}
13-
{% if block.block_type == 'item_introduction' %}
14-
{{ item_introduction.render(block.value) }}
15-
{% else %}
16-
{{ render_block.render(block, loop.index) }}
17-
{% endif %}
12+
{{ render_block.render(block, loop.index) }}
1813
{%- endfor %}
1914

2015
{% for block in page.content -%}

‎cfgov/unprocessed/css/organisms/item-introduction.less

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,25 @@
3535
*/
3636

3737
.o-item-introduction {
38-
margin-bottom: unit( @grid_gutter-width * 2 / @base-font-size-px, em );
38+
margin-bottom: unit(@grid_gutter-width * 2 / @base-font-size-px, em);
3939

4040
.short-desc {
41-
padding-bottom: unit( @grid_gutter-width / 2 / @base-font-size-px, em );
41+
padding-bottom: unit(@grid_gutter-width / 2 / @base-font-size-px, em);
4242
}
4343

4444
.lead-paragraph {
4545
margin-top: 0;
4646
}
4747

48-
.meta {
49-
margin-bottom: unit( @grid_gutter-width / @base-font-size-px, em );
48+
.a-byline {
49+
margin-bottom: unit(@grid_gutter-width / @base-font-size-px, em);
5050

5151
.byline {
5252
.heading-4();
5353
}
5454
}
5555
}
5656

57-
5857
/* topdoc
5958
name: EOF
6059
eof: true

‎cfgov/v1/atomic_elements/organisms.py

-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,6 @@ class ItemIntroduction(blocks.StructBlock):
721721
class Meta:
722722
icon = "form"
723723
template = "_includes/organisms/item-introduction.html"
724-
classname = "block__flush-top"
725724

726725

727726
class FilterableList(BaseExpandable):

‎cfgov/v1/jinja2/v1/template_debug.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<style>
88
.test-case {
99
margin-top: 20px;
10-
margin-bottom: 20px;
10+
margin-bottom: 40px;
1111
}
1212

1313
.test-case_link {

‎cfgov/v1/template_debug/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
from v1.views.template_debug import TemplateDebugView
44

5+
from .byline import byline_test_cases # noqa 401
56
from .call_to_action import call_to_action_test_cases # noqa 401
67
from .featured_content import featured_content_test_cases # noqa 401
78
from .heading import heading_test_cases # noqa 401
9+
from .item_introduction import item_introduction_test_cases # noqa 401
810
from .notification import notification_test_cases # noqa 401
11+
from .text_introduction import text_introduction_test_cases # noqa 401
912
from .video_player import video_player_test_cases # noqa 401
1013

1114

‎cfgov/v1/template_debug/byline.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from django.utils import timezone
2+
3+
4+
today = timezone.now().date()
5+
6+
7+
byline_test_cases = {
8+
"Empty": {},
9+
"Single author": {
10+
"authors": [
11+
"Bilbo Baggins",
12+
],
13+
},
14+
"Two authors": {
15+
"authors": [
16+
"Bilbo Baggins",
17+
"Frodo Baggins",
18+
],
19+
},
20+
"Three authors": {
21+
"authors": [
22+
"Bilbo Baggins",
23+
"Frodo Baggins",
24+
"Samwise Gamgee",
25+
],
26+
},
27+
"Author with date": {
28+
"authors": [
29+
"Bilbo Baggins",
30+
],
31+
"date": today,
32+
},
33+
"Date, no authors": {
34+
"date": today,
35+
},
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from django.utils import timezone
2+
3+
4+
today = timezone.now().date()
5+
6+
7+
item_introduction_defaults = {
8+
"heading": "Lorem ipsum dolor sit amet",
9+
"paragraph": (
10+
"<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco "
11+
"laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure "
12+
"dolor in reprehenderit in voluptate velit esse cillum dolore eu "
13+
"fugiat nulla pariatur.</p>"
14+
),
15+
"has_social": True,
16+
}
17+
18+
19+
category = {
20+
"show_category": True,
21+
"category": "press-release",
22+
"category_url": "/about-us/newsroom/",
23+
}
24+
25+
26+
byline = {
27+
"authors": ["Bilbo Baggins"],
28+
"date": today,
29+
}
30+
31+
32+
item_introduction_test_cases = {
33+
"Heading and paragraph": {},
34+
"Category": category,
35+
"Byline": byline,
36+
"Everything": {**category, **byline},
37+
"Customized social icons": {
38+
"social_options": {
39+
"is_printable": True,
40+
},
41+
},
42+
}
43+
44+
45+
for test_case in item_introduction_test_cases.values():
46+
for k, v in item_introduction_defaults.items():
47+
test_case.setdefault(k, v)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from django.utils import timezone
2+
3+
4+
today = timezone.now().date()
5+
6+
7+
text_introduction_defaults = {
8+
"intro": (
9+
"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do "
10+
"eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>"
11+
),
12+
"body": (
13+
"<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris"
14+
" nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in "
15+
"reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
16+
"pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
17+
"culpa qui officia deserunt mollit anim id est laborum.</p>"
18+
),
19+
}
20+
21+
22+
heading = {
23+
"heading": "Local hobbit finishes lengthy journey",
24+
}
25+
26+
27+
eyebrow = {
28+
"eyebrow": "Press Release",
29+
}
30+
31+
32+
byline = {
33+
"authors": ["Bilbo Baggins"],
34+
"date": today,
35+
}
36+
37+
38+
links = {
39+
"links": [
40+
{
41+
"text": "Click me",
42+
"url": "https://www.consumerfinance.gov/",
43+
"aria-label": "CFPB website",
44+
}
45+
],
46+
}
47+
48+
49+
text_introduction_test_cases = {
50+
"With heading": heading,
51+
"With heading and eyebrow": {**heading, **eyebrow},
52+
"With byline": byline,
53+
"With link": links,
54+
"With everything": {**heading, **eyebrow, **byline, **links},
55+
}
56+
57+
58+
for test_case in text_introduction_test_cases.values():
59+
for k, v in text_introduction_defaults.items():
60+
test_case.setdefault(k, v)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from django.test import TestCase
2+
3+
from wagtail.core.models import Site
4+
5+
from v1.atomic_elements.organisms import ItemIntroduction
6+
from v1.models import BlogPage, BrowseFilterablePage, CFGOVPageCategory
7+
8+
9+
class ItemIntroductionTests(TestCase):
10+
def test_renders_category_link(self):
11+
site_root = Site.objects.get(is_default_site=True).root_page
12+
13+
filter_page = BrowseFilterablePage(title="blog", slug="blog")
14+
site_root.add_child(instance=filter_page)
15+
16+
child_page = BlogPage(title="post", slug="post")
17+
child_page.categories.add(CFGOVPageCategory(name="press-release"))
18+
filter_page.add_child(instance=child_page)
19+
20+
block = ItemIntroduction()
21+
value = block.to_python(
22+
{
23+
"heading": "Heading",
24+
"show_category": True,
25+
}
26+
)
27+
html = block.render(value, context={"page": child_page})
28+
29+
self.assertIn("<h1>Heading</h1>", html)
30+
self.assertIn('<a href="/blog/?categories=press-release', html)
31+
self.assertIn("Press release", html)

‎cfgov/v1/tests/atomic_elements/test_molecules.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
TextIntroduction,
1515
)
1616
from v1.documents import FilterablePagesDocument
17-
from v1.models.browse_filterable_page import BrowseFilterablePage
18-
from v1.models.browse_page import BrowsePage
19-
from v1.models.landing_page import LandingPage
20-
from v1.models.learn_page import DocumentDetailPage, LearnPage
21-
from v1.models.sublanding_filterable_page import SublandingFilterablePage
22-
from v1.models.sublanding_page import SublandingPage
17+
from v1.models import (
18+
BrowseFilterablePage,
19+
BrowsePage,
20+
CFGOVPage,
21+
DocumentDetailPage,
22+
LandingPage,
23+
LearnPage,
24+
SublandingFilterablePage,
25+
SublandingPage,
26+
)
2327
from v1.tests.wagtail_pages.helpers import publish_page, save_new_page
2428

2529

@@ -244,6 +248,21 @@ def test_text_intro_with_heading_and_eyebrow_passes_validation(self):
244248
except StructBlockValidationError: # pragma: no cover
245249
self.fail("eyebrow with heading should not fail validation")
246250

251+
def test_render_without_page_does_not_show_authors(self):
252+
block = TextIntroduction()
253+
value = block.to_python({"heading": "Heading"})
254+
html = block.render(value=value)
255+
self.assertNotIn("By", html)
256+
257+
def test_render_with_page_pulls_authors(self):
258+
block = TextIntroduction()
259+
value = block.to_python({"heading": "Heading"})
260+
page = CFGOVPage()
261+
page.authors.add("Bilbo Baggins")
262+
page.authors.add("Frodo Baggins")
263+
html = block.render(value=value, context={"page": page})
264+
self.assertIn("By Bilbo Baggins and Frodo Baggins", html)
265+
247266

248267
class RSSFeedTests(TestCase):
249268
def render(self, context):

‎cfgov/v1/wagtail_hooks.py

+24
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
ReusableText,
3434
)
3535
from v1.template_debug import (
36+
byline_test_cases,
3637
call_to_action_test_cases,
3738
featured_content_test_cases,
3839
heading_test_cases,
40+
item_introduction_test_cases,
3941
notification_test_cases,
4042
register_template_debug,
43+
text_introduction_test_cases,
4144
video_player_test_cases,
4245
)
4346
from v1.views.reports import (
@@ -482,6 +485,11 @@ def add_export_feedback_permission_to_wagtail_admin_group_view():
482485
)
483486

484487

488+
register_template_debug(
489+
"v1", "byline", "_includes/atoms/byline.html", byline_test_cases
490+
)
491+
492+
485493
register_template_debug(
486494
"v1",
487495
"call_to_action",
@@ -504,6 +512,14 @@ def add_export_feedback_permission_to_wagtail_admin_group_view():
504512
)
505513

506514

515+
register_template_debug(
516+
"v1",
517+
"item_introduction",
518+
"_includes/organisms/item-introduction.html",
519+
item_introduction_test_cases,
520+
)
521+
522+
507523
register_template_debug(
508524
"v1",
509525
"notification",
@@ -512,6 +528,14 @@ def add_export_feedback_permission_to_wagtail_admin_group_view():
512528
)
513529

514530

531+
register_template_debug(
532+
"v1",
533+
"text_introduction",
534+
"_includes/molecules/text-introduction.html",
535+
text_introduction_test_cases,
536+
)
537+
538+
515539
register_template_debug(
516540
"v1",
517541
"video_player",

0 commit comments

Comments
 (0)
Please sign in to comment.