From aaf3322662d34abec01f715f3a1381ac315a6c65 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 3 Jan 2019 10:43:57 +0000 Subject: [PATCH 1/3] Use folder buttons in empty state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s confusing to have one way of adding things when your service is new (green button) but a different way once you’ve added your first thing (the new grey buttons). For services that have a `edit_folders` permission, this commit standardises on the grey buttons for a consistent experience. --- .../views/templates/_template_list.html | 2 +- app/templates/views/templates/choose.html | 8 ++-- tests/app/main/views/test_templates.py | 37 +++++++++++++++---- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/app/templates/views/templates/_template_list.html b/app/templates/views/templates/_template_list.html index e4c030e76..b1be5f719 100644 --- a/app/templates/views/templates/_template_list.html +++ b/app/templates/views/templates/_template_list.html @@ -1,7 +1,7 @@ {% from "components/checkbox.html" import unlabelled_checkbox %} {% from "components/message-count-label.html" import folder_contents_count, message_count_label %} -{% if not template_list.templates_to_show %} +{% if template_list.template_folder_id and not template_list.templates_to_show %}

{% if template_list.folder_is_empty %} This folder is empty diff --git a/app/templates/views/templates/choose.html b/app/templates/views/templates/choose.html index 0b0b0afc3..04e6f131f 100644 --- a/app/templates/views/templates/choose.html +++ b/app/templates/views/templates/choose.html @@ -34,7 +34,6 @@ emails or text messages {%- endif %}.

- Add a new template {% else %}

You need to ask your service manager to add templates before you can send @@ -71,7 +70,7 @@ {% endif %} {% endif %} - + {% endif %} {% if show_template_nav %}

{{ pill(template_nav_items, current_value=template_type, show_count=False) }} @@ -91,7 +90,10 @@ {% else %} {% include 'views/templates/_template_list.html' %} + {% if (not current_service.all_templates) and (not current_service.all_template_folders) and current_user.has_permissions('manage_templates') %} + Add a new template + {% endif %} {% endif %} - {% endif %} + {% endblock %} diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index d05edb241..4d1ab4c92 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -35,21 +35,14 @@ from tests.conftest import service_one as create_sample_service from tests.conftest import single_letter_contact_block -@pytest.mark.parametrize('extra_permissions', ( - [], - ['edit_folders'], -)) def test_should_show_empty_page_when_no_templates( client_request, service_one, mock_get_organisations_and_services_for_user, mock_get_service_templates_when_no_templates_exist, mock_get_template_folders, - extra_permissions, ): - service_one['permissions'] += extra_permissions - page = client_request.get( 'main.choose_template', service_id=service_one['id'], @@ -68,6 +61,36 @@ def test_should_show_empty_page_when_no_templates( assert len(page.select('main a')) == 1 +def test_should_show_add_template_form_if_service_has_folder_permission( + client_request, + service_one, + mock_get_organisations_and_services_for_user, + mock_get_service_templates_when_no_templates_exist, + mock_get_template_folders, +): + + service_one['permissions'] += ['edit_folders'] + + page = client_request.get( + 'main.choose_template', + service_id=service_one['id'], + ) + + assert normalize_spaces(page.select_one('h1').text) == ( + 'Templates' + ) + assert normalize_spaces(page.select_one('main p').text) == ( + 'You need a template before you can send emails or text messages.' + ) + assert [ + (item['name'], item['value']) for item in page.select('[type=radio]') + ] == [ + ('add_template_by_template_type', 'email'), + ('add_template_by_template_type', 'sms'), + ] + assert not page.select('main a') + + @pytest.mark.parametrize( 'user, expected_page_title, extra_args, expected_nav_links, expected_templates', [ From a9baa36005134c2b1073e662b5c97beb1bf430a1 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 3 Jan 2019 10:50:05 +0000 Subject: [PATCH 2/3] =?UTF-8?q?Hide=20=E2=80=98nothing=20selected=E2=80=99?= =?UTF-8?q?=20if=20nothing=20to=20select?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s doesn’t make sense to show the state if the state can’t change. This is especially true when you’re in a brand new, empty service. --- app/assets/javascripts/templateFolderForm.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/assets/javascripts/templateFolderForm.js b/app/assets/javascripts/templateFolderForm.js index f3adfe5cf..5f9079fbf 100644 --- a/app/assets/javascripts/templateFolderForm.js +++ b/app/assets/javascripts/templateFolderForm.js @@ -111,6 +111,12 @@ $('.template-list-selected-counter-count').html(numSelected); + $('.template-list-selected-counter').toggle(this.hasCheckboxes()); + + }; + + this.hasCheckboxes = function() { + return !!this.$form.find('input:checkbox').length; }; this.countSelectedCheckboxes = function() { From ecf6ebb1262d038836f033dd2a8403d93ada8165 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 3 Jan 2019 11:07:05 +0000 Subject: [PATCH 3/3] Equalise space before/after paragraph --- app/templates/views/templates/choose.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/views/templates/choose.html b/app/templates/views/templates/choose.html index 04e6f131f..1ef5c1c80 100644 --- a/app/templates/views/templates/choose.html +++ b/app/templates/views/templates/choose.html @@ -26,7 +26,7 @@ {{ page_title }} {% if current_user.has_permissions('manage_templates') %} -

+

You need a template before you can send {% if 'letter' in current_service.permissions %} emails, text messages or letters @@ -35,7 +35,7 @@ {%- endif %}.

{% else %} -

+

You need to ask your service manager to add templates before you can send {% if 'letter' in current_service.permissions %} emails, text messages or letters