Skip to content

Commit dcbb448

Browse files
committed
TWE-62: Add PromoBlock to ServiceAreaPage (with link optional)
1 parent 36444b3 commit dcbb448

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/promo_block.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<div class="promo-block__content">
55
{% include "patterns/atoms/section-title/section-title.html" with title=value.title classes="promo-block__title" %}
66
<p class="promo-block__description">{{ value.description }}</p>
7-
<a href="{{ value.get_button_link }}" class="button promo-block__button">{{ value.button_text }}</a>
7+
{% if value.button_text %}
8+
<a href="{{ value.get_button_link }}" class="button promo-block__button">{{ value.button_text }}</a>
9+
{% endif %}
810
{% if value.secondary_link %}
911
<hr class="promo-block__divider" aria-hidden="true" />
1012
{% with secondary_link=value.secondary_link.0.value %}

tbx/services/blocks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,23 @@ class ServiceStoryBlock(StoryBlock):
6969
)
7070

7171

72+
class OptionalLinkPromoBlock(PromoBlock):
73+
"""
74+
Identical to PromoBlock in all aspects, except that button_link is optional.
75+
"""
76+
77+
button_text = blocks.CharBlock(max_length=55, required=False)
78+
button_link = blocks.StreamBlock(
79+
PromoBlock.declared_blocks["button_link"].child_blocks.items(),
80+
required=False,
81+
max_num=1,
82+
)
83+
84+
7285
class ServiceAreaStoryBlock(StoryBlock):
7386
blog_chooser = BlogChooserBlock()
7487
four_photo_collage = FourPhotoCollageBlock()
7588
key_points = IconKeyPointsBlock(label="Key points with icons")
7689
link_columns = LinkColumnsBlock()
90+
promo = OptionalLinkPromoBlock()
7791
work_chooser = WorkChooserBlock()

tbx/services/tests/__init__.py

Whitespace-only changes.

tbx/services/tests/test_blocks.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from django.test import SimpleTestCase
2+
3+
from wagtail.blocks.struct_block import StructBlockValidationError
4+
5+
from tbx.services.blocks import OptionalLinkPromoBlock, PromoBlock
6+
7+
8+
class OptionalLinkPromoBlockTestCase(SimpleTestCase):
9+
def test_basic_promo_block_button_link_required(self):
10+
try:
11+
PromoBlock().clean({"button_link": []})
12+
except StructBlockValidationError:
13+
pass
14+
else:
15+
self.fail("PromoBlock.button_link should be required")
16+
17+
def test_custom_promo_block_button_link_optional(self):
18+
try:
19+
OptionalLinkPromoBlock().clean({"button_link": []})
20+
except StructBlockValidationError as e:
21+
self.fail(e.as_json_data())
22+
23+
def test_basic_promo_block_button_text_required(self):
24+
try:
25+
PromoBlock().clean({"button_text": ""})
26+
except StructBlockValidationError:
27+
pass
28+
else:
29+
self.fail("PromoBlock.button_text should be required")
30+
31+
def test_custom_promo_block_button_text_optional(self):
32+
try:
33+
OptionalLinkPromoBlock().clean({"button_text": ""})
34+
except StructBlockValidationError as e:
35+
self.fail(e.as_json_data())

0 commit comments

Comments
 (0)