From 41624295c91e24e6b9e154812a82c8055907809f Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Tue, 14 Jul 2020 14:45:56 +0100
Subject: [PATCH 1/3] Refactor conditional inside paragraph
This will make it easier to add more branches later.
---
app/templates/views/templates/choose.html | 30 +++++++++--------------
1 file changed, 12 insertions(+), 18 deletions(-)
diff --git a/app/templates/views/templates/choose.html b/app/templates/views/templates/choose.html
index db0851de4..6a536c8ca 100644
--- a/app/templates/views/templates/choose.html
+++ b/app/templates/views/templates/choose.html
@@ -21,25 +21,19 @@
{{ page_title }}
- {% if current_user.has_permissions('manage_templates') %}
-
+
+
+ {% 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
- {%- else -%}
- emails or text messages
- {%- 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
- {%- else -%}
- emails or text messages
- {%- endif %}.
-
- {% endif %}
+ {% else %}
+ You need to ask your service manager to add templates before you can send
+ {% endif %}
+ {% if 'letter' in current_service.permissions %}
+ emails, text messages or letters
+ {%- else -%}
+ emails or text messages
+ {%- endif %}.
+
{% else %}
From 008e4befb484700770e1ba032734ab1ca0810c8b Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Tue, 14 Jul 2020 14:52:52 +0100
Subject: [PATCH 2/3] =?UTF-8?q?Add=20=E2=80=98no=20templates=E2=80=99=20me?=
=?UTF-8?q?ssage=20for=20broadcast=20services?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This shouldn’t talk about emails, text messages or letters.
---
app/templates/views/templates/choose.html | 17 +++++++++------
tests/app/main/views/test_templates.py | 26 ++++++++++++++++++++++-
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/app/templates/views/templates/choose.html b/app/templates/views/templates/choose.html
index 6a536c8ca..31b5611b7 100644
--- a/app/templates/views/templates/choose.html
+++ b/app/templates/views/templates/choose.html
@@ -24,14 +24,19 @@
{% if current_user.has_permissions('manage_templates') %}
- You need a template before you can send
+ You need a template before you can
{% else %}
- You need to ask your service manager to add templates before you can send
+ You need to ask your service manager to add templates before you can
{% endif %}
- {% if 'letter' in current_service.permissions %}
- emails, text messages or letters
- {%- else -%}
- emails or text messages
+ {% if current_service.has_permission('broadcast') %}
+ prepare a broadcast
+ {%- else %}
+ send
+ {% if 'letter' in current_service.permissions %}
+ emails, text messages or letters
+ {%- else -%}
+ emails or text messages
+ {%- endif %}
{%- endif %}.
diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py
index 4a8c8bb72..9eb4483a1 100644
--- a/tests/app/main/views/test_templates.py
+++ b/tests/app/main/views/test_templates.py
@@ -27,13 +27,37 @@ from tests.conftest import (
)
+@pytest.mark.parametrize('permissions, expected_message', (
+ (['email'], (
+ 'You need a template before you can send emails or text messages.'
+ )),
+ (['sms'], (
+ 'You need a template before you can send emails or text messages.'
+ )),
+ (['letter'], (
+ 'You need a template before you can send emails, text messages or letters.'
+ )),
+ (['sms', 'letter'], (
+ 'You need a template before you can send emails, text messages or letters.'
+ )),
+ (['email', 'sms', 'letter'], (
+ 'You need a template before you can send emails, text messages or letters.'
+ )),
+ (['broadcast'], (
+ 'You need a template before you can prepare a broadcast.'
+ )),
+))
def test_should_show_empty_page_when_no_templates(
client_request,
service_one,
mock_get_service_templates_when_no_templates_exist,
mock_get_template_folders,
+ permissions,
+ expected_message,
):
+ service_one['permissions'] = permissions
+
page = client_request.get(
'main.choose_template',
service_id=service_one['id'],
@@ -43,7 +67,7 @@ def test_should_show_empty_page_when_no_templates(
'Templates'
)
assert normalize_spaces(page.select_one('main p').text) == (
- 'You need a template before you can send emails or text messages.'
+ expected_message
)
assert page.select_one('#add_new_folder_form')
assert page.select_one('#add_new_template_form')
From 9dfa48cfdd47277bfbe588966a36cdc1f174561f Mon Sep 17 00:00:00 2001
From: Chris Hill-Scott
Date: Tue, 14 Jul 2020 14:54:55 +0100
Subject: [PATCH 3/3] =?UTF-8?q?Don=E2=80=99t=20treat=20letters=20as=20a=20?=
=?UTF-8?q?special=20case?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This conditional comes from before we launched the letters feature.
Since we were only giving the letters permission to teams that we were
inviting, we didn’t want to confuse new users by mentioning letters.
Nowadays all new services will have the letters permission, so this
check is redundant.
---
app/templates/views/templates/choose.html | 7 +------
tests/app/main/views/test_templates.py | 13 +++++--------
2 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/app/templates/views/templates/choose.html b/app/templates/views/templates/choose.html
index 31b5611b7..505d6f527 100644
--- a/app/templates/views/templates/choose.html
+++ b/app/templates/views/templates/choose.html
@@ -31,12 +31,7 @@
{% if current_service.has_permission('broadcast') %}
prepare a broadcast
{%- else %}
- send
- {% if 'letter' in current_service.permissions %}
- emails, text messages or letters
- {%- else -%}
- emails or text messages
- {%- endif %}
+ send emails, text messages or letters
{%- endif %}.
diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py
index 9eb4483a1..edf61202a 100644
--- a/tests/app/main/views/test_templates.py
+++ b/tests/app/main/views/test_templates.py
@@ -29,15 +29,12 @@ from tests.conftest import (
@pytest.mark.parametrize('permissions, expected_message', (
(['email'], (
- 'You need a template before you can send emails or text messages.'
- )),
- (['sms'], (
- 'You need a template before you can send emails or text messages.'
- )),
- (['letter'], (
'You need a template before you can send emails, text messages or letters.'
)),
- (['sms', 'letter'], (
+ (['sms'], (
+ 'You need a template before you can send emails, text messages or letters.'
+ )),
+ (['letter'], (
'You need a template before you can send emails, text messages or letters.'
)),
(['email', 'sms', 'letter'], (
@@ -88,7 +85,7 @@ def test_should_show_add_template_form_if_service_has_folder_permission(
'Templates'
)
assert normalize_spaces(page.select_one('main p').text) == (
- 'You need a template before you can send emails or text messages.'
+ 'You need a template before you can send emails, text messages or letters.'
)
assert [
(item['name'], item['value']) for item in page.select('[type=radio]')