From 862d077f667d165f5b32289add6c1caae2aa64c4 Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Thu, 14 Feb 2019 16:27:13 +0000 Subject: [PATCH] Removed links to add_template_by_type_endpoint The endpoint was removed, but was still linked to in a couple of places. Some old links were no longer needed, so have been removed. We do still need a link to `add_template_by_type` on the 'Choose reply' page - this page is used to allow to let someone pick a template to reply to inbound SMS with. Since the link only appears if they have no SMS templates, we now link to `.choose_template` with the templates and folders form already opened at the option to add a template. --- app/main/views/templates.py | 4 ++++ .../views/templates/choose-reply.html | 2 +- app/templates/views/templates/choose.html | 18 ++++------------ tests/app/main/views/test_conversation.py | 21 +++++++++++++++++++ tests/app/main/views/test_templates.py | 15 +++++++++++++ 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 8019b7692..436a51bb9 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -135,6 +135,10 @@ def choose_template(service_id, template_type='all', template_folder_id=None): if 'templates_and_folders' in templates_and_folders_form.errors: flash('Select at least one template or folder') + initial_state = request.args.get('initial_state') + if request.method == 'GET' and initial_state: + templates_and_folders_form.op = initial_state + return render_template( 'views/templates/choose.html', current_template_folder_id=template_folder_id, diff --git a/app/templates/views/templates/choose-reply.html b/app/templates/views/templates/choose-reply.html index d95b06e13..05856fb89 100644 --- a/app/templates/views/templates/choose-reply.html +++ b/app/templates/views/templates/choose-reply.html @@ -19,7 +19,7 @@

You need a template before you can send text messages.

- Add a new template + Add a new template {% else %}

You need to ask your service manager to add templates before you diff --git a/app/templates/views/templates/choose.html b/app/templates/views/templates/choose.html index 149a7fc3b..ee4cc105d 100644 --- a/app/templates/views/templates/choose.html +++ b/app/templates/views/templates/choose.html @@ -57,17 +57,10 @@ show_fallback_page_title=not current_service.all_template_folders ) }} - {% if current_user.has_permissions('manage_templates') %} - {% if not current_user.has_permissions('manage_templates') %} -

- Add new template -
- {% endif %} - {% if current_user.has_permissions('manage_templates') and current_template_folder_id %} -
- Manage -
- {% endif %} + {% if current_user.has_permissions('manage_templates') and current_template_folder_id %} +
+ Manage +
{% endif %} {% endif %} @@ -90,9 +83,6 @@ {% 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 %} diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index f4bc37d5c..adbbcae45 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -251,6 +251,27 @@ def test_conversation_links_to_reply( ) +def test_conversation_reply_shows_link_to_add_templates_if_service_has_no_templates( + client_request, + fake_uuid, + mock_get_service_templates_when_no_templates_exist, +): + page = client_request.get( + 'main.conversation_reply', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + ) + page_text = page.find('p', class_='bottom-gutter').text + link = page.find('a', text='Add a new template')['href'] + + assert normalize_spaces(page_text) == 'You need a template before you can send text messages.' + assert link == url_for( + 'main.choose_template', + service_id=SERVICE_ONE_ID, + initial_state='add-new-template' + ) + + def test_conversation_reply_shows_templates( client_request, fake_uuid, diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 29fed97d5..de2e6e73c 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -196,6 +196,21 @@ def test_should_show_page_for_choosing_a_template( mock_get_template_folders.assert_called_once_with(SERVICE_ONE_ID) +def test_choose_template_can_pass_through_an_initial_state_to_templates_and_folders_selection_form( + client_request, + mock_get_template_folders, + mock_get_service_templates, +): + page = client_request.get( + 'main.choose_template', + service_id=SERVICE_ONE_ID, + initial_state='add-new-template' + ) + + templates_and_folders_form = page.find('form') + assert templates_and_folders_form['data-prev-state'] == 'add-new-template' + + def test_should_not_show_template_nav_if_only_one_type_of_template( client_request, mock_get_template_folders,