Always go back to previous page from notification

When looking at a notification you can either be coming from the page
of all notifications, or from a job. Currently the back link always
takes you to the page of all notifications.

This commit makes it a bit more sophisticated so if you’ve come from
looking at a job, you go back to the job.
This commit is contained in:
Chris Hill-Scott
2019-05-09 17:33:22 +01:00
parent b786997c6b
commit b4894e7a03
6 changed files with 73 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ from flask import url_for
from freezegun import freeze_time
from app.main.views.jobs import get_time_left
from tests import sample_uuid
from tests.conftest import (
SERVICE_ONE_ID,
active_caseworking_user,
@@ -218,6 +219,19 @@ def test_should_show_page_for_one_job(
)
assert csv_link.text == 'Download this report'
assert page.find('span', {'id': 'time-left'}).text == 'Data available for 7 days'
assert normalize_spaces(page.select_one('tbody tr').text) == normalize_spaces(
'07123456789 '
'template content '
'Delivered 1 January at 11:10am'
)
assert page.select_one('tbody tr a')['href'] == url_for(
'main.view_notification',
service_id=SERVICE_ONE_ID,
notification_id=sample_uuid(),
from_job=fake_uuid,
)
mock_get_notifications.assert_called_with(
SERVICE_ONE_ID,
fake_uuid,

View File

@@ -115,6 +115,46 @@ def test_notification_status_page_respects_redaction(
)
@pytest.mark.parametrize('extra_args, expected_back_link', [
(
{},
partial(url_for, 'main.view_notifications', message_type='sms'),
),
(
{'from_job': 'job_id'},
partial(url_for, 'main.view_job', job_id='job_id'),
),
(
{'help': '0'},
None,
),
(
{'help': '0', 'from_job': 'job_id'},
None,
),
])
def test_notification_status_shows_expected_back_link(
client_request,
mocker,
mock_get_notification,
fake_uuid,
extra_args,
expected_back_link,
):
page = client_request.get(
'main.view_notification',
service_id=SERVICE_ONE_ID,
notification_id=fake_uuid,
**extra_args
)
back_link = page.select_one('.govuk-back-link')
if expected_back_link:
assert back_link['href'] == expected_back_link(service_id=SERVICE_ONE_ID)
else:
assert back_link is None
@freeze_time("2012-01-01 01:01")
def test_notification_page_doesnt_link_to_template_in_tour(
client_request,