From 3c140ecdbf13a39a3a43970776dd8f2e5356f997 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 28 Feb 2020 15:41:59 +0000 Subject: [PATCH 1/4] Add some subheadings This helps differentiate the totals from the rest of the page, and it harmonises it with the per-service usage page. --- .../views/organisations/organisation/index.html | 16 ++++++++++------ .../views/organisations/test_organisation.py | 8 ++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/templates/views/organisations/organisation/index.html b/app/templates/views/organisations/organisation/index.html index 186a431d7..b44402bc3 100644 --- a/app/templates/views/organisations/organisation/index.html +++ b/app/templates/views/organisations/organisation/index.html @@ -12,46 +12,50 @@ Usage -
+
{{ pill(years, selected_year, big_number_args={'smallest': True}) }}
+

Emails

{{ big_number( total_emails_sent, - label='emails sent', + label='sent', smaller=True ) }}
+

Text messages

{{ big_number( total_sms_cost, - 'spent on text messages', + 'spent', currency="£", smaller=True ) }}
+

Letters

{{ big_number( total_letter_cost, - 'spent on letters', + 'spent', currency="£", smaller=True ) }}
+

By service

{% for service in services %}
-

+

{{ service.service_name }} -

+
{{ big_number( diff --git a/tests/app/main/views/organisations/test_organisation.py b/tests/app/main/views/organisations/test_organisation.py index afb1bb526..6a801beed 100644 --- a/tests/app/main/views/organisations/test_organisation.py +++ b/tests/app/main/views/organisations/test_organisation.py @@ -414,14 +414,14 @@ def test_organisation_services_shows_live_services_and_usage( page = client_request.get('.organisation_dashboard', org_id=ORGANISATION_ID) mock.assert_called_once_with(ORGANISATION_ID, 2019) - services = page.select('main h2') + services = page.select('main h3') usage_rows = page.select('main .govuk-grid-column-one-third') assert len(services) == 2 # Totals - assert normalize_spaces(usage_rows[0].text) == "33,000 emails sent" - assert normalize_spaces(usage_rows[1].text) == "£43.93 spent on text messages" - assert normalize_spaces(usage_rows[2].text) == "£30.50 spent on letters" + assert normalize_spaces(usage_rows[0].text) == "Emails 33,000 sent" + assert normalize_spaces(usage_rows[1].text) == "Text messages £43.93 spent" + assert normalize_spaces(usage_rows[2].text) == "Letters £30.50 spent" assert normalize_spaces(services[0].text) == '1' assert normalize_spaces(services[1].text) == '5' From 74dbd2b439892a5756778fcaf3ac18fc2f38ad82 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 28 Feb 2020 15:43:01 +0000 Subject: [PATCH 2/4] Add some more spacing below service name The service name is often about 1/3 of the width of the page, and was awkwardly grouping with the numbers in the text messages column. This commit adds a bit more vertical space to pull the two further apart which makes it easier to scan down the page. --- app/templates/views/organisations/organisation/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/views/organisations/organisation/index.html b/app/templates/views/organisations/organisation/index.html index b44402bc3..433242dd3 100644 --- a/app/templates/views/organisations/organisation/index.html +++ b/app/templates/views/organisations/organisation/index.html @@ -53,7 +53,7 @@

By service

{% for service in services %}
-

+

{{ service.service_name }}

From d2d5510376ef375d7bf67594d02f9729ad08e510 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 28 Feb 2020 16:14:28 +0000 Subject: [PATCH 3/4] Add a search as you type form As in other places where we have a long list of things where you might want to jump to a specific thing. We use this pattern where there are more than 7 things, per the magical number 7[1] 1. https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two --- app/main/views/organisations.py | 1 + .../organisations/organisation/index.html | 20 ++++- .../views/organisations/test_organisation.py | 80 +++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/app/main/views/organisations.py b/app/main/views/organisations.py index fd480b9e8..7b656bbfa 100644 --- a/app/main/views/organisations.py +++ b/app/main/views/organisations.py @@ -143,6 +143,7 @@ def organisation_dashboard(org_id): end=current_financial_year + 1, ), selected_year=year, + search_form=SearchByNameForm() if len(services) > 7 else None, **{ f'total_{key}': sum(service[key] for service in services) for key in ('emails_sent', 'sms_cost', 'letter_cost') diff --git a/app/templates/views/organisations/organisation/index.html b/app/templates/views/organisations/organisation/index.html index 433242dd3..c42e94ffe 100644 --- a/app/templates/views/organisations/organisation/index.html +++ b/app/templates/views/organisations/organisation/index.html @@ -1,4 +1,5 @@ {% from "components/big-number.html" import big_number %} +{% from "components/live-search.html" import live_search %} {% from "components/pill.html" import pill %} {% extends "org_template.html" %} @@ -50,10 +51,23 @@
-

By service

+ + {% if search_form %} +
+ {{ live_search( + target_selector='.organisation-service', + show=True, + form=search_form, + label='Search by service' + ) }} +
+ {% endif %} + +

By service

+ {% for service in services %} -
-

+
+

{{ service.service_name }}

diff --git a/tests/app/main/views/organisations/test_organisation.py b/tests/app/main/views/organisations/test_organisation.py index 6a801beed..ace9ab5a4 100644 --- a/tests/app/main/views/organisations/test_organisation.py +++ b/tests/app/main/views/organisations/test_organisation.py @@ -471,6 +471,86 @@ def test_organisation_services_filters_by_financial_year( ) +@freeze_time("2020-02-20 20:20") +def test_organisation_services_shows_search_bar( + client_request, + mock_get_organisation, + mocker, + active_user_with_permissions, + fake_uuid, +): + mocker.patch( + 'app.organisations_client.get_services_and_usage', + return_value={"services": [ + { + 'service_id': SERVICE_ONE_ID, + 'service_name': 'Service 1', + 'chargeable_billable_sms': 250122, + 'emails_sent': 13000, + 'free_sms_limit': 250000, + 'letter_cost': 30.50, + 'sms_billable_units': 122, + 'sms_cost': 1.93, + 'sms_remainder': None + }, + ] * 8} + ) + + client_request.login(active_user_with_permissions) + page = client_request.get('.organisation_dashboard', org_id=ORGANISATION_ID) + + services = page.select('.organisation-service') + assert len(services) == 8 + + assert page.select_one('.live-search')['data-targets'] == '.organisation-service' + assert [ + normalize_spaces(service_name.text) + for service_name in page.select('.live-search-relevant') + ] == [ + 'Service 1', + 'Service 1', + 'Service 1', + 'Service 1', + 'Service 1', + 'Service 1', + 'Service 1', + 'Service 1', + ] + + +@freeze_time("2020-02-20 20:20") +def test_organisation_services_hides_search_bar_for_7_or_fewer_services( + client_request, + mock_get_organisation, + mocker, + active_user_with_permissions, + fake_uuid, +): + mocker.patch( + 'app.organisations_client.get_services_and_usage', + return_value={"services": [ + { + 'service_id': SERVICE_ONE_ID, + 'service_name': 'Service 1', + 'chargeable_billable_sms': 250122, + 'emails_sent': 13000, + 'free_sms_limit': 250000, + 'letter_cost': 30.50, + 'sms_billable_units': 122, + 'sms_cost': 1.93, + 'sms_remainder': None + }, + ] * 7} + ) + + client_request.login(active_user_with_permissions) + page = client_request.get('.organisation_dashboard', org_id=ORGANISATION_ID) + + services = page.select('.organisation-service') + assert len(services) == 7 + assert not page.select_one('.live-search') + + def test_organisation_trial_mode_services_shows_all_non_live_services( client_request, platform_admin_user, From 39c3d14350cf6d76919406cce294db7b50499667 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 28 Feb 2020 16:38:35 +0000 Subject: [PATCH 4/4] Fix incorrect numbers for free text message count We were looking at the wrong field in the JSON. --- app/templates/views/organisations/organisation/index.html | 2 +- tests/app/main/views/organisations/test_organisation.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/templates/views/organisations/organisation/index.html b/app/templates/views/organisations/organisation/index.html index c42e94ffe..fe0e57c85 100644 --- a/app/templates/views/organisations/organisation/index.html +++ b/app/templates/views/organisations/organisation/index.html @@ -88,7 +88,7 @@ ) }} {% else %} {{ big_number( - service.free_sms_limit - service.sms_remainder, + service.sms_billable_units, 'free text messages sent', smallest=True ) }} diff --git a/tests/app/main/views/organisations/test_organisation.py b/tests/app/main/views/organisations/test_organisation.py index ace9ab5a4..06436e29a 100644 --- a/tests/app/main/views/organisations/test_organisation.py +++ b/tests/app/main/views/organisations/test_organisation.py @@ -402,7 +402,7 @@ def test_organisation_services_shows_live_services_and_usage( 'app.organisations_client.get_services_and_usage', return_value={"services": [ {'service_id': SERVICE_ONE_ID, 'service_name': '1', 'chargeable_billable_sms': 250122, 'emails_sent': 13000, - 'free_sms_limit': 250000, 'letter_cost': 30.50, 'sms_billable_units': 122, 'sms_cost': 1.93, + 'free_sms_limit': 250000, 'letter_cost': 30.50, 'sms_billable_units': 122, 'sms_cost': 0, 'sms_remainder': None}, {'service_id': SERVICE_TWO_ID, 'service_name': '5', 'chargeable_billable_sms': 0, 'emails_sent': 20000, 'free_sms_limit': 250000, 'letter_cost': 0, 'sms_billable_units': 2500, 'sms_cost': 42.0, @@ -420,7 +420,7 @@ def test_organisation_services_shows_live_services_and_usage( # Totals assert normalize_spaces(usage_rows[0].text) == "Emails 33,000 sent" - assert normalize_spaces(usage_rows[1].text) == "Text messages £43.93 spent" + assert normalize_spaces(usage_rows[1].text) == "Text messages £42.00 spent" assert normalize_spaces(usage_rows[2].text) == "Letters £30.50 spent" assert normalize_spaces(services[0].text) == '1' @@ -428,7 +428,7 @@ def test_organisation_services_shows_live_services_and_usage( assert services[0].find('a')['href'] == url_for('main.usage', service_id=SERVICE_ONE_ID) assert normalize_spaces(usage_rows[3].text) == "13,000 emails sent" - assert normalize_spaces(usage_rows[4].text) == "£1.93 spent on text messages" + assert normalize_spaces(usage_rows[4].text) == "122 free text messages sent" assert normalize_spaces(usage_rows[5].text) == "£30.50 spent on letters" assert services[1].find('a')['href'] == url_for('main.usage', service_id=SERVICE_TWO_ID) assert normalize_spaces(usage_rows[6].text) == "20,000 emails sent"