Don’t send users back to a page that will send them forward again

If you’re on a page with a normal placeholder and the previous
placeholder is one that’s also in the address block then going back to
the previous page will send you immediately forward to the current page
again.

This commit makes the back link a bit smarter by skipping over pages
where it can see that they relate to a placeholder from the address
block.

If it gets all the way to the start of the list of placeholders without
finding any non-address ones then it will default to generating a link
that will redirect the user to filling in the address block again.
This commit is contained in:
Chris Hill-Scott
2020-04-09 16:25:48 +01:00
parent b68dd569fc
commit d31c244363
2 changed files with 36 additions and 9 deletions

View File

@@ -2061,6 +2061,7 @@ def test_send_one_off_letter_copes_with_placeholder_from_address_block(
mocker,
fake_uuid,
mock_template_preview,
no_letter_contact_blocks,
placeholder,
):
mocker.patch(
@@ -2107,6 +2108,19 @@ def test_send_one_off_letter_copes_with_placeholder_from_address_block(
'postcode': 'SW1A 1AA',
}
back_link = page.select_one('.govuk-back-link')['href']
assert back_link == url_for(
'main.send_one_off_step',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
step_index=1,
)
previous_page = client_request.get_url(back_link, _follow_redirects=True)
# Weve skipped past the address placeholder and gone back to the
# address block
assert normalize_spaces(previous_page.select_one('form label').text) == 'Address'
def test_send_test_sms_message_puts_submitted_data_in_session(
client_request,