diff --git a/app/main/views/send.py b/app/main/views/send.py index 2643fdf49..ba098173e 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -476,7 +476,7 @@ def send_one_off_step(service_id, template_id, step_index): "views/send-test.html", page_title=get_send_test_page_title( template.template_type, - entering_recipient=(step_index == 0), + entering_recipient=not session["recipient"], name=template.name, ), template=template, @@ -561,24 +561,47 @@ def _check_messages(service_id, template_id, upload_id, preview_row, **kwargs): ) if request.args.get("from_test"): - # TODO: may not be required after letters code removed - back_link = url_for( - "main.send_one_off", service_id=service_id, template_id=template.id - ) - back_link_from_preview = url_for( - "main.send_one_off", service_id=service_id, template_id=template.id - ) + back_link = { + "href": { + "url": url_for( + "main.send_one_off", service_id=service_id, template_id=template.id + ), + "text": "Back to message personalization" + }, + "html": "Back to message personalization" + } + back_link_from_preview = { + "href": { + "url": url_for( + "main.send_one_off", service_id=service_id, template_id=template.id + ), + "text": "Back to message personalization" + }, + "html": "Back to message personalization" + } choose_time_form = None else: - back_link = url_for( - "main.send_messages", service_id=service_id, template_id=template.id - ) - back_link_from_preview = url_for( - "main.check_messages", - service_id=service_id, - template_id=template.id, - upload_id=upload_id, - ) + back_link = { + "href": { + "url": url_for( + "main.send_messages", service_id=service_id, template_id=template.id + ), + "text": "Back to upload a file" + }, + "html": "Back to upload a file" + } + back_link_from_preview = { + "href": { + "url": url_for( + "main.check_messages", + service_id=service_id, + template_id=template.id, + upload_id=upload_id, + ), + "text": "Back to check messages" + }, + "html": "Back to check messages" + } choose_time_form = ChooseTimeForm() if preview_row < 2: @@ -763,16 +786,19 @@ def get_back_link( service_id=service_id, template_id=template.id, ), - "text": "Back to preview" + "text": "Back to select delivery time" }, - "html": "Back to preview" + "html": "Back to select delivery time" } if step_index == 0: if should_skip_template_page(template._template): return { "href": { - "url": url_for(".choose_template", service_id=service_id), + "url": url_for( + ".choose_template", + service_id=service_id, + ), "text": "Back to all templates" }, "html": "Back to all templates" @@ -780,12 +806,17 @@ def get_back_link( else: return { "href": { - "url": url_for(".view_template", service_id=service_id, template_id=template.id), + "url": url_for( + ".view_template", + service_id=service_id, + template_id=template.id, + ), "text": "Back to confirm your template" }, "html": "Back to confirm your template" } + # fallback for other steps back_to_text = ( "Back to select recipients" if step_index == 1 else "Back to message personalization" ) diff --git a/app/templates/components/components/back-link/macro.njk b/app/templates/components/components/back-link/macro.njk index d232c1b2b..e52d92fff 100644 --- a/app/templates/components/components/back-link/macro.njk +++ b/app/templates/components/components/back-link/macro.njk @@ -1,3 +1,3 @@ {% macro usaBackLink(params) %} - {%- include "./template.njk" -%} + {%- include "./template.njk" with context %} {% endmacro %} diff --git a/app/templates/components/components/back-link/template.njk b/app/templates/components/components/back-link/template.njk index 340b3ca22..84344ab35 100644 --- a/app/templates/components/components/back-link/template.njk +++ b/app/templates/components/components/back-link/template.njk @@ -1,4 +1,6 @@ diff --git a/app/templates/views/check/preview.html b/app/templates/views/check/preview.html index 091ba345f..0d8d65f98 100644 --- a/app/templates/views/check/preview.html +++ b/app/templates/views/check/preview.html @@ -13,7 +13,7 @@ {% block backLink %} - {{ usaBackLink({ "href": back_link_from_preview }) }} + {{ usaBackLink(www.google.com) }} {% endblock %} {% block maincolumn_content %} diff --git a/app/templates/views/notifications/preview.html b/app/templates/views/notifications/preview.html index 536288d9a..c870ba539 100644 --- a/app/templates/views/notifications/preview.html +++ b/app/templates/views/notifications/preview.html @@ -16,9 +16,9 @@ {% block backLink %} {% if help %} - {{ usaBackLink({ "href": back_link }) }} + {{ usaBackLink(back_link) }} {% else %} - {{ usaBackLink({ "href": back_link_from_preview }) }} + {{ usaBackLink(back_link_from_preview) }} {% endif %} {% endblock %} diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 27956f299..6e6a5233e 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -1451,9 +1451,7 @@ def test_send_one_off_offers_link_to_upload( assert back_link.text.strip() in { "Back to all templates", - "Back to confirm your template", - "Back to select recipients", - "Back to message personalization" + "Back to confirm your template" } assert link.text.strip() == "Upload a list of phone numbers" @@ -1524,8 +1522,6 @@ def test_link_to_upload_not_offered_when_entering_personalisation( step_index=1, ) - # print(page.prettify()) # Print the full HTML response - # We’re entering personalization assert page.select_one("input[type=text]")["name"] == "placeholder_value" assert page.select_one("label").text.strip() == "name" @@ -2289,12 +2285,10 @@ def test_check_messages_back_link( **extra_args, ) - # assert (page.find_all("a", {"class": "usa-back-link"})[0]["href"]) == expected_url( - # service_id=SERVICE_ONE_ID, template_id=fake_uuid - # ) - actual_href = page.find_all("a", {"class": "usa-back-link"})[0]["href"] expected_href = expected_url(service_id=SERVICE_ONE_ID, template_id=fake_uuid) + + assert actual_href != "#", "Back link href fell back to '#' — missing correct back_link in view" assert actual_href == expected_href @@ -2723,8 +2717,15 @@ def test_preview_notification_shows_preview( template_id=fake_uuid, _expected_status=200, ) + assert page.h1.text.strip() == "Preview for sending" - assert (page.find_all("a", {"class": "usa-back-link"})[0]["href"]) == url_for( + back_link = page.find_all("a", {"class": "usa-back-link"})[0] + assert back_link is not None + + # The real rendered attribute + href = back_link["href"] + + assert href == url_for( "main.check_notification", service_id=service_one["id"], template_id=fake_uuid,