Add a confirmation page

Generally I prefer confirmation pages to the flash message thing
(they’re harder to miss). So this commit adds one.

It also adds some logic to this page, so that, depending what the user
has told us about the thing they’ve submitted, we can tell them how
quickly to expect a response.
This commit is contained in:
Chris Hill-Scott
2016-12-12 12:29:29 +00:00
parent 438868257f
commit 4ef087fb01
3 changed files with 84 additions and 15 deletions

View File

@@ -96,8 +96,7 @@ def feedback(ticket_type):
resp.json())
)
abort(500, "Feedback submission failed")
flash("Thanks, weve received your feedback", 'default_with_tick')
return redirect(url_for('.support', ticket_type=ticket_type))
return redirect(url_for('.thanks', urgent=urgent, anonymous=anonymous))
return render_template(
'views/support/{}.html'.format(ticket_type),
@@ -119,7 +118,9 @@ def bat_phone():
def thanks():
return render_template(
'views/support/thanks.html',
ticket_type=request.args.get('ticket_type'),
urgent=convert_to_boolean(request.args.get('urgent')),
anonymous=convert_to_boolean(request.args.get('anonymous')),
logged_in=(current_user and current_user.is_authenticated),
)

View File

@@ -0,0 +1,32 @@
{% extends "withoutnav_template.html" %}
{% from "components/textbox.html" import textbox %}
{% from "components/page-footer.html" import page_footer %}
{% block page_title %}
Thanks for contacting us GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">
Thanks for contacting GOV.UK Notify
</h1>
<p>
{% if anonymous %}
Well look into it
{% else %}
Well get back to you
{% endif %}
{% if urgent %}
within 30 minutes.
{% else %}
by the next working day.
{% endif %}
</p>
<p>
<a href="{{ url_for('.support') }}">Back to support</a>
</p>
{% endblock %}

View File

@@ -84,13 +84,14 @@ def test_get_feedback_page(client, ticket_type, expected_status_code):
@freeze_time("2016-12-12 12:00:00.000000")
@pytest.mark.parametrize('data, expected_message, expected_person_name, expected_email, logged_in', [
@pytest.mark.parametrize('data, expected_message, expected_person_name, expected_email, logged_in, is_anonymous', [
(
{'feedback': "blah", 'name': 'Fred'},
'Environment: http://localhost/\nFred (no email address supplied)\nblah',
'Fred',
'donotreply@notifications.service.gov.uk',
False,
True,
),
(
{'feedback': "blah"},
@@ -98,6 +99,7 @@ def test_get_feedback_page(client, ticket_type, expected_status_code):
None,
'donotreply@notifications.service.gov.uk',
False,
True,
),
(
{'feedback': "blah", 'name': "Steve Irwin", 'email_address': 'rip@gmail.com'},
@@ -105,6 +107,7 @@ def test_get_feedback_page(client, ticket_type, expected_status_code):
'Steve Irwin',
'rip@gmail.com',
False,
False,
),
(
{'feedback': "blah"},
@@ -112,6 +115,7 @@ def test_get_feedback_page(client, ticket_type, expected_status_code):
'Test User',
'test@user.gov.uk',
True,
False,
),
])
@pytest.mark.parametrize('ticket_type', ['problem', 'question'])
@@ -127,6 +131,7 @@ def test_post_problem_or_question(
expected_person_name,
expected_email,
logged_in,
is_anonymous,
):
mock_post = mocker.patch(
'app.main.views.feedback.requests.post',
@@ -139,6 +144,7 @@ def test_post_problem_or_question(
data=data,
)
assert resp.status_code == 302
assert resp.location == url_for('main.thanks', urgent=True, anonymous=is_anonymous, _external=True)
mock_post.assert_called_with(
ANY,
data={
@@ -155,21 +161,21 @@ def test_post_problem_or_question(
)
@pytest.mark.parametrize('ticket_type, severe, is_in_business_hours, expected_urgency', [
@pytest.mark.parametrize('ticket_type, severe, is_in_business_hours, numeric_urgency, is_urgent', [
# business hours, always urgent
('problem', True, True, 10),
('question', True, True, 10),
('problem', False, True, 10),
('question', False, True, 10),
('problem', True, True, 10, True),
('question', True, True, 10, True),
('problem', False, True, 10, True),
('question', False, True, 10, True),
# out of hours, non emergency, never urgent
('problem', False, False, 1),
('question', False, False, 1),
('problem', False, False, 1, False),
('question', False, False, 1, False),
# out of hours, emergency problems are urgent
('problem', True, False, 10),
('question', True, False, 1),
('problem', True, False, 10, True),
('question', True, False, 1, False),
])
def test_urgency(
@@ -181,7 +187,8 @@ def test_urgency(
ticket_type,
severe,
is_in_business_hours,
expected_urgency,
numeric_urgency,
is_urgent,
):
mocker.patch('app.main.views.feedback.in_business_hours', return_value=is_in_business_hours)
mock_post = mocker.patch('app.main.views.feedback.requests.post', return_value=Mock(status_code=201))
@@ -190,7 +197,8 @@ def test_urgency(
data={'feedback': "blah"},
)
assert response.status_code == 302
assert mock_post.call_args[1]['data']['urgency'] == expected_urgency
assert response.location == url_for('main.thanks', urgent=is_urgent, anonymous=False, _external=True)
assert mock_post.call_args[1]['data']['urgency'] == numeric_urgency
ids, params = zip(*[
@@ -369,3 +377,31 @@ def test_log_error_on_post(app_, mocker, ticket_type):
assert mock_post.called
mock_logger.assert_called_with(
"Deskpro create ticket request failed with {} '{}'".format(mock_post().status_code, mock_post().json()))
@pytest.mark.parametrize('logged_in', [True, False])
@pytest.mark.parametrize('urgent, anonymous, message', [
(True, False, 'Well get back to you within 30 minutes.'),
(False, False, 'Well get back to you by the next working day.'),
(True, True, 'Well look into it within 30 minutes.'),
(False, True, 'Well look into it by the next working day.'),
])
def test_thanks(
client,
mocker,
api_user_active,
mock_get_user,
urgent,
anonymous,
message,
logged_in,
):
if logged_in:
client.login(api_user_active)
response = client.get(url_for('main.thanks', urgent=urgent, anonymous=anonymous))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert ' '.join(page.find('main').find('p').text.split()) == message