Add option to copy existing template when adding

Sometimes when setting up a service you might have a few very similar
templates, in which only a small amount of content. Or you might even
have a few of services, which are used by different teams but have
similar templates.

Copy and pasting, especially from one service to another, is a pain.
This commit makes it easier by allowing users to copy an existing
template when choosing to add a new one, instead of starting from
scratch.
This commit is contained in:
Chris Hill-Scott
2018-07-19 12:30:04 +01:00
parent 078096eecc
commit 19632ea4ab
12 changed files with 293 additions and 10 deletions

View File

@@ -56,17 +56,19 @@ def test_letters_lets_in_without_permission(
@pytest.mark.parametrize('permissions, choices', [
(
['email', 'sms', 'letter'],
['Email', 'Text message', 'Letter']
['Email', 'Text message', 'Letter', 'Copy of an existing template']
),
(
['email', 'sms'],
['Email', 'Text message']
['Email', 'Text message', 'Copy of an existing template']
),
])
def test_given_option_to_add_letters_if_allowed(
logged_in_client,
service_one,
mocker,
mock_get_service_templates,
mock_get_organisations_and_services_for_user,
permissions,
choices,
):

View File

@@ -18,6 +18,8 @@ from tests import (
)
from tests.conftest import (
SERVICE_ONE_ID,
SERVICE_TWO_ID,
TEMPLATE_ONE_ID,
active_caseworking_user,
active_user_view_permissions,
mock_get_service_email_template,
@@ -394,11 +396,127 @@ def test_dont_show_preview_letter_templates_for_bad_filetype(
assert mock_get_service_template.called is False
def test_choosing_to_copy_redirects(
client_request,
mock_get_service_templates,
mock_get_organisations_and_services_for_user,
):
client_request.post(
'main.add_template_by_type',
service_id=SERVICE_ONE_ID,
_data={'template_type': 'copy-existing'}
)
def test_choose_a_template_to_copy(
client_request,
mock_get_service_templates,
mock_get_non_empty_organisations_and_services_for_user,
):
page = client_request.get(
'main.choose_template_to_copy',
service_id=SERVICE_ONE_ID,
)
assert normalize_spaces(
page.select_one('main nav').text
) == normalize_spaces(
'Service 1 '
' sms_template_one '
' Text message template'
' sms_template_two Text message template'
' email_template_one Email template'
' email_template_two Email template '
'Service 2 '
' sms_template_one'
' Text message template'
' sms_template_two'
' Text message template'
' email_template_one'
' Email template'
' email_template_two'
' Email template '
'Org 1 service 1 '
' sms_template_one'
' Text message template'
' sms_template_two'
' Text message template'
' email_template_one'
' Email template'
' email_template_two'
' Email template '
'Org 1 service 2 '
' sms_template_one'
' Text message template'
' sms_template_two'
' Text message template'
' email_template_one'
' Email template'
' email_template_two'
' Email template'
)
assert page.select_one('main nav a')['href'] == url_for(
'main.copy_template',
service_id=SERVICE_ONE_ID,
template_id=TEMPLATE_ONE_ID,
from_service=SERVICE_TWO_ID,
)
def test_load_edit_template_with_copy_of_template(
client_request,
mock_get_service_email_template,
mock_get_non_empty_organisations_and_services_for_user,
):
page = client_request.get(
'main.copy_template',
service_id=SERVICE_ONE_ID,
template_id=TEMPLATE_ONE_ID,
from_service=SERVICE_TWO_ID,
)
assert page.select_one('form')['method'] == 'post'
assert page.select_one('form')['action'] == url_for(
'main.add_service_template',
service_id=SERVICE_ONE_ID,
template_type='email',
)
assert page.select_one('input')['value'] == (
'Copy of Two week reminder'
)
assert page.select_one('textarea').text == (
'Your ((thing)) is due soon'
)
mock_get_service_email_template.assert_called_once_with(
SERVICE_TWO_ID,
TEMPLATE_ONE_ID,
)
def test_cant_copy_template_from_non_member_service(
client_request,
mock_get_service_email_template,
mock_get_organisations_and_services_for_user,
):
client_request.get(
'main.copy_template',
service_id=SERVICE_ONE_ID,
template_id=TEMPLATE_ONE_ID,
from_service=SERVICE_TWO_ID,
_expected_status=403,
)
assert mock_get_service_email_template.call_args_list == []
@pytest.mark.parametrize('type_of_template', ['email', 'sms'])
def test_should_not_allow_creation_of_template_through_form_without_correct_permission(
logged_in_client,
service_one,
mocker,
mock_get_service_templates,
mock_get_organisations_and_services_for_user,
type_of_template,
):
service_one['permissions'] = []