diff --git a/app/__init__.py b/app/__init__.py index 3345c1cb4..7e0f9229b 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -431,7 +431,9 @@ def format_notification_status_as_field_status(status, notification_type): ).get(status, 'error') -def format_notification_status_as_url(status): +def format_notification_status_as_url(status, notification_type): + if notification_type == 'letter': + return None url = partial(url_for, "main.using_notify") return { 'technical-failure': url(_anchor='technical-failure'), diff --git a/app/assets/stylesheets/views/notification.scss b/app/assets/stylesheets/views/notification.scss index 08def6684..e26268f56 100644 --- a/app/assets/stylesheets/views/notification.scss +++ b/app/assets/stylesheets/views/notification.scss @@ -15,4 +15,9 @@ } + &-cancelled { + @include bold-19; + color: $error-colour; + } + } diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index f1e594357..fe454b8e5 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -76,6 +76,7 @@ def view_notification(service_id, notification_id): return render_template( 'views/notifications/notification.html', finished=(notification['status'] in (DELIVERED_STATUSES + FAILURE_STATUSES)), + notification_status=notification['status'], uploaded_file_name='Report', template=template, job=job, @@ -89,6 +90,7 @@ def view_notification(service_id, notification_id): partials=get_single_notification_partials(notification), created_by=notification.get('created_by'), created_at=notification['created_at'], + updated_at=notification['updated_at'], help=get_help_argument(), estimated_letter_delivery_date=get_letter_timings( notification['created_at'], diff --git a/app/templates/components/table.html b/app/templates/components/table.html index 9ab0124a3..2c43ecbe2 100644 --- a/app/templates/components/table.html +++ b/app/templates/components/table.html @@ -154,7 +154,7 @@ align='right' ) %} {% if displayed_on_single_line %}{% endif %} - {% if notification.status|format_notification_status_as_url %} + {% if notification.status|format_notification_status_as_url(notification.notification_type) %} {% endif %} {% if notification['notification_type'] != "letter" or notification.status == 'virus-scan-failed' %} @@ -162,12 +162,19 @@ notification.template.template_type ) }} {% endif %} - {% if notification.status|format_notification_status_as_url %} + {% if notification.notification_type == "letter" and notification.status == 'permanent-failure' %} + Cancelled + {% endif %} + {% if notification.status|format_notification_status_as_url(notification.notification_type) %} {% endif %} {% if notification['notification_type'] == "letter" %} - {{ notification.created_at|format_datetime_short }} + {% if notification.status == 'permanent-failure' %} + {{ (notification.updated_at)|format_datetime_short }} + {% else %} + {{ (notification.created_at)|format_datetime_short }} + {% endif %} {% else %} {{ notification.status|format_notification_status_as_time( notification.created_at|format_datetime_short, diff --git a/app/templates/partials/notifications/status.html b/app/templates/partials/notifications/status.html index 0886ca352..d90e82462 100644 --- a/app/templates/partials/notifications/status.html +++ b/app/templates/partials/notifications/status.html @@ -1,12 +1,12 @@

- {% if notification.status|format_notification_status_as_url %} - + {% if notification.status|format_notification_status_as_url(notification.notification_type) %} + {% endif %} {{ notification.status|format_notification_status( notification.template.template_type ) }} - {% if notification.status|format_notification_status_as_url %} + {% if notification.status|format_notification_status_as_url(notification.notification_type) %} {% endif %} {% if sent_with_test_key %} diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html index b7ba44d04..2c2e9788a 100644 --- a/app/templates/views/notifications/notification.html +++ b/app/templates/views/notifications/notification.html @@ -35,15 +35,21 @@

{% if template.template_type == 'letter' %} -

- Postage: {{ postage }} class -

-

- Estimated delivery date: {{ estimated_letter_delivery_date|string|format_date_short }} -

-

- Download as a PDF -

+ {% if notification_status == 'permanent-failure' %} +

+ Cancelled {{ updated_at|format_datetime_short }} +

+ {% else %} +

+ Postage: {{ postage }} class +

+

+ Estimated delivery date: {{ estimated_letter_delivery_date|string|format_date_short }} +

+

+ Download as a PDF +

+ {% endif %} {% endif %} {{ template|string }} diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py index 1f5e312ca..e9727f171 100644 --- a/tests/app/main/views/test_activity.py +++ b/tests/app/main/views/test_activity.py @@ -542,10 +542,11 @@ def test_big_numbers_and_search_dont_show_for_letters( @freeze_time("2017-09-27 16:30:00.000000") @pytest.mark.parametrize( - "message_type, hint_status_visible", [ - ('email', True), - ('sms', True), - ('letter', False) + "message_type, status, expected_hint_status, single_line", [ + ('email', 'delivered', 'Delivered 27 September at 5:31pm', True), + ('sms', 'delivered', 'Delivered 27 September at 5:31pm', True), + ('letter', 'delivered', '27 September at 5:30pm', True), + ('letter', 'permanent-failure', 'Cancelled 27 September at 5:31pm', False), ] ) def test_sending_status_hint_does_not_include_status_for_letters( @@ -555,10 +556,12 @@ def test_sending_status_hint_does_not_include_status_for_letters( mock_get_service_statistics, mock_get_service_data_retention_by_notification_type, message_type, - hint_status_visible, + status, + expected_hint_status, + single_line, mocker ): - mock_get_notifications(mocker, True, diff_template_type=message_type) + mock_get_notifications(mocker, True, diff_template_type=message_type, noti_status=status) page = client_request.get( 'main.view_notifications', @@ -566,10 +569,8 @@ def test_sending_status_hint_does_not_include_status_for_letters( message_type=message_type ) - if message_type == 'letter': - assert normalize_spaces(page.select(".align-with-message-body")[0].text) == "27 September at 5:30pm" - else: - assert normalize_spaces(page.select(".align-with-message-body")[0].text) == "Delivered 27 September at 5:31pm" + assert normalize_spaces(page.select(".table-field-right-aligned")[0].text) == expected_hint_status + assert bool(page.select('.align-with-message-body')) is single_line @pytest.mark.parametrize("is_precompiled_letter,expected_hint", [ diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index 5a6bdd418..82fc55e22 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -174,6 +174,41 @@ def test_notification_page_shows_page_for_letter_notification( ) +@freeze_time("2016-01-01 01:01") +def test_notification_page_shows_cancelled_letter( + client_request, + mocker, + fake_uuid, +): + + mock_get_notification( + mocker, + fake_uuid, + template_type='letter', + notification_status='permanent-failure', + ) + mocker.patch( + 'app.main.views.notifications.get_page_count_for_letter', + return_value=1 + ) + + page = client_request.get( + 'main.view_notification', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + ) + + assert normalize_spaces(page.select('main p')[0].text) == ( + 'sample template sent by Test User on 1 January at 1:01am' + ) + assert normalize_spaces(page.select('main p')[1].text) == ( + 'Cancelled 1 January at 1:02am' + ) + assert not page.select('p.notification-status') + + assert page.select_one('main img')['src'].endswith('.png?page=1') + + @freeze_time("2016-01-01 01:01") def test_notification_page_shows_page_for_first_class_letter_notification( client_request,