From cb1177b0164e8cfbb2f358c196aa46c50f563e47 Mon Sep 17 00:00:00 2001 From: Andy Chosak Date: Wed, 10 Jul 2024 13:18:08 -0400 Subject: [PATCH] TCCP: Fix phone number parsing This commit modifies how phone numbers are rendered on the frontend of the "Explore credit cards" tool. It fixes an issue with parsing phone numbers that have spaces in them in the TCCP dataset. The TCCP dataset contains cards that only provide a single phone number, but sometimes this can include spaces, for example: 1 (800) 555-1234 Instead of parsing this like multiple phone numbers separated by spaces, we need to parse this as a single phone number. --- cfgov/tccp/jinja2/tccp/includes/contact_info.html | 6 +++--- cfgov/tccp/jinja2tags.py | 5 ++--- cfgov/tccp/tests/test_jinja2tags.py | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cfgov/tccp/jinja2/tccp/includes/contact_info.html b/cfgov/tccp/jinja2/tccp/includes/contact_info.html index dbc976c07a1..cfc54fb73b6 100644 --- a/cfgov/tccp/jinja2/tccp/includes/contact_info.html +++ b/cfgov/tccp/jinja2/tccp/includes/contact_info.html @@ -1,13 +1,13 @@ -{% if urls or phone_numbers -%} +{% if urls or phone_number -%}
{% for value in urls %} {%- include "v1/includes/molecules/contact-hyperlink.html" -%} {% endfor %} - {% for phone_number in phone_numbers %} + {% if phone_number %} {% with value = {"phones": [{"number": phone_number}]} %} {%- include "v1/includes/molecules/contact-phone.html" -%} {% endwith %} - {%- endfor %} + {%- endif %}
{%- endif %} diff --git a/cfgov/tccp/jinja2tags.py b/cfgov/tccp/jinja2tags.py index 12b3b0af8bb..2d6cc0ed7ab 100644 --- a/cfgov/tccp/jinja2tags.py +++ b/cfgov/tccp/jinja2tags.py @@ -45,9 +45,8 @@ def fmt_list(format_fn, value): "urls": fmt_list( _format_contact_website, card["website_for_consumer"] ), - "phone_numbers": fmt_list( - _format_contact_phone_number, - card["telephone_number_for_consumers"], + "phone_number": _format_contact_phone_number( + card["telephone_number_for_consumers"] or "" ), } diff --git a/cfgov/tccp/tests/test_jinja2tags.py b/cfgov/tccp/tests/test_jinja2tags.py index 2f6ffe57131..b8a71b87108 100644 --- a/cfgov/tccp/tests/test_jinja2tags.py +++ b/cfgov/tccp/tests/test_jinja2tags.py @@ -75,7 +75,7 @@ def test_render(self): html = render_contact_info( { "website_for_consumer": "https://example.com foo.com", - "telephone_number_for_consumers": "212-555-1234", + "telephone_number_for_consumers": "1 212-555-1234", } ) @@ -83,3 +83,4 @@ def test_render(self): self.assertIn('', html) self.assertNotIn('', html) self.assertEqual(len(re.findall("m-contact-phone", html)), 1) + self.assertIn("2125551234", html)