From c270688fe47d5e4e9c974ea5a85bff77707eb9c0 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 17 Jul 2020 08:07:40 +0100 Subject: [PATCH] Show pending broadcasts on dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we have an approval flow, `pending-approval` will be the state a broadcast is in between being a draft and broadcasting. This means it is the earliest stage at which a broadcast can appear on the dashboard, so this commit adds a new section at the top of the dashboard to display these broadcasts (since the dashboard is in a reverse chronological order). Rather than displaying the scheduled time, the extra information shown is the person who drafted the broadcast, since I reckon you’ll be coming to this page because they’ve asked you to approve their broadcast. --- app/main/views/broadcast.py | 7 ++++- app/templates/views/broadcast/dashboard.html | 8 ++++++ .../broadcast/partials/dashboard-table.html | 6 ++++- tests/app/main/views/test_broadcast.py | 26 +++++++++++++++++-- tests/conftest.py | 3 +++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/app/main/views/broadcast.py b/app/main/views/broadcast.py index 0c30ef0df..1737dbb8f 100644 --- a/app/main/views/broadcast.py +++ b/app/main/views/broadcast.py @@ -13,7 +13,7 @@ from app.utils import service_has_permission, user_has_permissions def broadcast_dashboard(service_id): return render_template( 'views/broadcast/dashboard.html', - partials=get_broadcast_dashboard_partials(current_service.id) + partials=get_broadcast_dashboard_partials(current_service.id), ) @@ -27,6 +27,11 @@ def broadcast_dashboard_updates(service_id): def get_broadcast_dashboard_partials(service_id): broadcast_messages = BroadcastMessages(service_id) return dict( + pending_approval_broadcasts=render_template( + 'views/broadcast/partials/dashboard-table.html', + broadcasts=broadcast_messages.with_status('pending-approval'), + empty_message='You do not have any broadcasts waiting for approval', + ), live_broadcasts=render_template( 'views/broadcast/partials/dashboard-table.html', broadcasts=broadcast_messages.with_status('broadcasting'), diff --git a/app/templates/views/broadcast/dashboard.html b/app/templates/views/broadcast/dashboard.html index 3e35af6ec..c44257e62 100644 --- a/app/templates/views/broadcast/dashboard.html +++ b/app/templates/views/broadcast/dashboard.html @@ -10,6 +10,14 @@

Dashboard

+

Waiting for approval

+ + {{ ajax_block( + partials, + url_for('.broadcast_dashboard_updates', service_id=current_service.id), + 'pending_approval_broadcasts' + ) }} +

Live broadcasts

{{ ajax_block( diff --git a/app/templates/views/broadcast/partials/dashboard-table.html b/app/templates/views/broadcast/partials/dashboard-table.html index fd197201e..92cd40b5d 100644 --- a/app/templates/views/broadcast/partials/dashboard-table.html +++ b/app/templates/views/broadcast/partials/dashboard-table.html @@ -21,7 +21,11 @@ {% endcall %} {% call field(align='right') %} - {% if item.status == 'broadcasting' %} + {% if item.status == 'pending-approval' %} +

+ Prepared by {{ item.created_by.name }} +

+ {% elif item.status == 'broadcasting' %}

Live until {{ item.finishes_at|format_datetime_relative }}

diff --git a/tests/app/main/views/test_broadcast.py b/tests/app/main/views/test_broadcast.py index f379717cf..d777b9002 100644 --- a/tests/app/main/views/test_broadcast.py +++ b/tests/app/main/views/test_broadcast.py @@ -62,6 +62,7 @@ def test_empty_broadcast_dashboard( assert [ normalize_spaces(row.text) for row in page.select('tbody tr .table-empty-message') ] == [ + 'You do not have any broadcasts waiting for approval', 'You do not have any live broadcasts at the moment', 'You do not have any previous broadcasts', ] @@ -78,13 +79,29 @@ def test_broadcast_dashboard( '.broadcast_dashboard', service_id=SERVICE_ONE_ID, ) + assert normalize_spaces(page.select('main h2')[0].text) == ( + 'Waiting for approval' + ) assert [ normalize_spaces(row.text) for row in page.select('table')[0].select('tbody tr') ] == [ - 'Example template To England and Scotland Live until tomorrow at 2:20am', + 'Example template To England and Scotland Prepared by Test User', ] + + assert normalize_spaces(page.select('main h2')[1].text) == ( + 'Live broadcasts' + ) assert [ normalize_spaces(row.text) for row in page.select('table')[1].select('tbody tr') + ] == [ + 'Example template To England and Scotland Live until tomorrow at 2:20am', + ] + + assert normalize_spaces(page.select('main h2')[2].text) == ( + 'Previous broadcasts' + ) + assert [ + normalize_spaces(row.text) for row in page.select('table')[2].select('tbody tr') ] == [ 'Example template To England and Scotland Stopped 10 February at 2:20am', 'Example template To England and Scotland Finished yesterday at 8:20pm', @@ -107,8 +124,13 @@ def test_broadcast_dashboard_json( json_response = json.loads(response.get_data(as_text=True)) - assert json_response.keys() == {'live_broadcasts', 'previous_broadcasts'} + assert json_response.keys() == { + 'pending_approval_broadcasts', + 'live_broadcasts', + 'previous_broadcasts', + } + assert 'Prepared by Test User' in json_response['pending_approval_broadcasts'] assert 'Live until tomorrow at 2:20am' in json_response['live_broadcasts'] assert 'Finished yesterday at 8:20pm' in json_response['previous_broadcasts'] diff --git a/tests/conftest.py b/tests/conftest.py index 88a96f8d4..b2ece7b0c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4270,6 +4270,9 @@ def mock_get_broadcast_messages( partial_json( status='draft', ), + partial_json( + status='pending-approval', + ), partial_json( status='broadcasting', starts_at=(