Ensure correct page titles on send test flows

We have some fairly complicated nested if statements in our Jinja that
decide what the page titles should be. It’s only going to get more
complicated with the send individual message routes.

So this commit:
- moves the logic from Jinja to Python
- adds tests to check things are working as expected
- sets the page titles to the right thing for each flow
This commit is contained in:
Chris Hill-Scott
2017-05-25 13:31:23 +01:00
parent 27c1463213
commit 82549c817a
3 changed files with 79 additions and 14 deletions

View File

@@ -284,6 +284,7 @@ def send_test_step(service_id, template_id, step_index):
return render_template(
'views/send-test.html',
page_title=get_send_test_page_title(template.template_type, request.endpoint),
template=template,
form=form,
optional_placeholder=optional_placeholder,
@@ -546,3 +547,14 @@ def all_placeholders_in_session(placeholders):
get_normalised_send_test_values_from_session().get(placeholder, False) not in (False, None)
for placeholder in placeholders
)
def get_send_test_page_title(template_type, endpoint):
if get_help_argument():
return 'Example text message'
if template_type == 'letter':
return 'Print a test letter'
return {
'main.send_test_step': 'Send yourself a test',
'main.send_one_off_step': 'Send one-off message',
}[endpoint]

View File

@@ -5,25 +5,13 @@
{% from "components/table.html" import list_table, field, text_field, index_field, index_field_heading %}
{% block service_page_title %}
{% if request.args['help'] %}
Example text message
{% else %}
Send yourself a test
{% endif %}
{{ page_title }}
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">
{% if request.args['help'] %}
Example text message
{% else %}
{% if template.template_type == 'letter' %}
Print a test letter
{% else %}
Send yourself a test
{% endif %}
{% endif %}
{{ page_title }}
</h1>
<form method="post" class="js-stick-at-top-when-scrolling" data-module="autofocus">

View File

@@ -332,6 +332,71 @@ def test_send_test_step_redirects_if_session_not_setup(
assert session['send_test_values'] == expected_session_contents
@pytest.mark.parametrize('template_mock, partial_url, expected_h1', [
(
mock_get_service_template_with_placeholders,
partial(url_for, 'main.send_test'),
'Send yourself a test',
),
(
mock_get_service_template_with_placeholders,
partial(url_for, 'main.send_one_off'),
'Send one-off message',
),
(
mock_get_service_template_with_placeholders,
partial(url_for, 'main.send_test', help=1),
'Example text message',
),
(
mock_get_service_email_template,
partial(url_for, 'main.send_test', help=1),
'Example text message',
),
(
mock_get_service_email_template,
partial(url_for, 'main.send_test'),
'Send yourself a test',
),
(
mock_get_service_email_template,
partial(url_for, 'main.send_one_off'),
'Send one-off message',
),
(
mock_get_service_letter_template,
partial(url_for, 'main.send_test'),
'Print a test letter',
),
(
mock_get_service_letter_template,
partial(url_for, 'main.send_one_off'),
'Print a test letter',
),
])
def test_send_one_off_or_test_has_correct_page_titles(
logged_in_client,
service_one,
fake_uuid,
mocker,
template_mock,
partial_url,
expected_h1,
):
template_mock(mocker)
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=99)
response = logged_in_client.get(
partial_url(service_id=service_one['id'], template_id=fake_uuid, step_index=0),
follow_redirects=True,
)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert response.status_code == 200
assert page.h1.text.strip() == expected_h1
@pytest.mark.parametrize('endpoint, expected_redirect, send_test_values', [
(
'main.send_test_step',