diff --git a/app/__init__.py b/app/__init__.py index c8224e21e..dd668fee8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -93,7 +93,6 @@ from app.notify_client import InviteTokenError from app.notify_client.api_key_api_client import api_key_api_client from app.notify_client.billing_api_client import billing_api_client from app.notify_client.complaint_api_client import complaint_api_client -from app.notify_client.email_branding_client import email_branding_client from app.notify_client.events_api_client import events_api_client from app.notify_client.inbound_number_client import inbound_number_client from app.notify_client.invite_api_client import invite_api_client @@ -186,7 +185,6 @@ def create_app(application): api_key_api_client, billing_api_client, complaint_api_client, - email_branding_client, events_api_client, inbound_number_client, invite_api_client, diff --git a/app/assets/javascripts/previewPane.js b/app/assets/javascripts/previewPane.js deleted file mode 100644 index 4266b8590..000000000 --- a/app/assets/javascripts/previewPane.js +++ /dev/null @@ -1,36 +0,0 @@ -(function (global) { - - 'use strict'; - - $ = global.jQuery; - - let branding_style = $('.usa-radio input[name="branding_style"]:checked'); - - if (!branding_style.length) { return; } - - branding_style = branding_style.val(); - - const $paneWrapper = $('
'); - const $form = $('form'); - const previewType = $form.data('previewType'); - const $previewPane = $(``); - - function buildQueryString () { - return $.map(arguments, (val, idx) => encodeURI(val[0]) + '=' + encodeURI(val[1])).join('&'); - } - - function setPreviewPane (e) { - const $target = $(e.target); - if ($target.attr('name') == 'branding_style') { - branding_style = $target.val(); - } - $previewPane.attr('src', `/_${previewType}?${buildQueryString(['branding_style', branding_style])}`); - } - - $paneWrapper.append($previewPane); - $form.find('.govuk-grid-row').eq(0).prepend($paneWrapper); - $form.attr('action', location.pathname.replace(new RegExp(`set-${previewType}-branding$`), `preview-${previewType}-branding`)); - $form.find('button[type="submit"]').text('Save'); - - $('fieldset').on('change', 'input[name="branding_style"]', setPreviewPane); -})(window); diff --git a/app/main/__init__.py b/app/main/__init__.py index 325a82e93..8626582f2 100644 --- a/app/main/__init__.py +++ b/app/main/__init__.py @@ -9,7 +9,6 @@ from app.main.views import ( # noqa isort:skip code_not_received, conversation, dashboard, - email_branding, feedback, find_services, find_users, diff --git a/app/main/forms.py b/app/main/forms.py index 2f18b3b88..56fdca51b 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -63,7 +63,7 @@ from app.main.validators import ( ) from app.models.feedback import PROBLEM_TICKET_TYPE, QUESTION_TICKET_TYPE from app.models.organization import Organization -from app.utils import branding, merge_jsonlike +from app.utils import merge_jsonlike from app.utils.csv import get_user_preferred_timezone from app.utils.user_permissions import all_ui_permissions, permission_options @@ -1543,65 +1543,6 @@ class ServiceSwitchChannelForm(ServiceOnOffSettingForm): super().__init__(name, *args, **kwargs) -class AdminSetEmailBrandingForm(StripWhitespaceForm): - branding_style = GovukRadiosFieldWithNoneOption( - "Branding style", - param_extensions={"fieldset": {"legend": {"classes": "usa-sr-only"}}}, - thing="a branding style", - ) - - DEFAULT = (FieldWithNoneOption.NONE_OPTION_VALUE, "GOV.UK") - - def __init__(self, all_branding_options, current_branding): - super().__init__(branding_style=current_branding) - - self.branding_style.choices = sorted( - all_branding_options + [self.DEFAULT], - key=lambda branding: ( - branding[0] != current_branding, - branding[0] is not self.DEFAULT[0], - branding[1].lower(), - ), - ) - - -class AdminPreviewBrandingForm(StripWhitespaceForm): - branding_style = HiddenFieldWithNoneOption("branding_style") - - -class AdminEditEmailBrandingForm(StripWhitespaceForm): - name = GovukTextInputField("Name of brand") - text = GovukTextInputField("Text") - colour = GovukTextInputField( - "Colour", - validators=[ - Regexp( - regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", - message="Must be a valid color hex code (starting with #)", - ) - ], - param_extensions={ - "attributes": {"data-module": "colour-preview"}, - }, - ) - file = FileField_wtf( - "Upload a PNG logo", validators=[FileAllowed(["png"], "PNG Images only!")] - ) - brand_type = GovukRadiosField( - "Brand type", - choices=[ - ("both", "GOV.UK and branding"), - ("org", "Branding only"), - ("org_banner", "Branding banner"), - ], - ) - - def validate_name(self, name): - op = request.form.get("operation") - if op == "email-branding-details" and not self.name.data: - raise ValidationError("This field is required") - - class SVGFileUpload(StripWhitespaceForm): file = FileField_wtf( "Upload an SVG logo", @@ -1816,42 +1757,6 @@ class AdminSetOrganizationForm(StripWhitespaceForm): ) -class ChooseBrandingForm(StripWhitespaceForm): - FALLBACK_OPTION_VALUE = "something_else" - FALLBACK_OPTION = (FALLBACK_OPTION_VALUE, "Something else") - - @property - def something_else_is_only_option(self): - return self.options.choices == (self.FALLBACK_OPTION,) - - -class ChooseEmailBrandingForm(ChooseBrandingForm): - options = RadioField("Choose your new email branding") - - def __init__(self, service): - super().__init__() - - self.options.choices = tuple( - list(branding.get_email_choices(service)) + [self.FALLBACK_OPTION] - ) - - -class SomethingElseBrandingForm(StripWhitespaceForm): - something_else = GovukTextareaField( - "Describe the branding you want", - validators=[DataRequired("Cannot be empty")], - param_extensions={ - "label": { - "isPageHeading": True, - "classes": "font-body-xl", - }, - "hint": { - "text": "Include links to your brand guidelines or examples of how to use your branding." - }, - }, - ) - - class AdminServiceAddDataRetentionForm(StripWhitespaceForm): notification_type = GovukRadiosField( "What notification type?", diff --git a/app/main/views/email_branding.py b/app/main/views/email_branding.py deleted file mode 100644 index 4a050f849..000000000 --- a/app/main/views/email_branding.py +++ /dev/null @@ -1,133 +0,0 @@ -from flask import current_app, redirect, render_template, session, url_for - -from app import email_branding_client -from app.main import main -from app.main.forms import AdminEditEmailBrandingForm, SearchByNameForm -from app.s3_client.s3_logo_client import ( - TEMP_TAG, - delete_email_temp_file, - delete_email_temp_files_created_by, - permanent_email_logo_name, - persist_logo, - upload_email_logo, -) -from app.utils.user import user_is_platform_admin - - -@main.route("/email-branding", methods=["GET", "POST"]) -@user_is_platform_admin -def email_branding(): - brandings = email_branding_client.get_all_email_branding(sort_key="name") - - return render_template( - "views/email-branding/select-branding.html", - email_brandings=brandings, - search_form=SearchByNameForm(), - ) - - -@main.route("/email-branding//edit", methods=["GET", "POST"]) -@main.route("/email-branding//edit/", methods=["GET", "POST"]) -@user_is_platform_admin -def update_email_branding(branding_id, logo=None): - email_branding = email_branding_client.get_email_branding(branding_id)[ - "email_branding" - ] - - form = AdminEditEmailBrandingForm( - name=email_branding["name"], - text=email_branding["text"], - colour=email_branding["colour"], - brand_type=email_branding["brand_type"], - ) - - logo = logo if logo else email_branding.get("logo") if email_branding else None - - if form.validate_on_submit(): - if form.file.data: - upload_filename = upload_email_logo( - form.file.data.filename, form.file.data, user_id=session["user_id"] - ) - - if logo and logo.startswith(TEMP_TAG.format(user_id=session["user_id"])): - delete_email_temp_file(logo) - - return redirect( - url_for( - ".update_email_branding", - branding_id=branding_id, - logo=upload_filename, - ) - ) - - updated_logo_name = ( - permanent_email_logo_name(logo, session["user_id"]) if logo else None - ) - - email_branding_client.update_email_branding( - branding_id=branding_id, - logo=updated_logo_name, - name=form.name.data, - text=form.text.data, - colour=form.colour.data, - brand_type=form.brand_type.data, - ) - - if logo: - persist_logo(logo, updated_logo_name) - - delete_email_temp_files_created_by(session["user_id"]) - - return redirect(url_for(".email_branding", branding_id=branding_id)) - - return render_template( - "views/email-branding/manage-branding.html", - form=form, - email_branding=email_branding, - cdn_url=current_app.config["LOGO_CDN_DOMAIN"], - logo=logo, - ) - - -@main.route("/email-branding/create", methods=["GET", "POST"]) -@main.route("/email-branding/create/", methods=["GET", "POST"]) -@user_is_platform_admin -def create_email_branding(logo=None): - form = AdminEditEmailBrandingForm(brand_type="org") - - if form.validate_on_submit(): - if form.file.data: - upload_filename = upload_email_logo( - form.file.data.filename, form.file.data, user_id=session["user_id"] - ) - - if logo and logo.startswith(TEMP_TAG.format(user_id=session["user_id"])): - delete_email_temp_file(logo) - - return redirect(url_for(".create_email_branding", logo=upload_filename)) - - updated_logo_name = ( - permanent_email_logo_name(logo, session["user_id"]) if logo else None - ) - - email_branding_client.create_email_branding( - logo=updated_logo_name, - name=form.name.data, - text=form.text.data, - colour=form.colour.data, - brand_type=form.brand_type.data, - ) - - if logo: - persist_logo(logo, updated_logo_name) - - delete_email_temp_files_created_by(session["user_id"]) - - return redirect(url_for(".email_branding")) - - return render_template( - "views/email-branding/manage-branding.html", - form=form, - cdn_url=current_app.config["LOGO_CDN_DOMAIN"], - logo=logo, - ) diff --git a/app/main/views/index.py b/app/main/views/index.py index 30818db99..044543526 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -1,18 +1,8 @@ -from flask import ( - abort, - current_app, - make_response, - redirect, - render_template, - request, - url_for, -) +from flask import abort, redirect, render_template, request, url_for from flask_login import current_user -from notifications_utils.template import HTMLEmailTemplate -from app import email_branding_client, status_api_client +from app import status_api_client from app.main import main -from app.main.forms import FieldWithNoneOption from app.main.views.pricing import CURRENT_SMS_RATE from app.main.views.sub_navigation_dictionaries import features_nav, using_notify_nav from app.utils.user import user_is_logged_in @@ -63,105 +53,6 @@ def design_content(): ) -@main.route("/_email") -@user_is_logged_in -def email_template(): - branding_type = "govuk" - branding_style = request.args.get("branding_style", None) - - if branding_style == FieldWithNoneOption.NONE_OPTION_VALUE: - branding_style = None - - if branding_style is not None: - email_branding = email_branding_client.get_email_branding(branding_style)[ - "email_branding" - ] - branding_type = email_branding["brand_type"] - - if branding_type == "govuk": - brand_text = None - brand_colour = None - brand_logo = None - govuk_banner = True - brand_banner = False - brand_name = None - else: - colour = email_branding["colour"] - brand_text = email_branding["text"] - brand_colour = colour - brand_logo = ( - f"https://{current_app.config['LOGO_CDN_DOMAIN']}/{email_branding['logo']}" - if email_branding["logo"] - else None - ) - govuk_banner = branding_type in ["govuk", "both"] - brand_banner = branding_type == "org_banner" - brand_name = email_branding["name"] - - template = { - "template_type": "email", - "subject": "Email branding preview", - "content": ( - "Lorem Ipsum is simply dummy text of the printing and typesetting " - "industry.\n\nLorem Ipsum has been the industry’s standard dummy " - "text ever since the 1500s, when an unknown printer took a galley " - "of type and scrambled it to make a type specimen book. " - "\n\n" - "# History" - "\n\n" - "It has " - "survived not only" - "\n\n" - "* five centuries" - "\n" - "* but also the leap into electronic typesetting" - "\n\n" - "It was " - "popularised in the 1960s with the release of Letraset sheets " - "containing Lorem Ipsum passages, and more recently with desktop " - "publishing software like Aldus PageMaker including versions of " - "Lorem Ipsum." - "\n\n" - "^ It is a long established fact that a reader will be distracted " - "by the readable content of a page when looking at its layout." - "\n\n" - "The point of using Lorem Ipsum is that it has a more-or-less " - "normal distribution of letters, as opposed to using ‘Content " - "here, content here’, making it look like readable English." - "\n\n\n" - "1. One" - "\n" - "2. Two" - "\n" - "10. Three" - "\n\n" - "This is an example of an email sent using Notify.gov." - "\n\n" - "https://www.notifications.service.gov.uk" - ), - } - - if not bool(request.args): - resp = make_response(str(HTMLEmailTemplate(template))) - else: - resp = make_response( - str( - HTMLEmailTemplate( - template, - govuk_banner=govuk_banner, - brand_text=brand_text, - brand_colour=brand_colour, - brand_logo=brand_logo, - brand_banner=brand_banner, - brand_name=brand_name, - ) - ) - ) - - resp.headers["X-Frame-Options"] = "SAMEORIGIN" - return resp - - @main.route("/documentation") @user_is_logged_in def documentation(): @@ -196,14 +87,6 @@ def roadmap(): return render_template("views/roadmap.html", navigation_links=features_nav()) -@main.route("/features/email") -@user_is_logged_in -def features_email(): - return render_template( - "views/features/emails.html", navigation_links=features_nav() - ) - - @main.route("/features/sms") @user_is_logged_in def features_sms(): @@ -288,15 +171,6 @@ def guidance_index(): ) -@main.route("/using-notify/guidance/branding-and-customisation") -@user_is_logged_in -def branding_and_customisation(): - return render_template( - "views/guidance/branding-and-customisation.html", - navigation_links=using_notify_nav(), - ) - - @main.route("/using-notify/guidance/create-and-send-messages") @user_is_logged_in def create_and_send_messages(): diff --git a/app/main/views/organizations.py b/app/main/views/organizations.py index 1a1ba44f2..ed5c7ca9d 100644 --- a/app/main/views/organizations.py +++ b/app/main/views/organizations.py @@ -6,12 +6,7 @@ from flask import flash, redirect, render_template, request, url_for from flask_login import current_user from notifications_python_client.errors import HTTPError -from app import ( - current_organization, - email_branding_client, - org_invite_api_client, - organizations_client, -) +from app import current_organization, org_invite_api_client, organizations_client from app.main import main from app.main.forms import ( AdminBillingDetailsForm, @@ -19,8 +14,6 @@ from app.main.forms import ( AdminNotesForm, AdminOrganizationDomainsForm, AdminOrganizationGoLiveNotesForm, - AdminPreviewBrandingForm, - AdminSetEmailBrandingForm, InviteOrgUserForm, OrganizationOrganizationTypeForm, RenameOrganizationForm, @@ -31,7 +24,6 @@ from app.main.views.dashboard import ( get_tuples_of_financial_years, requested_and_current_financial_year, ) -from app.main.views.service_settings import get_branding_as_value_and_label from app.models.organization import AllOrganizations, Organization from app.models.user import InvitedOrgUser, User from app.utils.csv import Spreadsheet @@ -283,58 +275,6 @@ def edit_organization_type(org_id): ) -@main.route( - "/organizations//settings/set-email-branding", methods=["GET", "POST"] -) -@user_is_platform_admin -def edit_organization_email_branding(org_id): - email_branding = email_branding_client.get_all_email_branding() - - form = AdminSetEmailBrandingForm( - all_branding_options=get_branding_as_value_and_label(email_branding), - current_branding=current_organization.email_branding_id, - ) - - if form.validate_on_submit(): - return redirect( - url_for( - ".organization_preview_email_branding", - org_id=org_id, - branding_style=form.branding_style.data, - ) - ) - - return render_template( - "views/organizations/organization/settings/set-email-branding.html", - form=form, - search_form=SearchByNameForm(), - ) - - -@main.route( - "/organizations//settings/preview-email-branding", - methods=["GET", "POST"], -) -@user_is_platform_admin -def organization_preview_email_branding(org_id): - branding_style = request.args.get("branding_style", None) - - form = AdminPreviewBrandingForm(branding_style=branding_style) - - if form.validate_on_submit(): - current_organization.update( - email_branding_id=form.branding_style.data, - delete_services_cache=True, - ) - return redirect(url_for(".organization_settings", org_id=org_id)) - - return render_template( - "views/organizations/organization/settings/preview-email-branding.html", - form=form, - action=url_for("main.organization_preview_email_branding", org_id=org_id), - ) - - @main.route( "/organizations//settings/edit-organization-domains", methods=["GET", "POST"], diff --git a/app/main/views/platform_admin.py b/app/main/views/platform_admin.py index f953d1e58..802ed5b18 100644 --- a/app/main/views/platform_admin.py +++ b/app/main/views/platform_admin.py @@ -596,13 +596,6 @@ def clear_cache(): "service-????????-????-????-????-????????????-template-????????-????-????-????-????????????-versions", # noqa ], ), - ( - "email_branding", - [ - "email_branding", - "email_branding-????????-????-????-????-????????????", - ], - ), ( "organization", [ diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 70ad3ef92..05f219ab6 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -18,7 +18,6 @@ from notifications_utils.clients.zendesk.zendesk_client import NotifySupportTick from app import ( billing_api_client, current_service, - email_branding_client, inbound_number_client, notification_api_client, organizations_client, @@ -35,16 +34,13 @@ from app.main import main from app.main.forms import ( AdminBillingDetailsForm, AdminNotesForm, - AdminPreviewBrandingForm, AdminServiceAddDataRetentionForm, AdminServiceEditDataRetentionForm, AdminServiceInboundNumberForm, AdminServiceMessageLimitForm, AdminServiceRateLimitForm, AdminServiceSMSAllowanceForm, - AdminSetEmailBrandingForm, AdminSetOrganizationForm, - ChooseEmailBrandingForm, EstimateUsageForm, RenameServiceForm, SearchByNameForm, @@ -55,10 +51,8 @@ from app.main.forms import ( ServiceSmsSenderForm, ServiceSwitchChannelForm, SMSPrefixForm, - SomethingElseBrandingForm, ) from app.utils import DELIVERED_STATUSES, FAILURE_STATUSES, SENDING_STATUSES -from app.utils.branding import get_email_choices as get_email_branding_choices from app.utils.time import parse_naive_dt from app.utils.user import ( user_has_permissions, @@ -87,7 +81,6 @@ def service_settings(service_id): return render_template( "views/service-settings.html", service_permissions=PLATFORM_ADMIN_SERVICE_PERMISSIONS, - email_branding_options=ChooseEmailBrandingForm(current_service), ) @@ -876,57 +869,6 @@ def set_rate_limit(service_id): ) -@main.route( - "/services//service-settings/set-email-branding", - methods=["GET", "POST"], -) -@user_is_platform_admin -def service_set_email_branding(service_id): - email_branding = email_branding_client.get_all_email_branding() - - form = AdminSetEmailBrandingForm( - all_branding_options=get_branding_as_value_and_label(email_branding), - current_branding=current_service.email_branding_id, - ) - - if form.validate_on_submit(): - return redirect( - url_for( - ".service_preview_email_branding", - service_id=service_id, - branding_style=form.branding_style.data, - ) - ) - - return render_template( - "views/service-settings/set-email-branding.html", - form=form, - search_form=SearchByNameForm(), - ) - - -@main.route( - "/services//service-settings/preview-email-branding", - methods=["GET", "POST"], -) -@user_is_platform_admin -def service_preview_email_branding(service_id): - branding_style = request.args.get("branding_style", None) - - form = AdminPreviewBrandingForm(branding_style=branding_style) - - if form.validate_on_submit(): - current_service.update(email_branding=form.branding_style.data) - return redirect(url_for(".service_settings", service_id=service_id)) - - return render_template( - "views/service-settings/preview-email-branding.html", - form=form, - service_id=service_id, - action=url_for("main.service_preview_email_branding", service_id=service_id), - ) - - @main.route( "/services//service-settings/link-service-to-organization", methods=["GET", "POST"], @@ -957,145 +899,6 @@ def link_service_to_organization(service_id): ) -def create_email_branding_zendesk_ticket(form_option_selected, detail=None): - form = ChooseEmailBrandingForm(current_service) - - ticket_message = render_template( - "support-tickets/branding-request.txt", - current_branding=current_service.email_branding_name, - branding_requested=dict(form.options.choices)[form_option_selected], - detail=detail, - ) - ticket = NotifySupportTicket( - subject=f"Email branding request - {current_service.name}", - message=ticket_message, - ticket_type=NotifySupportTicket.TYPE_QUESTION, - user_name=current_user.name, - user_email=current_user.email_address, - org_id=current_service.organization_id, - org_type=current_service.organization_type, - service_id=current_service.id, - ) - zendesk_client.send_ticket_to_zendesk(ticket) - - -@main.route( - "/services//service-settings/email-branding", - methods=["GET", "POST"], -) -@user_has_permissions("manage_service") -def email_branding_request(service_id): - form = ChooseEmailBrandingForm(current_service) - branding_name = current_service.email_branding_name - if form.validate_on_submit(): - return redirect( - url_for( - f".email_branding_{form.options.data}", - service_id=current_service.id, - ) - ) - - return render_template( - "views/service-settings/branding/email-branding-options.html", - form=form, - branding_name=branding_name, - ) - - -def check_email_branding_allowed_for_service(branding): - allowed_branding_for_service = dict(get_email_branding_choices(current_service)) - - if branding not in allowed_branding_for_service: - abort(404) - - -@main.route( - "/services//service-settings/email-branding/govuk", - methods=["GET", "POST"], -) -@user_has_permissions("manage_service") -def email_branding_govuk(service_id): - check_email_branding_allowed_for_service("govuk") - - if request.method == "POST": - current_service.update(email_branding=None) - - flash("You’ve updated your email branding", "default") - return redirect(url_for(".service_settings", service_id=current_service.id)) - - return render_template("views/service-settings/branding/email-branding-govuk.html") - - -@main.route( - "/services//service-settings/email-branding/govuk-and-org", - methods=["GET", "POST"], -) -@user_has_permissions("manage_service") -def email_branding_govuk_and_org(service_id): - check_email_branding_allowed_for_service("govuk_and_org") - - if request.method == "POST": - create_email_branding_zendesk_ticket("govuk_and_org") - - flash( - "Thanks for your branding request. We’ll get back to you within one working day.", - "default", - ) - return redirect(url_for(".service_settings", service_id=current_service.id)) - - return render_template( - "views/service-settings/branding/email-branding-govuk-org.html" - ) - - -@main.route( - "/services//service-settings/email-branding/organization", - methods=["GET", "POST"], -) -@user_has_permissions("manage_service") -def email_branding_organization(service_id): - check_email_branding_allowed_for_service("organization") - - if request.method == "POST": - create_email_branding_zendesk_ticket("organization") - - flash( - "Thanks for your branding request. We’ll get back to you within one working day.", - "default", - ) - return redirect(url_for(".service_settings", service_id=current_service.id)) - - return render_template( - "views/service-settings/branding/email-branding-organization.html" - ) - - -@main.route( - "/services//service-settings/email-branding/something-else", - methods=["GET", "POST"], -) -@user_has_permissions("manage_service") -def email_branding_something_else(service_id): - form = SomethingElseBrandingForm() - - if form.validate_on_submit(): - create_email_branding_zendesk_ticket( - "something_else", detail=form.something_else.data - ) - - flash( - "Thanks for your branding request. We’ll get back to you within one working day.", - "default", - ) - return redirect(url_for(".service_settings", service_id=current_service.id)) - - return render_template( - "views/service-settings/branding/email-branding-something-else.html", - form=form, - branding_options=ChooseEmailBrandingForm(current_service), - ) - - @main.route("/services//data-retention", methods=["GET"]) @user_is_platform_admin def data_retention(service_id): @@ -1184,10 +987,6 @@ def edit_service_billing_details(service_id): ) -def get_branding_as_value_and_label(email_branding): - return [(branding["id"], branding["name"]) for branding in email_branding] - - def convert_dictionary_to_wtforms_choices_format(dictionary, value, label): return [(item[value], item[label]) for item in dictionary] diff --git a/app/main/views/sub_navigation_dictionaries.py b/app/main/views/sub_navigation_dictionaries.py index 609e74814..f76d69c14 100644 --- a/app/main/views/sub_navigation_dictionaries.py +++ b/app/main/views/sub_navigation_dictionaries.py @@ -4,10 +4,6 @@ def features_nav(): "name": "Features", "link": "main.features", "sub_navigation_items": [ - # { - # "name": "Emails", - # "link": "main.features_email", - # }, # { # "name": "Text messages", # "link": "main.features_sms", @@ -56,10 +52,6 @@ def using_notify_nav(): # "link": "main.edit_and_format_messages", # }, # { - # "name": "Branding", - # "link": "main.branding_and_customisation", - # }, - # { # "name": "Send files by email", # "link": "main.send_files_by_email", # }, diff --git a/app/models/event.py b/app/models/event.py index 548123b58..b988ba3b4 100644 --- a/app/models/event.py +++ b/app/models/event.py @@ -66,9 +66,6 @@ class ServiceEvent(Event): def format_contact_link(self): return "Set the contact details for this service to ‘{}’".format(self.value_to) - def format_email_branding(self): - return "Updated this service’s email branding" - def format_inbound_api(self): return "Updated the callback for received text messages" diff --git a/app/models/organization.py b/app/models/organization.py index 8be65a662..87b0bdff9 100644 --- a/app/models/organization.py +++ b/app/models/organization.py @@ -3,7 +3,6 @@ from collections import OrderedDict from werkzeug.utils import cached_property from app.models import JSONModel, ModelList, SerialisedModelCollection, SortByNameMixin -from app.notify_client.email_branding_client import email_branding_client from app.notify_client.organizations_api_client import organizations_client @@ -25,7 +24,6 @@ class Organization(JSONModel, SortByNameMixin): "name", "active", "organization_type", - "email_branding_id", "domains", "request_to_go_live_notes", "count_of_live_services", @@ -74,7 +72,6 @@ class Organization(JSONModel, SortByNameMixin): self.domains = [] self.organization_type = None self.request_to_go_live_notes = None - self.email_branding_id = None @property def organization_type_label(self): @@ -128,19 +125,6 @@ class Organization(JSONModel, SortByNameMixin): key=lambda user: user.email_address.lower(), ) - @cached_property - def email_branding(self): - if self.email_branding_id: - return email_branding_client.get_email_branding(self.email_branding_id)[ - "email_branding" - ] - - @property - def email_branding_name(self): - if self.email_branding_id: - return self.email_branding["name"] - return "GOV.UK" - def update(self, delete_services_cache=False, **kwargs): response = organizations_client.update_organization( self.id, diff --git a/app/models/service.py b/app/models/service.py index 9a0cdd1e7..81b604f50 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -8,7 +8,6 @@ from app.models.organization import Organization from app.models.user import InvitedUsers, User, Users from app.notify_client.api_key_api_client import api_key_api_client from app.notify_client.billing_api_client import billing_api_client -from app.notify_client.email_branding_client import email_branding_client from app.notify_client.inbound_number_client import inbound_number_client from app.notify_client.invite_api_client import invite_api_client from app.notify_client.job_api_client import job_api_client @@ -408,31 +407,6 @@ class Service(JSONModel, SortByNameMixin): {}, ).get("days_of_retention", current_app.config["ACTIVITY_STATS_LIMIT_DAYS"]) - @property - def email_branding_id(self): - return self._dict["email_branding"] - - @cached_property - def email_branding(self): - if self.email_branding_id: - return email_branding_client.get_email_branding(self.email_branding_id)[ - "email_branding" - ] - return None - - @cached_property - def email_branding_name(self): - if self.email_branding is None: - return "GOV.UK" - return self.email_branding["name"] - - @property - def needs_to_change_email_branding(self): - return ( - self.email_branding_id is None - and self.organization_type != Organization.TYPE_CENTRAL - ) - @cached_property def organization(self): return Organization.from_id(self.organization_id) diff --git a/app/navigation.py b/app/navigation.py index d5af628ab..931d3caad 100644 --- a/app/navigation.py +++ b/app/navigation.py @@ -47,7 +47,6 @@ class HeaderNavigation(Navigation): }, "features": { "features", - "features_email", "features_sms", "roadmap", "security", @@ -102,11 +101,6 @@ class HeaderNavigation(Navigation): "manage_users", "remove_user_from_service", "usage", - "email_branding_govuk", - "email_branding_govuk_and_org", - "email_branding_organization", - "email_branding_request", - "email_branding_something_else", "estimate_usage", "link_service_to_organization", "request_to_go_live", @@ -118,11 +112,9 @@ class HeaderNavigation(Navigation): "service_edit_sms_sender", "service_email_reply_to", "service_name_change", - "service_preview_email_branding", "service_set_auth_type", "service_set_channel", "send_files_by_email_contact_details", - "service_set_email_branding", "service_set_inbound_number", "service_set_inbound_sms", "service_set_international_sms", @@ -164,8 +156,6 @@ class HeaderNavigation(Navigation): "archive_user", "change_user_auth", "clear_cache", - "create_email_branding", - "email_branding", "find_services_by_name", "find_users_by_email", "live_services", @@ -183,7 +173,6 @@ class HeaderNavigation(Navigation): "platform_admin_splash_page", "suspend_service", "trial_services", - "update_email_branding", "user_information", }, "sign-in": { @@ -256,12 +245,6 @@ class MainNavigation(Navigation): "usage", }, "settings": { - # 'add_organization_from_gp_service', - "email_branding_govuk", - "email_branding_govuk_and_org", - "email_branding_organization", - "email_branding_request", - "email_branding_something_else", "estimate_usage", "link_service_to_organization", "request_to_go_live", @@ -273,11 +256,9 @@ class MainNavigation(Navigation): "service_edit_sms_sender", "service_email_reply_to", "service_name_change", - "service_preview_email_branding", "service_set_auth_type", "service_set_channel", "send_files_by_email_contact_details", - "service_set_email_branding", "service_set_inbound_number", "service_set_inbound_sms", "service_set_international_sms", @@ -335,12 +316,10 @@ class OrgNavigation(Navigation): "settings": { "edit_organization_billing_details", "edit_organization_domains", - "edit_organization_email_branding", "edit_organization_go_live_notes", "edit_organization_name", "edit_organization_notes", "edit_organization_type", - "organization_preview_email_branding", "organization_settings", }, "team-members": { diff --git a/app/notify_client/email_branding_client.py b/app/notify_client/email_branding_client.py deleted file mode 100644 index fe939cfd8..000000000 --- a/app/notify_client/email_branding_client.py +++ /dev/null @@ -1,40 +0,0 @@ -from app.notify_client import NotifyAdminAPIClient, cache - - -class EmailBrandingClient(NotifyAdminAPIClient): - @cache.set("email_branding-{branding_id}") - def get_email_branding(self, branding_id): - return self.get(url="/email-branding/{}".format(branding_id)) - - @cache.set("email_branding") - def get_all_email_branding(self, sort_key=None): - brandings = self.get(url="/email-branding")["email_branding"] - if sort_key and sort_key in brandings[0]: - brandings.sort(key=lambda branding: branding[sort_key].lower()) - return brandings - - @cache.delete("email_branding") - def create_email_branding(self, logo, name, text, colour, brand_type): - data = { - "logo": logo, - "name": name, - "text": text, - "colour": colour, - "brand_type": brand_type, - } - return self.post(url="/email-branding", data=data) - - @cache.delete("email_branding") - @cache.delete("email_branding-{branding_id}") - def update_email_branding(self, branding_id, logo, name, text, colour, brand_type): - data = { - "logo": logo, - "name": name, - "text": text, - "colour": colour, - "brand_type": brand_type, - } - return self.post(url="/email-branding/{}".format(branding_id), data=data) - - -email_branding_client = EmailBrandingClient() diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 434bf8b3b..fe1a6aff5 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -82,7 +82,6 @@ class ServiceAPIClient(NotifyAdminAPIClient): "contact_link", "created_by", "count_as_live", - "email_branding", "email_from", "free_sms_fragment_limit", "go_live_at", diff --git a/app/templates/components/branding-preview.html b/app/templates/components/branding-preview.html deleted file mode 100644 index db3e3001d..000000000 --- a/app/templates/components/branding-preview.html +++ /dev/null @@ -1,7 +0,0 @@ -{% macro branding_preview(branding_style, endpoint) %} - -{% endmacro %} - -{% macro email_branding_preview(branding_style) %} - {{ branding_preview(branding_style, 'main.email_template') }} -{% endmacro %} diff --git a/app/templates/support-tickets/branding-request.txt b/app/templates/support-tickets/branding-request.txt deleted file mode 100644 index 7c80176e8..000000000 --- a/app/templates/support-tickets/branding-request.txt +++ /dev/null @@ -1,14 +0,0 @@ -Organization: {% if current_service.organization -%} - {{ current_service.organization.name }} -{%- else -%} - Can’t tell (domain is {{ current_user.email_domain }}) -{%- endif %} -Service: {{ current_service.name }} -{{ url_for('main.service_dashboard', service_id=current_service.id, _external=True) }} - ---- -Current branding: {{ current_branding }} -Branding requested: {{ branding_requested }} -{% if detail %} -{{ detail }} -{% endif %} diff --git a/app/templates/views/email-branding/manage-branding.html b/app/templates/views/email-branding/manage-branding.html deleted file mode 100644 index 5cb7da9c5..000000000 --- a/app/templates/views/email-branding/manage-branding.html +++ /dev/null @@ -1,46 +0,0 @@ -{% extends "views/platform-admin/_base_template.html" %} -{% from "components/file-upload.html" import file_upload %} -{% from "components/page-header.html" import page_header %} -{% from "components/page-footer.html" import page_footer %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/back-link/macro.njk" import usaBackLink %} - -{% block service_page_title %} - {{ '{} email branding'.format('Update' if email_branding else 'Create')}} -{% endblock %} - - -{% block backLink %} - {{ usaBackLink({ "href": url_for('.email_branding') }) }} -{% endblock %} - -{% block platform_admin_content %} - - {{ page_header('{} email branding'.format('Update' if email_branding else 'Add')) }} -
-
- {% if logo %} -
- -
- {% endif %} -

- Logos should be PNG files, 108px high -

- {{ file_upload(form.file, allowed_file_extensions=['png'], button_text='{} logo'.format('Update' if email_branding else 'Upload')) }} - {% call form_wrapper() %} -
-
{{form.name}}
-
{{form.text}}
- {{ form.colour }} - {{ form.brand_type }} - {{ page_footer( - 'Save', - button_name='operation', - button_value='email-branding-details' - ) }} -
- {% endcall %} -
- -{% endblock %} diff --git a/app/templates/views/email-branding/select-branding.html b/app/templates/views/email-branding/select-branding.html deleted file mode 100644 index 5d0503f10..000000000 --- a/app/templates/views/email-branding/select-branding.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "views/platform-admin/_base_template.html" %} -{% from "components/page-header.html" import page_header %} -{% from "components/live-search.html" import live_search %} -{% from "components/components/button/macro.njk" import usaButton %} - -{% set page_title = "Email branding" %} - -{% block per_page_title %} - {{ page_title }} -{% endblock %} - -{% block platform_admin_content %} - -

{{ page_title }}

- {{ live_search(target_selector='.message-name', show=True, form=search_form, autofocus=True) }} - -
- {{ usaButton({ - "element": "a", - "text": "New brand", - "href": url_for('.create_email_branding'), - "classes": "govuk-button--secondary" - }) }} -
- -{% endblock %} diff --git a/app/templates/views/features.html b/app/templates/views/features.html index 244334f97..a981b86e0 100644 --- a/app/templates/views/features.html +++ b/app/templates/views/features.html @@ -13,7 +13,6 @@

If you work for the government, you can use Notify.gov to keep your users updated.

Notify makes it easy to create, customize, and send text messages.

You do not need any technical knowledge to use Notify.

diff --git a/app/templates/views/features/emails.html b/app/templates/views/features/emails.html deleted file mode 100644 index 88731639f..000000000 --- a/app/templates/views/features/emails.html +++ /dev/null @@ -1,49 +0,0 @@ -{% extends "content_template.html" %} -{% from "components/table.html" import mapping_table, row, text_field, edit_field, field with context %} - -{% block per_page_title %} - Emails -{% endblock %} - -{% block content_column_content %} - -

Emails

-

Send an unlimited number of emails for free with Notify.gov.

- {% if not current_user.is_authenticated %} -

Create an account and try Notify for yourself.

- {% endif %} - -

Features

-

Notify makes it easy to:

-
    -
  • create reusable email templates
  • -
  • personalize the content of your emails
  • -
  • send and schedule bulk messages
  • -
-

You can also integrate with our API to send emails automatically.

- -

Email branding

-

Add your organization’s logo and brand color to email templates.

-

See how to change your email branding.

- -

Send files by email

-

Notify offers a safe and reliable way to send files by email.

-

Upload a file using our API, then send your users an email with a link to download it.

-

Notify uses encrypted links instead of email attachments because:

-
    -
  • they’re more secure
  • - -
  • email attachments are often marked as spam
  • -
-

Read our API documentation for more information.

- -

Add a reply-to address

-

Notify lets you choose the email address that users reply to.

-

Emails with a reply-to address seem more trustworthy and are less likely to be labelled as spam.

-

See how to add a reply-to address.

- -

Pricing

-

It’s free to send emails through Notify.

-

See pricing for more details.

- -{% endblock %} diff --git a/app/templates/views/get-started.html b/app/templates/views/get-started.html index 7b6ad500c..d4ad0ebce 100644 --- a/app/templates/views/get-started.html +++ b/app/templates/views/get-started.html @@ -34,10 +34,10 @@
  • Set up your service

    {% if not current_user.is_authenticated or not current_service %} -

    Review your settings to add message branding and sender information.

    +

    Review your settings to add message customization and sender information.

    Add team members and check their permissions.

    {% else %} -

    Review your settings to add message branding and sender information.

    +

    Review your settings to add message customization and sender information.

    Add team members and check their permissions.

    {% endif %}
  • diff --git a/app/templates/views/guidance/branding-and-customisation.html b/app/templates/views/guidance/branding-and-customisation.html deleted file mode 100644 index 2e3939a5b..000000000 --- a/app/templates/views/guidance/branding-and-customisation.html +++ /dev/null @@ -1,55 +0,0 @@ -{% extends "content_template.html" %} -{% from "components/service-link.html" import service_link %} - -{% block per_page_title %} - Branding and customization -{% endblock %} - -{% block content_column_content %} - -

    Branding and customization

    - - - -

    Change the text message sender

    - -

    The text message sender tells your users who the message is from.

    - -

    To change the text message sender from the default of ‘Notify.gov’:

    - -
      -
    1. Go to the Text message settings section of the {{ service_link(current_service, 'main.service_settings', 'settings') }} page.
    2. -
    3. Select Manage on the Text message senders row.
    4. -
    5. Select Change or Add text message sender.
    6. -
    - -{% endblock %} diff --git a/app/templates/views/guidance/index.html b/app/templates/views/guidance/index.html index e73cd5cd5..7d43f81c3 100644 --- a/app/templates/views/guidance/index.html +++ b/app/templates/views/guidance/index.html @@ -17,12 +17,12 @@

    Edit and format messages

    - +

    This section explains how to:

    - +

    Format your content

    - +

    You can see a list of formatting instructions on the edit template page:

    - +
    1. Go to the {{ service_link(current_service, 'main.choose_template', 'templates') }} page.
    2. Add a new template or choose an existing template and select Edit.
    - + - +

    When composing a text message, write URLs in full and Notify will convert them into links for you.

    - +

    You cannot convert text into a link.

    - +

    We do not recommend using a third-party link shortening service because:

    - +
    • your users cannot see where the link will take them
    • your link might stop working if there’s a service outage
    • you can no longer control where the redirect goes
    - +

    Personalize your content

    - +

    To personalize the content of your messages, add a placeholder to the template.

    - +

    Placeholders are filled in with details, like a name or reference number, each time you send a message.

    - +

    To add a placeholder to the template:

    - +
    1. Go to the {{ service_link(current_service, 'main.choose_template', 'templates') }} page.
    2. Add a new template or choose an existing template and select Edit.
    3. @@ -73,20 +73,20 @@ ((ref number)).
    4. Select Save.
    - +

    When you send a message you can either:

    - +
    • manually fill in the placeholders yourself
    • upload a list of personal details and let Notify do it for you
    - +

    If you upload a list, the column names need to match the placeholders in your template.

    - +

    Add optional content

    - +

    To add optional content to your messages:

    - +
    1. Go to the {{ service_link(current_service, 'main.choose_template', 'templates') }} page.
    2. Add a new template or choose an existing template and select Edit.
    3. @@ -94,25 +94,25 @@ who are under 18: ((under18??Please get your application signed by a parent or guardian.))
    4. Select Save.
    - +

    For each person you send this message to, specify ‘yes’ or ‘no’ to show or hide this content. You can either:

    - +
    • do this yourself
    • upload a list of personal details and let Notify do it for you
    - +

    If you upload a list, the column names need to match the optional content in your template.

    -

    Branding and customization

    - +

    Message customization

    +

    Change the text message sender

    - +

    The text message sender tells your users who the message is from.

    - +

    To change the text message sender from the default of ‘Notify.gov’:

    - +
    1. Go to the Text message settings section of the {{ service_link(current_service, 'main.service_settings', 'settings') }} page.
    2. diff --git a/app/templates/views/organizations/organization/settings/index.html b/app/templates/views/organizations/organization/settings/index.html index 50bee3109..a9d339bf8 100644 --- a/app/templates/views/organizations/organization/settings/index.html +++ b/app/templates/views/organizations/organization/settings/index.html @@ -67,16 +67,6 @@ }} {% endcall %} - {% call row() %} - {{ text_field('Default email branding') }} - {{ text_field(current_org.email_branding_name) }} - {{ edit_field( - 'Change', - url_for('.edit_organization_email_branding', org_id=current_org.id), - suffix='default email branding for the organization' - ) - }} - {% endcall %} {% call row() %} {{ text_field('Known email domains') }} {{ optional_text_field(current_org.domains or None, default='None') }} diff --git a/app/templates/views/organizations/organization/settings/preview-email-branding.html b/app/templates/views/organizations/organization/settings/preview-email-branding.html deleted file mode 100644 index 45feae8c5..000000000 --- a/app/templates/views/organizations/organization/settings/preview-email-branding.html +++ /dev/null @@ -1,26 +0,0 @@ -{% extends "org_template.html" %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/button/macro.njk" import usaButton %} -{% from "components/branding-preview.html" import email_branding_preview %} - -{% block org_page_title %} - Preview email branding -{% endblock %} - -{% block maincolumn_content %} - -

      Preview email branding

      -
      -
      - {{ email_branding_preview(form.branding_style.data) }} - {% call form_wrapper(action=action) %} -
      - {{ form.hidden_tag() }} - -
      - {% endcall %} -
      -
      -{% endblock %} diff --git a/app/templates/views/organizations/organization/settings/set-email-branding.html b/app/templates/views/organizations/organization/settings/set-email-branding.html deleted file mode 100644 index 30df51d10..000000000 --- a/app/templates/views/organizations/organization/settings/set-email-branding.html +++ /dev/null @@ -1,43 +0,0 @@ -{% extends "org_template.html" %} -{% from "components/page-footer.html" import page_footer %} -{% from "components/page-header.html" import page_header %} -{% from "components/live-search.html" import live_search %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/back-link/macro.njk" import usaBackLink %} - -{% set page_title = "Default email branding" %} - -{% block per_page_title %} - {{ page_title }} -{% endblock %} - -{% block backLink %} - {{ usaBackLink({ "href": url_for('.organization_settings', org_id=current_org.id) }) }} -{% endblock %} - -{% block maincolumn_content %} - - {{ page_header(page_title) }} - {% call form_wrapper(data_kwargs={'preview-type': 'email'}) %} -
      -
      -
      -
      -
      -
      - {{ live_search( - target_selector='.usa-radio', - show=True, - form=search_form, - label='Search branding styles by name', - autofocus=True - ) }} - {{ form.branding_style }} -
      -
      -
      - {{ page_footer('Preview') }} -
      - {% endcall %} - -{% endblock %} diff --git a/app/templates/views/platform-admin/_base_template.html b/app/templates/views/platform-admin/_base_template.html index 777d7b9bd..99d788dda 100644 --- a/app/templates/views/platform-admin/_base_template.html +++ b/app/templates/views/platform-admin/_base_template.html @@ -26,7 +26,6 @@ ('Trial mode services', ('main.trial_services')), ('Organizations', ('main.organizations')), ('Reports', ('main.platform_admin_reports')), - ('Email branding', ('main.email_branding')), ('Inbound SMS numbers', ('main.inbound_sms_admin')), ('Find services by name', ('main.find_services_by_name')), ('Find users by email', ('main.find_users_by_email')), diff --git a/app/templates/views/service-settings.html b/app/templates/views/service-settings.html index a1dd3232e..86ef1a36d 100644 --- a/app/templates/views/service-settings.html +++ b/app/templates/views/service-settings.html @@ -162,23 +162,6 @@ }} {% endcall %} - {% if email_branding_options.something_else_is_only_option %} - {% set email_request_url = url_for('.email_branding_something_else', service_id=current_service.id) %} - {% else %} - {% set email_request_url = url_for('.email_branding_request', service_id=current_service.id) %} - {% endif %} - - {% call settings_row(if_has_permission='email') %} - {{ text_field('Email branding') }} - {{ text_field(current_service.email_branding_name) }} - {{ edit_field( - 'Change', - email_request_url, - permissions=['manage_service'], - suffix='email branding', - )}} - {% endcall %} - {% call settings_row(if_has_permission='email') %} {{ text_field('Send files by email') }} {{ optional_text_field(current_service.contact_link, default="Not set up", truncate=true) }} @@ -303,11 +286,6 @@ {{ text_field('{:,} per year'.format(current_service.free_sms_fragment_limit)) }} {{ edit_field('Change', url_for('.set_free_sms_allowance', service_id=current_service.id), suffix='free text message allowance') }} {% endcall %} - {% call row() %} - {{ text_field('Email branding' )}} - {{ text_field(current_service.email_branding_name) }} - {{ edit_field('Change', url_for('.service_set_email_branding', service_id=current_service.id), suffix='email branding (admin view)') }} - {% endcall %} {% call row() %} {{ text_field('Custom data retention')}} {% call field() %} diff --git a/app/templates/views/service-settings/branding/email-branding-govuk-org.html b/app/templates/views/service-settings/branding/email-branding-govuk-org.html deleted file mode 100644 index ba3043073..000000000 --- a/app/templates/views/service-settings/branding/email-branding-govuk-org.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "withnav_template.html" %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/back-link/macro.njk" import usaBackLink %} -{% from "components/page-footer.html" import page_footer %} -{% from "components/page-header.html" import page_header %} - -{% block service_page_title %} - Before you request new branding -{% endblock %} - -{% block backLink %} - {{ usaBackLink({ - "href": url_for('.email_branding_request', service_id=current_service.id) - }) }} -{% endblock %} - -{% block maincolumn_content %} - - {{ page_header('Before you request new branding') }} - -

      You can only use Notify.gov branding if people go to Notify.gov to access your service.

      - -

      - You cannot use Notify.gov branding if your organization is - independent - from government. -

      - -

      We’ll email you once your branding’s ready to use, or if we need any more information.

      - - {% call form_wrapper() %} - {{ page_footer('Request new branding') }} - {% endcall %} - -{% endblock %} diff --git a/app/templates/views/service-settings/branding/email-branding-govuk.html b/app/templates/views/service-settings/branding/email-branding-govuk.html deleted file mode 100644 index e58231326..000000000 --- a/app/templates/views/service-settings/branding/email-branding-govuk.html +++ /dev/null @@ -1,43 +0,0 @@ -{% extends "withnav_template.html" %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/back-link/macro.njk" import usaBackLink %} -{% from "components/page-footer.html" import page_footer %} -{% from "components/page-header.html" import page_header %} -{% from "components/branding-preview.html" import email_branding_preview %} - -{% block service_page_title %} - Check your new branding -{% endblock %} - -{% block backLink %} - {{ usaBackLink({ - "href": url_for('.email_branding_request', service_id=current_service.id) - }) }} -{% endblock %} - -{% block maincolumn_content %} - - {{ page_header('Check your new branding') }} - -

      - Emails from {{ current_service.name }} will look like this. -

      - - {{ email_branding_preview('__NONE__') }} - -

      Before you continue

      - -

      You can only use Notify.gov branding if people go to Notify.gov to access your service.

      - -

      - You cannot use Notify.gov branding if your organization is - independent - from government. -

      - - {% call form_wrapper() %} - {{ page_footer('Use this branding') }} - {% endcall %} - -{% endblock %} diff --git a/app/templates/views/service-settings/branding/email-branding-options.html b/app/templates/views/service-settings/branding/email-branding-options.html deleted file mode 100644 index acaf348b0..000000000 --- a/app/templates/views/service-settings/branding/email-branding-options.html +++ /dev/null @@ -1,48 +0,0 @@ -{% extends "withnav_template.html" %} -{% from "components/radios.html" import radio %} -{% from "components/select-input.html" import select_wrapper %} -{% from "components/textbox.html" import textbox %} -{% from "components/page-header.html" import page_header %} -{% from "components/page-footer.html" import page_footer %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/back-link/macro.njk" import usaBackLink %} -{% from "components/branding-preview.html" import email_branding_preview %} - -{% block service_page_title %} - Change email branding -{% endblock %} - -{% block backLink %} - {{ usaBackLink({ - "href": url_for('.service_settings', service_id=current_service.id) - }) }} -{% endblock %} - -{% block maincolumn_content %} - - {{ page_header('Change email branding') }} - -

      - Your emails currently have {{ branding_name }} branding. -

      - - {{ email_branding_preview( - current_service.email_branding_id if current_service.email_branding else '__NONE__' - ) }} - - {% if current_service.needs_to_change_email_branding %} -

      - You should be using your own branding instead. -

      - {% endif %} - - {% call form_wrapper() %} - {% call select_wrapper(form.options) %} - {% for option in form.options %} - {{ radio(option) }} - {% endfor %} - {% endcall %} - {{ page_footer('Continue') }} - {% endcall %} - -{% endblock %} diff --git a/app/templates/views/service-settings/branding/email-branding-organization.html b/app/templates/views/service-settings/branding/email-branding-organization.html deleted file mode 100644 index 83b6eb8c2..000000000 --- a/app/templates/views/service-settings/branding/email-branding-organization.html +++ /dev/null @@ -1,31 +0,0 @@ -{% extends "withnav_template.html" %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/back-link/macro.njk" import usaBackLink %} -{% from "components/page-footer.html" import page_footer %} -{% from "components/page-header.html" import page_header %} - -{% block service_page_title %} - When you request new branding -{% endblock %} - -{% block backLink %} - {{ usaBackLink({ - "href": url_for('.email_branding_request', service_id=current_service.id) - }) }} -{% endblock %} - -{% block maincolumn_content %} - - {{ page_header('When you request new branding') }} - -

      We’ll check if we already have the {{organization}} logo.

      - -

      If we do, we’ll let you know when your new branding is ready to use.

      - -

      If we don’t, we’ll email you to ask for more information.

      - - {% call form_wrapper() %} - {{ page_footer('Request new branding') }} - {% endcall %} - -{% endblock %} diff --git a/app/templates/views/service-settings/branding/email-branding-something-else.html b/app/templates/views/service-settings/branding/email-branding-something-else.html deleted file mode 100644 index bd61df811..000000000 --- a/app/templates/views/service-settings/branding/email-branding-something-else.html +++ /dev/null @@ -1,30 +0,0 @@ -{% extends "withnav_template.html" %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/back-link/macro.njk" import usaBackLink %} -{% from "components/page-footer.html" import page_footer %} -{% from "components/textbox.html" import textbox %} -{% from "components/components/textarea/macro.njk" import govukTextarea %} - -{% block service_page_title %} - Describe the branding you want -{% endblock %} - -{% if branding_options.something_else_is_only_option %} - {% set back_url = url_for('.service_settings', service_id=current_service.id) %} -{% else %} - {% set back_url = url_for('.email_branding_request', service_id=current_service.id) %} -{% endif %} - -{% block backLink %} - {{ usaBackLink({"href": back_url}) }} -{% endblock %} - -{% block maincolumn_content %} - - {% call form_wrapper() %} - {{ form.something_else }} -

      We’ll email you when your branding is ready, or if we need any more information.

      - {{ page_footer('Request new branding') }} - {% endcall %} - -{% endblock %} diff --git a/app/templates/views/service-settings/preview-email-branding.html b/app/templates/views/service-settings/preview-email-branding.html deleted file mode 100644 index c575f4acc..000000000 --- a/app/templates/views/service-settings/preview-email-branding.html +++ /dev/null @@ -1,26 +0,0 @@ -{% extends "withnav_template.html" %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/button/macro.njk" import usaButton %} -{% from "components/branding-preview.html" import email_branding_preview %} - -{% block service_page_title %} - Preview email branding -{% endblock %} - -{% block maincolumn_content %} - -

      Preview email branding

      -
      -
      - {{ email_branding_preview(form.branding_style.data) }} - {% call form_wrapper(action=action) %} -
      - {{ form.hidden_tag() }} - -
      - {% endcall %} -
      -
      -{% endblock %} diff --git a/app/templates/views/service-settings/set-email-branding.html b/app/templates/views/service-settings/set-email-branding.html deleted file mode 100644 index 131e8d73a..000000000 --- a/app/templates/views/service-settings/set-email-branding.html +++ /dev/null @@ -1,41 +0,0 @@ -{% extends "withnav_template.html" %} -{% from "components/page-header.html" import page_header %} -{% from "components/page-footer.html" import page_footer, sticky_page_footer %} -{% from "components/live-search.html" import live_search %} -{% from "components/form.html" import form_wrapper %} -{% from "components/components/back-link/macro.njk" import usaBackLink %} - -{% set page_title = "Set email branding" %} - -{% block backLink %} - {{ usaBackLink({ "href": url_for('.service_settings', service_id=current_service.id) }) }} -{% endblock %} - -{% block service_page_title %} - {{ page_title }} -{% endblock %} - -{% block maincolumn_content %} - - {{ page_header(page_title) }} - {% call form_wrapper(data_kwargs={'preview-type': 'email'}) %} -
      -
      -
      -
      -
      -
      - {{ live_search( - target_selector='.usa-radio', - show=True, - form=search_form, - label='Search branding styles by name', - autofocus=True - ) }} - {{ form.branding_style }} -
      -
      - {{ sticky_page_footer('Preview') }} - {% endcall %} - -{% endblock %} diff --git a/app/templates/views/using-notify.html b/app/templates/views/using-notify.html index 7d2701777..3b11fa271 100644 --- a/app/templates/views/using-notify.html +++ b/app/templates/views/using-notify.html @@ -21,7 +21,6 @@ diff --git a/app/utils/branding.py b/app/utils/branding.py deleted file mode 100644 index dd35fea30..000000000 --- a/app/utils/branding.py +++ /dev/null @@ -1,23 +0,0 @@ -from app.models.organization import Organization - - -def get_email_choices(service): - organization_branding_id = ( - service.organization.email_branding_id if service.organization else None - ) - - if ( - service.organization_type == Organization.TYPE_FEDERAL - and service.email_branding_id is not None # GOV.UK is not current branding - and organization_branding_id is None # no default to supersede it (GOV.UK) - ): - yield ("govuk", "GOV.UK") - - if ( - service.organization_type == Organization.TYPE_FEDERAL - and service.organization - and organization_branding_id is None # don't offer both if org has default - and service.email_branding_name.lower() - != f"GOV.UK and {service.organization.name}".lower() - ): - yield ("govuk_and_org", f"GOV.UK and {service.organization.name}") diff --git a/gulpfile.js b/gulpfile.js index 541c39cf4..9c0b34265 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -117,7 +117,6 @@ const javascripts = () => { paths.src + 'javascripts/errorTracking.js', paths.src + 'javascripts/preventDuplicateFormSubmissions.js', paths.src + 'javascripts/fullscreenTable.js', - paths.src + 'javascripts/previewPane.js', paths.src + 'javascripts/colourPreview.js', paths.src + 'javascripts/templateFolderForm.js', paths.src + 'javascripts/collapsibleCheckboxes.js', diff --git a/paas-failwhale/static_503/stylesheets/main.css b/paas-failwhale/static_503/stylesheets/main.css index 92ac258b8..50a467879 100644 --- a/paas-failwhale/static_503/stylesheets/main.css +++ b/paas-failwhale/static_503/stylesheets/main.css @@ -8903,14 +8903,6 @@ only screen and (min-resolution: 2dppx) { padding-bottom: 75% } -.branding-preview { - width: 100%; - box-sizing: border-box; - border: solid 1px #bfc1c3; - min-height: 200px; - margin-bottom: 30px -} - #logo-img { background-color: #f8f8f8; background-image: linear-gradient(45deg, #dee0e2 25%, transparent 25%), linear-gradient(-45deg, #dee0e2 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #dee0e2 75%), linear-gradient(-45deg, transparent 75%, #dee0e2 75%); @@ -9444,56 +9436,6 @@ only screen and (min-resolution: 2dppx) { position: relative } -.edit-template-link-letter-contact, -.edit-template-link-letter-address, -.edit-template-link-letter-body, -.edit-template-link-letter-branding, -.edit-template-link { - font-family: "nta", Arial, sans-serif; - font-weight: 400; - text-transform: none; - font-size: 16px; - line-height: 1.25; - position: absolute; - background: #005ea5; - color: #fff; - padding: 10px 15px; - z-index: 10000 -} - -@media (min-width: 641px) { - - .edit-template-link-letter-contact, - .edit-template-link-letter-address, - .edit-template-link-letter-body, - .edit-template-link-letter-branding, - .edit-template-link { - font-size: 19px; - line-height: 1.31579 - } -} - -.edit-template-link-letter-contact:link, -.edit-template-link-letter-address:link, -.edit-template-link-letter-body:link, -.edit-template-link-letter-branding:link, -.edit-template-link-letter-contact:visited, -.edit-template-link-letter-address:visited, -.edit-template-link-letter-body:visited, -.edit-template-link-letter-branding:visited, -.edit-template-link:link, -.edit-template-link:visited { - color: #fff -} - -.edit-template-link-letter-contact:hover, -.edit-template-link-letter-address:hover, -.edit-template-link-letter-body:hover, -.edit-template-link-letter-branding:hover, -.edit-template-link:hover { - color: #d5e8f3 -} - .notification-status { font-family: "nta", Arial, sans-serif; font-weight: 400; @@ -9817,4 +9759,4 @@ details .arrow { .heading-upcoming-jobs { margin-top: 15px -} \ No newline at end of file +} diff --git a/tests/app/main/views/organizations/test_organizations.py b/tests/app/main/views/organizations/test_organizations.py index 0b330b5a9..440e8252a 100644 --- a/tests/app/main/views/organizations/test_organizations.py +++ b/tests/app/main/views/organizations/test_organizations.py @@ -931,7 +931,6 @@ def test_organization_settings_for_platform_admin( "Request to go live notes None Change go live notes for the organization", "Billing details None Change billing details for the organization", "Notes None Change the notes for the organization", - "Default email branding GOV.UK Change default email branding for the organization", "Known email domains None Change known email domains for the organization", ] diff --git a/tests/app/main/views/service_settings/test_email_branding_requests.py b/tests/app/main/views/service_settings/test_email_branding_requests.py deleted file mode 100644 index ccab8a87a..000000000 --- a/tests/app/main/views/service_settings/test_email_branding_requests.py +++ /dev/null @@ -1,519 +0,0 @@ -from unittest.mock import ANY, PropertyMock - -import pytest -from flask import url_for -from notifications_utils.clients.zendesk.zendesk_client import NotifySupportTicket - -from tests import sample_uuid -from tests.conftest import ORGANISATION_ID, SERVICE_ONE_ID, normalize_spaces - - -@pytest.mark.parametrize( - ("organization_type", "expected_options"), - [ - ( - "other", - [ - ("something_else", "Something else"), - ], - ), - ], -) -def test_email_branding_request_page_when_no_branding_is_set( - service_one, - client_request, - mocker, - mock_get_email_branding, - organization_type, - expected_options, -): - service_one["email_branding"] = None - service_one["organization_type"] = organization_type - - mocker.patch( - "app.models.service.Service.email_branding_id", - new_callable=PropertyMock, - return_value=None, - ) - - page = client_request.get(".email_branding_request", service_id=SERVICE_ONE_ID) - - assert mock_get_email_branding.called is False - assert page.find_all("iframe")[1]["src"] == url_for( - "main.email_template", branding_style="__NONE__" - ) - - button_text = normalize_spaces(page.select_one(".page-footer button").text) - - assert [ - ( - radio["value"], - page.select_one("label[for={}]".format(radio["id"])).text.strip(), - ) - for radio in page.select("input[type=radio]") - ] == expected_options - - assert button_text == "Continue" - - -def test_email_branding_request_page_shows_branding_if_set( - mocker, - service_one, - client_request, - mock_get_email_branding, - mock_get_service_organization, -): - mocker.patch( - "app.models.service.Service.email_branding_id", - new_callable=PropertyMock, - return_value="some-random-branding", - ) - - page = client_request.get(".email_branding_request", service_id=SERVICE_ONE_ID) - assert page.find_all("iframe")[1]["src"] == url_for( - "main.email_template", branding_style="some-random-branding" - ) - - -def test_email_branding_request_page_back_link( - client_request, -): - page = client_request.get(".email_branding_request", service_id=SERVICE_ONE_ID) - - back_link = page.select_one("a.usa-back-link") - assert len(back_link) > 0, "No back link found on the page" - assert back_link["href"] == url_for(".service_settings", service_id=SERVICE_ONE_ID) - - -@pytest.mark.parametrize( - ("data", "org_type", "endpoint"), - [ - ( - { - "options": "govuk", - }, - "federal", - "main.email_branding_govuk", - ), - ( - { - "options": "govuk_and_org", - }, - "federal", - "main.email_branding_govuk_and_org", - ), - ( - { - "options": "something_else", - }, - "federal", - "main.email_branding_something_else", - ), - ], -) -def test_email_branding_request_submit( - client_request, - service_one, - mocker, - mock_get_email_branding, - organization_one, - data, - org_type, - endpoint, -): - organization_one["organization_type"] = org_type - service_one["email_branding"] = sample_uuid() - service_one["organization"] = organization_one - - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_one, - ) - - client_request.post( - ".email_branding_request", - service_id=SERVICE_ONE_ID, - _data=data, - _expected_status=302, - _expected_redirect=url_for( - endpoint, - service_id=SERVICE_ONE_ID, - ), - ) - - -def test_email_branding_request_submit_when_no_radio_button_is_selected( - client_request, - service_one, - mock_get_email_branding, -): - service_one["email_branding"] = sample_uuid() - - page = client_request.post( - ".email_branding_request", - service_id=SERVICE_ONE_ID, - _data={"options": ""}, - _follow_redirects=True, - ) - assert page.h1.text == "Change email branding" - assert ( - normalize_spaces(page.select_one(".error-message").text) == "Select an option" - ) - - -@pytest.mark.parametrize( - ("endpoint", "expected_heading"), - [ - ("main.email_branding_govuk_and_org", "Before you request new branding"), - ], -) -def test_email_branding_description_pages_for_org_branding( - client_request, - mocker, - service_one, - organization_one, - mock_get_email_branding, - endpoint, - expected_heading, -): - service_one["email_branding"] = sample_uuid() - service_one["organization"] = organization_one - - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_one, - ) - - page = client_request.get( - endpoint, - service_id=SERVICE_ONE_ID, - ) - assert page.h1.text == expected_heading - assert ( - normalize_spaces(page.select_one(".page-footer button").text) - == "Request new branding" - ) - - -@pytest.mark.parametrize( - ("endpoint", "service_org_type", "branding_preview_id"), - [("main.email_branding_govuk", "central", "__NONE__")], -) -@pytest.mark.skip(reason="Update for TTS") -def test_email_branding_govuk_and_nhs_pages( - client_request, - mocker, - service_one, - organization_one, - mock_get_email_branding, - endpoint, - service_org_type, - branding_preview_id, -): - organization_one["organization_type"] = service_org_type - service_one["email_branding"] = sample_uuid() - service_one["organization"] = organization_one - - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_one, - ) - - page = client_request.get( - endpoint, - service_id=SERVICE_ONE_ID, - ) - assert page.h1.text == "Check your new branding" - assert "Emails from service one will look like this" in normalize_spaces(page.text) - assert page.find("iframe")["src"] == url_for( - "main.email_template", branding_style=branding_preview_id - ) - assert ( - normalize_spaces(page.select_one(".page-footer button").text) - == "Use this branding" - ) - - -@pytest.mark.skip(reason="Update for TTS") -def test_email_branding_something_else_page(client_request, service_one): - # expect to have a "NHS" option as well as the - # fallback, so back button goes to choices page - service_one["organization_type"] = "nhs_central" - - page = client_request.get( - "main.email_branding_something_else", - service_id=SERVICE_ONE_ID, - ) - assert normalize_spaces(page.h1.text) == "Describe the branding you want" - assert page.select_one("textarea")["name"] == ("something_else") - assert ( - normalize_spaces(page.select_one(".page-footer button").text) - == "Request new branding" - ) - assert page.select_one(".usa-back-link")["href"] == url_for( - "main.email_branding_request", - service_id=SERVICE_ONE_ID, - ) - - -def test_get_email_branding_something_else_page_is_only_option( - client_request, service_one -): - # should only have a "something else" option - # so back button goes back to settings page - service_one["organization_type"] = "other" - - page = client_request.get( - "main.email_branding_something_else", - service_id=SERVICE_ONE_ID, - ) - assert page.select_one(".usa-back-link")["href"] == url_for( - "main.service_settings", - service_id=SERVICE_ONE_ID, - ) - - -@pytest.mark.parametrize( - "endpoint", - [ - ("main.email_branding_govuk"), - ("main.email_branding_govuk_and_org"), - ("main.email_branding_organization"), - ], -) -def test_email_branding_pages_give_404_if_selected_branding_not_allowed( - client_request, - endpoint, -): - # The only email branding allowed is 'something_else', so trying to visit any of the other - # endpoints gives a 404 status code. - client_request.get(endpoint, service_id=SERVICE_ONE_ID, _expected_status=404) - - -def test_email_branding_govuk_submit( - mocker, - client_request, - service_one, - organization_one, - no_reply_to_email_addresses, - mock_get_email_branding, - single_sms_sender, - mock_update_service, -): - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_one, - ) - mocker.patch( - "app.models.service.Service.organization_id", - new_callable=PropertyMock, - return_value=ORGANISATION_ID, - ) - service_one["email_branding"] = sample_uuid() - - page = client_request.post( - ".email_branding_govuk", - service_id=SERVICE_ONE_ID, - _follow_redirects=True, - ) - - mock_update_service.assert_called_once_with( - SERVICE_ONE_ID, - email_branding=None, - ) - assert page.h1.text == "Settings" - assert ( - normalize_spaces(page.select_one(".banner-default").text) - == "You’ve updated your email branding" - ) - - -@pytest.mark.skip(reason="Update for TTS") -def test_email_branding_govuk_and_org_submit( - mocker, - client_request, - service_one, - organization_one, - no_reply_to_email_addresses, - mock_get_email_branding, - single_sms_sender, -): - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_one, - ) - mocker.patch( - "app.models.service.Service.organization_id", - new_callable=PropertyMock, - return_value=ORGANISATION_ID, - ) - service_one["email_branding"] = sample_uuid() - - mock_create_ticket = mocker.spy(NotifySupportTicket, "__init__") - mock_send_ticket_to_zendesk = mocker.patch( - "app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk", - autospec=True, - ) - - page = client_request.post( - ".email_branding_govuk_and_org", - service_id=SERVICE_ONE_ID, - _follow_redirects=True, - ) - - mock_create_ticket.assert_called_once_with( - ANY, - message="\n".join( - [ - "Organization: organization one", - "Service: service one", - "http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb", - "", - "---", - "Current branding: Organization name", - "Branding requested: GOV.UK and organization one\n", - ] - ), - subject="Email branding request - service one", - ticket_type="question", - user_name="Test User", - user_email="test@user.gsa.gov", - org_id=ORGANISATION_ID, - org_type="central", - service_id=SERVICE_ONE_ID, - ) - mock_send_ticket_to_zendesk.assert_called_once() - assert normalize_spaces(page.select_one(".banner-default").text) == ( - "Thanks for your branding request. We’ll get back to you " - "within one working day." - ) - - -@pytest.mark.skip(reason="Update for TTS") -def test_email_branding_organization_submit( - mocker, - client_request, - service_one, - organization_one, - no_reply_to_email_addresses, - mock_get_email_branding, - single_sms_sender, -): - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_one, - ) - mocker.patch( - "app.models.service.Service.organization_id", - new_callable=PropertyMock, - return_value=ORGANISATION_ID, - ) - service_one["email_branding"] = sample_uuid() - - mock_create_ticket = mocker.spy(NotifySupportTicket, "__init__") - mock_send_ticket_to_zendesk = mocker.patch( - "app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk", - autospec=True, - ) - - page = client_request.post( - ".email_branding_organization", - service_id=SERVICE_ONE_ID, - _follow_redirects=True, - ) - - mock_create_ticket.assert_called_once_with( - ANY, - message="\n".join( - [ - "Organization: organization one", - "Service: service one", - "http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb", - "", - "---", - "Current branding: Organization name", - "Branding requested: organization one\n", - ] - ), - subject="Email branding request - service one", - ticket_type="question", - user_name="Test User", - user_email="test@user.gsa.gov", - org_id=ORGANISATION_ID, - org_type="central", - service_id=SERVICE_ONE_ID, - ) - mock_send_ticket_to_zendesk.assert_called_once() - assert normalize_spaces(page.select_one(".banner-default").text) == ( - "Thanks for your branding request. We’ll get back to you " - "within one working day." - ) - - -def test_email_branding_something_else_submit( - client_request, - mocker, - service_one, - no_reply_to_email_addresses, - mock_get_email_branding, - single_sms_sender, -): - service_one["email_branding"] = sample_uuid() - service_one["organization_type"] = "nhs_local" - - mock_create_ticket = mocker.spy(NotifySupportTicket, "__init__") - mock_send_ticket_to_zendesk = mocker.patch( - "app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk", - autospec=True, - ) - - page = client_request.post( - ".email_branding_something_else", - service_id=SERVICE_ONE_ID, - _data={"something_else": "Homer Simpson"}, - _follow_redirects=True, - ) - - mock_create_ticket.assert_called_once_with( - ANY, - message="\n".join( - [ - "Organization: Can’t tell (domain is user.gsa.gov)", - "Service: service one", - "http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb", - "", - "---", - "Current branding: Organization name", - "Branding requested: Something else\n", - "Homer Simpson\n", - ] - ), - subject="Email branding request - service one", - ticket_type="question", - user_name="Test User", - user_email="test@user.gsa.gov", - org_id=None, - org_type="nhs_local", - service_id=SERVICE_ONE_ID, - ) - mock_send_ticket_to_zendesk.assert_called_once() - assert normalize_spaces(page.select_one(".banner-default").text) == ( - "Thanks for your branding request. We’ll get back to you " - "within one working day." - ) - - -def test_email_branding_something_else_submit_shows_error_if_textbox_is_empty( - client_request, -): - page = client_request.post( - ".email_branding_something_else", - service_id=SERVICE_ONE_ID, - _data={"something_else": ""}, - _follow_redirects=True, - ) - assert normalize_spaces(page.h1.text) == "Describe the branding you want" - assert ( - normalize_spaces(page.select_one(".usa-error-message").text) - == "Error: Cannot be empty" - ) diff --git a/tests/app/main/views/service_settings/test_service_settings.py b/tests/app/main/views/service_settings/test_service_settings.py index ede9f1e92..906dcc883 100644 --- a/tests/app/main/views/service_settings/test_service_settings.py +++ b/tests/app/main/views/service_settings/test_service_settings.py @@ -1,7 +1,6 @@ from datetime import datetime from functools import partial from unittest.mock import ANY, Mock, PropertyMock, call -from urllib.parse import parse_qs, urlparse from uuid import uuid4 import pytest @@ -83,7 +82,6 @@ def _mock_get_service_settings_page_common( "Rate limit 3,000 per minute Change rate limit", "Message batch limit 1,000 per send Change message batch limit", "Free text message allowance 250,000 per year Change free text message allowance", - "Email branding GOV.UK Change email branding (admin view)", "Custom data retention Email – 7 days Change data retention", "Receive inbound SMS Off Change your settings for Receive inbound SMS", "Email authentication Off Change your settings for Email authentication", @@ -256,13 +254,11 @@ def test_should_show_overview_for_service_with_more_things_set( service_one, single_reply_to_email_address, single_sms_sender, - mock_get_email_branding, permissions, expected_rows, ): client_request.login(active_user_with_permissions) service_one["permissions"] = permissions - service_one["email_branding"] = uuid4() page = client_request.get("main.service_settings", service_id=service_one["id"]) for index, row in enumerate(expected_rows): assert row == " ".join(page.find_all("tr")[index + 1].text.split()) @@ -2823,247 +2819,6 @@ def test_does_not_show_research_mode_indicator( assert not element -@pytest.mark.parametrize( - ("current_branding", "expected_values", "expected_labels"), - [ - ( - None, - [ - "__NONE__", - "1", - "2", - "3", - "4", - "5", - ], - ["GOV.UK", "org 1", "org 2", "org 3", "org 4", "org 5"], - ), - ( - "5", - [ - "5", - "__NONE__", - "1", - "2", - "3", - "4", - ], - [ - "org 5", - "GOV.UK", - "org 1", - "org 2", - "org 3", - "org 4", - ], - ), - ], -) -@pytest.mark.parametrize( - ("endpoint", "extra_args"), - [ - ( - "main.service_set_email_branding", - {"service_id": SERVICE_ONE_ID}, - ), - ( - "main.edit_organization_email_branding", - {"org_id": ORGANISATION_ID}, - ), - ], -) -def test_should_show_branding_styles( - mocker, - client_request, - platform_admin_user, - service_one, - mock_get_all_email_branding, - current_branding, - expected_values, - expected_labels, - endpoint, - extra_args, -): - service_one["email_branding"] = current_branding - mocker.patch( - "app.organizations_client.get_organization", - side_effect=lambda org_id: organization_json( - org_id, - "Org 1", - email_branding_id=current_branding, - ), - ) - - client_request.login(platform_admin_user) - page = client_request.get(endpoint, **extra_args) - - branding_style_choices = page.find_all("input", attrs={"name": "branding_style"}) - - radio_labels = [ - page.find("label", attrs={"for": branding_style_choices[idx]["id"]}) - .get_text() - .strip() - for idx, element in enumerate(branding_style_choices) - ] - - assert len(branding_style_choices) == 6 - - for index, expected_value in enumerate(expected_values): - assert branding_style_choices[index]["value"] == expected_value - - # radios should be in alphabetical order, based on their labels - assert radio_labels == expected_labels - - assert "checked" in branding_style_choices[0].attrs - assert "checked" not in branding_style_choices[1].attrs - assert "checked" not in branding_style_choices[2].attrs - assert "checked" not in branding_style_choices[3].attrs - assert "checked" not in branding_style_choices[4].attrs - assert "checked" not in branding_style_choices[5].attrs - - app.email_branding_client.get_all_email_branding.assert_called_once_with() - app.service_api_client.get_service.assert_called_once_with(service_one["id"]) - - -@pytest.mark.parametrize( - ("endpoint", "extra_args", "expected_redirect"), - [ - ( - "main.service_set_email_branding", - {"service_id": SERVICE_ONE_ID}, - "main.service_preview_email_branding", - ), - ( - "main.edit_organization_email_branding", - {"org_id": ORGANISATION_ID}, - "main.organization_preview_email_branding", - ), - ], -) -def test_should_send_branding_and_organizations_to_preview( - client_request, - platform_admin_user, - service_one, - mock_get_organization, - mock_get_all_email_branding, - mock_update_service, - endpoint, - extra_args, - expected_redirect, -): - client_request.login(platform_admin_user) - client_request.post( - endpoint, - _data={"branding_type": "org", "branding_style": "1"}, - _expected_status=302, - _expected_location=url_for(expected_redirect, branding_style="1", **extra_args), - **extra_args, - ) - - mock_get_all_email_branding.assert_called_once_with() - - -@pytest.mark.parametrize( - ("endpoint", "extra_args"), - [ - ( - "main.service_preview_email_branding", - {"service_id": SERVICE_ONE_ID}, - ), - ( - "main.organization_preview_email_branding", - {"org_id": ORGANISATION_ID}, - ), - ], -) -def test_should_preview_email_branding( - client_request, - platform_admin_user, - mock_get_organization, - endpoint, - extra_args, -): - client_request.login(platform_admin_user) - page = client_request.get( - endpoint, branding_type="org", branding_style="1", **extra_args - ) - - iframe = page.find("iframe", attrs={"class": "branding-preview"}) - iframeURLComponents = urlparse(iframe["src"]) - iframeQString = parse_qs(iframeURLComponents.query) - - assert page.find("input", attrs={"id": "branding_style"})["value"] == "1" - assert iframeURLComponents.path == "/_email" - assert iframeQString["branding_style"] == ["1"] - - -@pytest.mark.parametrize( - ("posted_value", "submitted_value"), - [ - ("1", "1"), - ("__NONE__", None), - pytest.param("None", None, marks=pytest.mark.xfail(raises=AssertionError)), - ], -) -@pytest.mark.parametrize( - ("endpoint", "extra_args", "expected_redirect"), - [ - ( - "main.service_preview_email_branding", - {"service_id": SERVICE_ONE_ID}, - "main.service_settings", - ), - ( - "main.organization_preview_email_branding", - {"org_id": ORGANISATION_ID}, - "main.organization_settings", - ), - ], -) -def test_should_set_branding_and_organizations( - client_request, - platform_admin_user, - service_one, - mock_get_organization, - mock_get_organization_services, - mock_update_service, - mock_update_organization, - posted_value, - submitted_value, - endpoint, - extra_args, - expected_redirect, -): - client_request.login(platform_admin_user) - client_request.post( - endpoint, - _data={"branding_style": posted_value}, - _expected_status=302, - _expected_redirect=url_for(expected_redirect, **extra_args), - **extra_args, - ) - - if endpoint == "main.service_preview_email_branding": - mock_update_service.assert_called_once_with( - SERVICE_ONE_ID, - email_branding=submitted_value, - ) - assert mock_update_organization.called is False - elif endpoint == "main.organization_preview_email_branding": - mock_update_organization.assert_called_once_with( - ORGANISATION_ID, - email_branding_id=submitted_value, - cached_service_ids=[ - "12345", - "67890", - "596364a0-858e-42c8-9062-a8fe822260eb", - ], - ) - assert mock_update_service.called is False - else: - raise Exception - - @pytest.mark.parametrize("method", ["get", "post"]) @pytest.mark.parametrize( "endpoint", @@ -4170,33 +3925,6 @@ def test_update_service_organization_does_not_update_if_same_value( assert mock_update_service_organization.called is False -@pytest.mark.skip(reason="Email currently deactivated") -@pytest.mark.parametrize( - ("single_branding_option", "expected_href"), - [ - ( - True, - f"/services/{SERVICE_ONE_ID}/service-settings/email-branding/something-else", - ), - ], -) -def test_service_settings_links_to_branding_request_page_for_emails( - service_one, - client_request, - no_reply_to_email_addresses, - single_sms_sender, - single_branding_option, - expected_href, -): - if single_branding_option: - # should only have a "something else" option - # so we go straight to that form - service_one["organization_type"] = "other" - - page = client_request.get(".service_settings", service_id=SERVICE_ONE_ID) - assert len(page.find_all("a", attrs={"href": expected_href})) == 1 - - def test_show_service_data_retention( client_request, platform_admin_user, diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index 0d04715ac..4f2ab9964 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -97,7 +97,6 @@ def test_should_add_service_and_redirect_to_tour_when_no_services( mock_create_service_template, mock_get_services_with_no_services, api_user_active, - mock_get_all_email_branding, inherited, email_address, posted, @@ -153,7 +152,6 @@ def test_add_service_has_to_choose_org_type( mock_create_service_template, mock_get_services_with_no_services, api_user_active, - mock_get_all_email_branding, platform_admin_user, ): client_request.login(platform_admin_user) @@ -227,7 +225,6 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service( api_user_active, organization_type, free_allowance, - mock_get_all_email_branding, platform_admin_user, ): client_request.login(platform_admin_user) diff --git a/tests/app/main/views/test_email_branding.py b/tests/app/main/views/test_email_branding.py deleted file mode 100644 index fe86c108c..000000000 --- a/tests/app/main/views/test_email_branding.py +++ /dev/null @@ -1,451 +0,0 @@ -from io import BytesIO -from unittest.mock import call - -import pytest -from flask import url_for -from notifications_python_client.errors import HTTPError - -from app.s3_client.s3_logo_client import EMAIL_LOGO_LOCATION_STRUCTURE, TEMP_TAG -from tests.conftest import create_email_branding, normalize_spaces - - -def test_email_branding_page_shows_full_branding_list( - client_request, platform_admin_user, mock_get_all_email_branding -): - client_request.login(platform_admin_user) - page = client_request.get(".email_branding") - - links = page.select(".message-name a") - brand_names = [normalize_spaces(link.text) for link in links] - hrefs = [link["href"] for link in links] - - assert normalize_spaces(page.select_one("h1").text) == "Email branding" - - assert page.select(".grid-col-9 a")[-1]["href"] == url_for( - "main.create_email_branding" - ) - - assert brand_names == [ - "org 1", - "org 2", - "org 3", - "org 4", - "org 5", - ] - assert hrefs == [ - url_for(".update_email_branding", branding_id=1), - url_for(".update_email_branding", branding_id=2), - url_for(".update_email_branding", branding_id=3), - url_for(".update_email_branding", branding_id=4), - url_for(".update_email_branding", branding_id=5), - ] - - -def test_edit_email_branding_shows_the_correct_branding_info( - client_request, platform_admin_user, mock_get_email_branding, fake_uuid -): - client_request.login(platform_admin_user) - page = client_request.get( - ".update_email_branding", - branding_id=fake_uuid, - _test_page_title=False, # TODO: Fix page titles - ) - - assert page.select_one("#logo-img > img")["src"].endswith("/example.png") - assert page.select_one("#name").attrs.get("value") == "Organization name" - assert page.select_one("#file").attrs.get("accept") == ".png" - assert page.select_one("#text").attrs.get("value") == "Organization text" - assert page.select_one("#colour").attrs.get("value") == "#f00" - - -def test_create_email_branding_does_not_show_any_branding_info( - client_request, platform_admin_user, mock_no_email_branding -): - client_request.login(platform_admin_user) - page = client_request.get( - ".create_email_branding", - _test_page_title=False, # TODO: Fix page titles - ) - - assert page.select_one("#logo-img > img") is None - assert page.select_one("#name").attrs.get("value") is None - assert page.select_one("#file").attrs.get("accept") == ".png" - assert page.select_one("#text").attrs.get("value") is None - assert page.select_one("#colour").attrs.get("value") is None - - -def test_create_new_email_branding_without_logo( - client_request, - platform_admin_user, - mocker, - fake_uuid, - mock_create_email_branding, -): - data = { - "logo": None, - "colour": "#ff0000", - "text": "new text", - "name": "new name", - "brand_type": "org", - } - - mock_persist = mocker.patch("app.main.views.email_branding.persist_logo") - mocker.patch("app.main.views.email_branding.delete_email_temp_files_created_by") - - client_request.login(platform_admin_user) - client_request.post( - ".create_email_branding", - _content_type="multipart/form-data", - _data=data, - ) - - assert mock_create_email_branding.called - assert mock_create_email_branding.call_args == call( - logo=data["logo"], - name=data["name"], - text=data["text"], - colour=data["colour"], - brand_type=data["brand_type"], - ) - assert mock_persist.call_args_list == [] - - -def test_create_email_branding_requires_a_name_when_submitting_logo_details( - client_request, - mocker, - mock_create_email_branding, - platform_admin_user, -): - mocker.patch("app.main.views.email_branding.persist_logo") - mocker.patch("app.main.views.email_branding.delete_email_temp_files_created_by") - data = { - "operation": "email-branding-details", - "logo": "", - "colour": "#ff0000", - "text": "new text", - "name": "", - "brand_type": "org", - } - client_request.login(platform_admin_user) - page = client_request.post( - ".create_email_branding", - _content_type="multipart/form-data", - _data=data, - _expected_status=200, - ) - - assert ( - page.select_one(".usa-error-message").text.strip() - == "Error: This field is required" - ) - assert mock_create_email_branding.called is False - - -def test_create_email_branding_does_not_require_a_name_when_uploading_a_file( - client_request, - mocker, - platform_admin_user, -): - mocker.patch( - "app.main.views.email_branding.upload_email_logo", return_value="temp_filename" - ) - data = { - "file": (BytesIO("".encode("utf-8")), "test.png"), - "colour": "", - "text": "", - "name": "", - "brand_type": "org", - } - client_request.login(platform_admin_user) - page = client_request.post( - ".create_email_branding", - _content_type="multipart/form-data", - _data=data, - _follow_redirects=True, - ) - - assert not page.find(".error-message") - - -def test_create_new_email_branding_when_branding_saved( - client_request, platform_admin_user, mocker, mock_create_email_branding, fake_uuid -): - with client_request.session_transaction() as session: - user_id = session["user_id"] - - data = { - "logo": "test.png", - "colour": "#ff0000", - "text": "new text", - "name": "new name", - "brand_type": "org_banner", - } - - temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format( - temp=TEMP_TAG.format(user_id=user_id), - unique_id=fake_uuid, - filename=data["logo"], - ) - - mocker.patch("app.main.views.email_branding.persist_logo") - mocker.patch("app.main.views.email_branding.delete_email_temp_files_created_by") - - client_request.login(platform_admin_user) - client_request.post( - ".create_email_branding", - logo=temp_filename, - _content_type="multipart/form-data", - _data={ - "colour": data["colour"], - "name": data["name"], - "text": data["text"], - "cdn_url": "https://static-logos.cdn.com", - "brand_type": data["brand_type"], - }, - ) - - updated_logo_name = "{}-{}".format(fake_uuid, data["logo"]) - - assert mock_create_email_branding.called - assert mock_create_email_branding.call_args == call( - logo=updated_logo_name, - name=data["name"], - text=data["text"], - colour=data["colour"], - brand_type=data["brand_type"], - ) - - -@pytest.mark.parametrize( - ("endpoint", "has_data"), - [ - ("main.create_email_branding", False), - ("main.update_email_branding", True), - ], -) -def test_deletes_previous_temp_logo_after_uploading_logo( - client_request, platform_admin_user, mocker, endpoint, has_data, fake_uuid -): - if has_data: - mocker.patch( - "app.email_branding_client.get_email_branding", - return_value=create_email_branding(fake_uuid), - ) - - with client_request.session_transaction() as session: - user_id = session["user_id"] - - temp_old_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format( - temp=TEMP_TAG.format(user_id=user_id), - unique_id=fake_uuid, - filename="old_test.png", - ) - - temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format( - temp=TEMP_TAG.format(user_id=user_id), unique_id=fake_uuid, filename="test.png" - ) - - mocked_upload_email_logo = mocker.patch( - "app.main.views.email_branding.upload_email_logo", return_value=temp_filename - ) - - mocked_delete_email_temp_file = mocker.patch( - "app.main.views.email_branding.delete_email_temp_file" - ) - - client_request.login(platform_admin_user) - client_request.post( - "main.create_email_branding", - logo=temp_old_filename, - branding_id=fake_uuid, - _data={"file": (BytesIO("".encode("utf-8")), "test.png")}, - _content_type="multipart/form-data", - ) - - assert mocked_upload_email_logo.called - assert mocked_delete_email_temp_file.called - assert mocked_delete_email_temp_file.call_args == call(temp_old_filename) - - -def test_update_existing_branding( - client_request, - platform_admin_user, - mocker, - fake_uuid, - mock_get_email_branding, - mock_update_email_branding, -): - with client_request.session_transaction() as session: - user_id = session["user_id"] - - data = { - "logo": "test.png", - "colour": "#0000ff", - "text": "new text", - "name": "new name", - "brand_type": "both", - } - - temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format( - temp=TEMP_TAG.format(user_id=user_id), - unique_id=fake_uuid, - filename=data["logo"], - ) - - mocker.patch("app.main.views.email_branding.persist_logo") - mocker.patch("app.main.views.email_branding.delete_email_temp_files_created_by") - - client_request.login(platform_admin_user) - client_request.post( - ".update_email_branding", - logo=temp_filename, - branding_id=fake_uuid, - _content_type="multipart/form-data", - _data={ - "colour": data["colour"], - "name": data["name"], - "text": data["text"], - "cdn_url": "https://static-logos.cdn.com", - "brand_type": data["brand_type"], - }, - ) - - updated_logo_name = "{}-{}".format(fake_uuid, data["logo"]) - - assert mock_update_email_branding.called - assert mock_update_email_branding.call_args == call( - branding_id=fake_uuid, - logo=updated_logo_name, - name=data["name"], - text=data["text"], - colour=data["colour"], - brand_type=data["brand_type"], - ) - - -def test_temp_logo_is_shown_after_uploading_logo( - client_request, - platform_admin_user, - mocker, - fake_uuid, -): - with client_request.session_transaction() as session: - user_id = session["user_id"] - - temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format( - temp=TEMP_TAG.format(user_id=user_id), unique_id=fake_uuid, filename="test.png" - ) - - mocker.patch( - "app.main.views.email_branding.upload_email_logo", return_value=temp_filename - ) - mocker.patch("app.main.views.email_branding.delete_email_temp_file") - - client_request.login(platform_admin_user) - page = client_request.post( - "main.create_email_branding", - _data={"file": (BytesIO("".encode("utf-8")), "test.png")}, - _content_type="multipart/form-data", - _follow_redirects=True, - ) - - assert page.select_one("#logo-img > img").attrs["src"].endswith(temp_filename) - - -def test_logo_persisted_when_organization_saved( - client_request, platform_admin_user, mock_create_email_branding, mocker, fake_uuid -): - with client_request.session_transaction() as session: - user_id = session["user_id"] - - temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format( - temp=TEMP_TAG.format(user_id=user_id), unique_id=fake_uuid, filename="test.png" - ) - - mocked_upload_email_logo = mocker.patch( - "app.main.views.email_branding.upload_email_logo" - ) - mocked_persist_logo = mocker.patch("app.main.views.email_branding.persist_logo") - mocked_delete_email_temp_files_by = mocker.patch( - "app.main.views.email_branding.delete_email_temp_files_created_by" - ) - - client_request.login(platform_admin_user) - client_request.post( - ".create_email_branding", - logo=temp_filename, - _content_type="multipart/form-data", - ) - - assert not mocked_upload_email_logo.called - assert mocked_persist_logo.called - assert mocked_delete_email_temp_files_by.called - assert mocked_delete_email_temp_files_by.call_args == call(user_id) - assert mock_create_email_branding.called - - -def test_logo_does_not_get_persisted_if_updating_email_branding_client_throws_an_error( - client_request, platform_admin_user, mock_create_email_branding, mocker, fake_uuid -): - with client_request.session_transaction() as session: - user_id = session["user_id"] - - temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format( - temp=TEMP_TAG.format(user_id=user_id), unique_id=fake_uuid, filename="test.png" - ) - - mocked_persist_logo = mocker.patch("app.main.views.email_branding.persist_logo") - mocked_delete_email_temp_files_by = mocker.patch( - "app.main.views.email_branding.delete_email_temp_files_created_by" - ) - mocker.patch( - "app.main.views.email_branding.email_branding_client.create_email_branding", - side_effect=HTTPError(), - ) - - client_request.login(platform_admin_user) - client_request.post( - ".create_email_branding", - logo=temp_filename, - _content_type="multipart/form-data", - _expected_status=500, - ) - - assert not mocked_persist_logo.called - assert not mocked_delete_email_temp_files_by.called - - -@pytest.mark.parametrize( - ("colour_hex", "expected_status_code"), - [ - ("#FF00FF", 302), - ("hello", 200), - ("", 302), - ], -) -def test_colour_regex_validation( - client_request, - platform_admin_user, - mocker, - fake_uuid, - colour_hex, - expected_status_code, - mock_create_email_branding, -): - data = { - "logo": None, - "colour": colour_hex, - "text": "new text", - "name": "new name", - "brand_type": "org", - } - - mocker.patch("app.main.views.email_branding.delete_email_temp_files_created_by") - - client_request.login(platform_admin_user) - client_request.post( - ".create_email_branding", - _content_type="multipart/form-data", - _data=data, - _expected_status=expected_status_code, - ) diff --git a/tests/app/main/views/test_email_preview.py b/tests/app/main/views/test_email_preview.py deleted file mode 100644 index 60604a9f3..000000000 --- a/tests/app/main/views/test_email_preview.py +++ /dev/null @@ -1,95 +0,0 @@ -import re - -import pytest - - -@pytest.mark.parametrize( - ("query_args", "result"), [({}, True), ({"govuk_banner": "false"}, "false")] -) -def test_renders(client_request, mocker, query_args, result): - mocker.patch( - "app.main.views.index.HTMLEmailTemplate.__str__", return_value="rendered" - ) - - response = client_request.get_response("main.email_template", **query_args) - - assert response.get_data(as_text=True) == "rendered" - - -def test_displays_both_branding( - client_request, mock_get_email_branding_with_both_brand_type -): - page = client_request.get( - "main.email_template", branding_style="1", _test_page_title=False - ) - - mock_get_email_branding_with_both_brand_type.assert_called_once_with("1") - - assert page.find("img", attrs={"src": re.compile("example.png$")}) - assert ( - page.select( - "body > table:nth-of-type(3) table > tr:nth-of-type(1) > td:nth-of-type(2)" - )[0] - .get_text() - .strip() - == "Organization text" - ) # brand text is set - - -def test_displays_org_branding(client_request, mock_get_email_branding): - # mock_get_email_branding has 'brand_type' of 'org' - page = client_request.get( - "main.email_template", branding_style="1", _test_page_title=False - ) - - mock_get_email_branding.assert_called_once_with("1") - - assert not page.find("a", attrs={"href": "https://www.gsa.gov"}) - assert page.find("img", attrs={"src": re.compile("example.png")}) - assert not page.select( - "body > table > tr > td[bgcolor='#f00']" - ) # banner colour is not set - assert ( - page.select( - "body > table:nth-of-type(1) > tr:nth-of-type(1) > td:nth-of-type(2)" - )[0] - .get_text() - .strip() - == "Organization text" - ) # brand text is set - - -def test_displays_org_branding_with_banner( - client_request, mock_get_email_branding_with_org_banner_brand_type -): - page = client_request.get( - "main.email_template", branding_style="1", _test_page_title=False - ) - - mock_get_email_branding_with_org_banner_brand_type.assert_called_once_with("1") - - assert not page.find("a", attrs={"href": "https://www.gsa.gov"}) - assert page.find("img", attrs={"src": re.compile("example.png")}) - assert page.select("body > table > tr > td[bgcolor='#f00']") # banner colour is set - assert ( - page.select("body > table table > tr > td > span")[0].get_text().strip() - == "Organization text" - ) # brand text is set - - -def test_displays_org_branding_with_banner_without_brand_text( - client_request, mock_get_email_branding_without_brand_text -): - # mock_get_email_branding_without_brand_text has 'brand_type' of 'org_banner' - page = client_request.get( - "main.email_template", branding_style="1", _test_page_title=False - ) - - mock_get_email_branding_without_brand_text.assert_called_once_with("1") - - assert not page.find("a", attrs={"href": "https://www.gsa.gov"}) - assert page.find("img", attrs={"src": re.compile("example.png")}) - assert page.select("body > table > tr > td[bgcolor='#f00']") # banner colour is set - assert ( - not page.select("body > table table > tr > td > span") == 0 - ) # brand text is not set diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index 7311dbaaa..ac55aed4f 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -5,7 +5,7 @@ from bs4 import BeautifulSoup from flask import url_for from freezegun import freeze_time -from tests.conftest import SERVICE_ONE_ID, normalize_spaces, sample_uuid +from tests.conftest import SERVICE_ONE_ID, normalize_spaces def test_non_logged_in_user_can_see_homepage( @@ -104,12 +104,10 @@ def test_hiding_pages_from_search_engines( "documentation", "security", "message_status", - "features_email", "features_sms", "how_to_pay", "get_started", "guidance_index", - "branding_and_customisation", "create_and_send_messages", "edit_and_format_messages", "send_files_by_email", @@ -265,36 +263,6 @@ def test_css_is_served_from_correct_path(client_request): # assert logo_svg_fallback['src'].startswith('https://static.example.com/images/us-notify-color.png') -@pytest.mark.parametrize( - ("extra_args", "email_branding_retrieved"), - [ - ( - {}, - False, - ), - ( - {"branding_style": "__NONE__"}, - False, - ), - ( - {"branding_style": sample_uuid()}, - True, - ), - ], -) -def test_email_branding_preview( - client_request, - mock_get_email_branding, - extra_args, - email_branding_retrieved, -): - page = client_request.get( - "main.email_template", _test_page_title=False, **extra_args - ) - assert page.title.text == "Email branding preview" - assert mock_get_email_branding.called is email_branding_retrieved - - @pytest.mark.parametrize( ("current_date", "expected_rate"), [ diff --git a/tests/app/main/views/test_platform_admin.py b/tests/app/main/views/test_platform_admin.py index 49206d873..f5e7862a7 100644 --- a/tests/app/main/views/test_platform_admin.py +++ b/tests/app/main/views/test_platform_admin.py @@ -757,7 +757,6 @@ def test_clear_cache_shows_form( "user", "service", "template", - "email_branding", "organization", } diff --git a/tests/app/models/test_event.py b/tests/app/models/test_event.py index 4f64f7a32..bbff4fe91 100644 --- a/tests/app/models/test_event.py +++ b/tests/app/models/test_event.py @@ -12,7 +12,6 @@ from tests.conftest import sample_uuid ("active", False, True, ("Unsuspended this service")), ("active", True, False, ("Deleted this service")), ("contact_link", "x", "y", ("Set the contact details for this service to ‘y’")), - ("email_branding", "foo", "bar", ("Updated this service’s email branding")), ( "inbound_api", "foo", diff --git a/tests/app/notify_client/test_email_branding_client.py b/tests/app/notify_client/test_email_branding_client.py deleted file mode 100644 index 85b2c12c9..000000000 --- a/tests/app/notify_client/test_email_branding_client.py +++ /dev/null @@ -1,104 +0,0 @@ -from unittest.mock import call - -from app.notify_client.email_branding_client import EmailBrandingClient - - -def test_get_email_branding(mocker, fake_uuid): - mock_get = mocker.patch( - "app.notify_client.email_branding_client.EmailBrandingClient.get", - return_value={"foo": "bar"}, - ) - mock_redis_get = mocker.patch( - "app.extensions.RedisClient.get", - return_value=None, - ) - mock_redis_set = mocker.patch( - "app.extensions.RedisClient.set", - ) - EmailBrandingClient().get_email_branding(fake_uuid) - mock_get.assert_called_once_with(url="/email-branding/{}".format(fake_uuid)) - mock_redis_get.assert_called_once_with("email_branding-{}".format(fake_uuid)) - mock_redis_set.assert_called_once_with( - "email_branding-{}".format(fake_uuid), - '{"foo": "bar"}', - ex=604800, - ) - - -def test_get_all_email_branding(mocker): - mock_get = mocker.patch( - "app.notify_client.email_branding_client.EmailBrandingClient.get", - return_value={"email_branding": [1, 2, 3]}, - ) - mock_redis_get = mocker.patch( - "app.extensions.RedisClient.get", - return_value=None, - ) - mock_redis_set = mocker.patch( - "app.extensions.RedisClient.set", - ) - EmailBrandingClient().get_all_email_branding() - mock_get.assert_called_once_with(url="/email-branding") - mock_redis_get.assert_called_once_with("email_branding") - mock_redis_set.assert_called_once_with( - "email_branding", - "[1, 2, 3]", - ex=604800, - ) - - -def test_create_email_branding(mocker): - org_data = { - "logo": "test.png", - "name": "test name", - "text": "test name", - "colour": "red", - "brand_type": "org", - } - - mock_post = mocker.patch( - "app.notify_client.email_branding_client.EmailBrandingClient.post" - ) - mock_redis_delete = mocker.patch("app.extensions.RedisClient.delete") - EmailBrandingClient().create_email_branding( - logo=org_data["logo"], - name=org_data["name"], - text=org_data["text"], - colour=org_data["colour"], - brand_type="org", - ) - - mock_post.assert_called_once_with(url="/email-branding", data=org_data) - - mock_redis_delete.assert_called_once_with("email_branding") - - -def test_update_email_branding(mocker, fake_uuid): - org_data = { - "logo": "test.png", - "name": "test name", - "text": "test name", - "colour": "red", - "brand_type": "org", - } - - mock_post = mocker.patch( - "app.notify_client.email_branding_client.EmailBrandingClient.post" - ) - mock_redis_delete = mocker.patch("app.extensions.RedisClient.delete") - EmailBrandingClient().update_email_branding( - branding_id=fake_uuid, - logo=org_data["logo"], - name=org_data["name"], - text=org_data["text"], - colour=org_data["colour"], - brand_type="org", - ) - - mock_post.assert_called_once_with( - url="/email-branding/{}".format(fake_uuid), data=org_data - ) - assert mock_redis_delete.call_args_list == [ - call("email_branding-{}".format(fake_uuid)), - call("email_branding"), - ] diff --git a/tests/app/notify_client/test_service_api_client.py b/tests/app/notify_client/test_service_api_client.py index acffa3f8a..815f3e5e2 100644 --- a/tests/app/notify_client/test_service_api_client.py +++ b/tests/app/notify_client/test_service_api_client.py @@ -632,7 +632,6 @@ def test_client_updates_service_with_allowed_attributes( "consent_to_research", "contact_link", "count_as_live", - "email_branding", "email_from", "free_sms_fragment_limit", "go_live_at", diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index 9873d6422..2f890d7b3 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -34,7 +34,6 @@ EXCLUDED_ENDPOINTS = tuple( "bat_phone", "begin_tour", "billing_details", - "branding_and_customisation", "callbacks", "cancel_invited_org_user", "cancel_invited_user", @@ -61,7 +60,6 @@ EXCLUDED_ENDPOINTS = tuple( "count_content_length", "create_and_send_messages", "create_api_key", - "create_email_branding", "data_retention", "delete_service_template", "delete_template_folder", @@ -75,7 +73,6 @@ EXCLUDED_ENDPOINTS = tuple( "edit_data_retention", "edit_organization_billing_details", "edit_organization_domains", - "edit_organization_email_branding", "edit_organization_go_live_notes", "edit_organization_name", "edit_organization_notes", @@ -87,18 +84,10 @@ EXCLUDED_ENDPOINTS = tuple( "edit_user_email", "edit_user_mobile_number", "edit_user_permissions", - "email_branding", - "email_branding_govuk", - "email_branding_govuk_and_org", - "email_branding_organization", - "email_branding_request", - "email_branding_something_else", "email_not_received", - "email_template", "error", "estimate_usage", "features", - "features_email", "features_sms", "feedback", "find_services_by_name", @@ -146,7 +135,6 @@ EXCLUDED_ENDPOINTS = tuple( "old_using_notify", "organization_billing", "organization_dashboard", - "organization_preview_email_branding", "organization_settings", "organization_trial_mode_services", "organizations", @@ -193,10 +181,8 @@ EXCLUDED_ENDPOINTS = tuple( "service_edit_sms_sender", "service_email_reply_to", "service_name_change", - "service_preview_email_branding", "service_set_auth_type", "service_set_channel", - "service_set_email_branding", "service_set_inbound_number", "service_set_inbound_sms", "service_set_international_sms", @@ -236,7 +222,6 @@ EXCLUDED_ENDPOINTS = tuple( "two_factor_email", "two_factor_email_interstitial", "two_factor_email_sent", - "update_email_branding", "uploads", "usage", "user_information", diff --git a/tests/app/utils/test_branding.py b/tests/app/utils/test_branding.py deleted file mode 100644 index 8c1aae4bd..000000000 --- a/tests/app/utils/test_branding.py +++ /dev/null @@ -1,189 +0,0 @@ -from unittest.mock import PropertyMock - -import pytest - -from app.models.service import Service -from app.utils.branding import get_email_choices -from tests import organization_json -from tests.conftest import create_email_branding - - -@pytest.mark.parametrize("function", [get_email_choices]) -@pytest.mark.parametrize( - ("org_type", "expected_options"), - [ - ("federal", []), - ("state", []), - ], -) -def test_get_choices_service_not_assigned_to_org( - service_one, - function, - org_type, - expected_options, -): - service_one["organization_type"] = org_type - service = Service(service_one) - - options = function(service) - assert list(options) == expected_options - - -@pytest.mark.parametrize( - ("org_type", "branding_id", "expected_options"), - [ - ( - "federal", - None, - [ - ("govuk_and_org", "GOV.UK and Test Organization"), - ("organization", "Test Organization"), - ], - ), - ( - "federal", - "some-branding-id", - [ - ("govuk", "GOV.UK"), # central orgs can switch back to gsa.gov - ("govuk_and_org", "GOV.UK and Test Organization"), - ("organization", "Test Organization"), - ], - ), - ("state", None, [("organization", "Test Organization")]), - ("state", "some-branding-id", [("organization", "Test Organization")]), - # ('nhs_central', None, [ - # ('nhs', 'NHS') - # ]), - # ('nhs_central', NHS_EMAIL_BRANDING_ID, [ - # # don't show NHS if it's the current branding - # ]), - ], -) -@pytest.mark.skip(reason="Update for TTS") -def test_get_email_choices_service_assigned_to_org( - mocker, - service_one, - org_type, - branding_id, - expected_options, - mock_get_service_organization, - mock_get_email_branding, -): - service = Service(service_one) - - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_json(organization_type=org_type), - ) - mocker.patch( - "app.models.service.Service.email_branding_id", - new_callable=PropertyMock, - return_value=branding_id, - ) - - options = get_email_choices(service) - assert list(options) == expected_options - - -@pytest.mark.parametrize( - ("org_type", "branding_id", "expected_options"), - [ - ( - "federal", - "some-branding-id", - [ - # don't show gsa.gov options as org default supersedes it - ("organization", "Test Organization"), - ], - ), - ( - "federal", - "org-branding-id", - [ - # also don't show org option if it's the current branding - ], - ), - ( - "state", - "org-branding-id", - [ - # don't show org option if it's the current branding - ], - ), - ], -) -@pytest.mark.skip(reason="Update for TTS") -def test_get_email_choices_org_has_default_branding( - mocker, - service_one, - org_type, - branding_id, - expected_options, - mock_get_service_organization, - mock_get_email_branding, -): - service = Service(service_one) - - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_json( - organization_type=org_type, email_branding_id="org-branding-id" - ), - ) - mocker.patch( - "app.models.service.Service.email_branding_id", - new_callable=PropertyMock, - return_value=branding_id, - ) - - options = get_email_choices(service) - assert list(options) == expected_options - - -@pytest.mark.parametrize( - ("branding_name", "expected_options"), - [ - ( - "gsa.gov and something else", - [ - ("govuk", "GOV.UK"), - ("govuk_and_org", "GOV.UK and Test Organization"), - ("organization", "Test Organization"), - ], - ), - ( - "gsa.gov and test OrganisatioN", - [ - ("govuk", "GOV.UK"), - ("organization", "Test Organization"), - ], - ), - ], -) -@pytest.mark.skip(reason="Update for TTS") -def test_get_email_choices_branding_name_in_use( - mocker, - service_one, - branding_name, - expected_options, - mock_get_service_organization, -): - service = Service(service_one) - - mocker.patch( - "app.organizations_client.get_organization", - return_value=organization_json(organization_type="central"), - ) - mocker.patch( - "app.models.service.Service.email_branding_id", - new_callable=PropertyMock, - return_value="some-branding-id", - ) - mocker.patch( - "app.email_branding_client.get_email_branding", - return_value=create_email_branding("_id", {"name": branding_name}), - ) - - options = get_email_choices(service) - # don't show option if its name is similar to current branding - assert list(options) == expected_options diff --git a/tests/conftest.py b/tests/conftest.py index 9d55b796b..aa679aff6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2182,152 +2182,6 @@ def mock_send_already_registered_email(mocker): return mocker.patch("app.user_api_client.send_already_registered_email") -def create_email_brandings( - number_of_brandings, non_standard_values=None, shuffle=False -): - brandings = [ - { - "id": str(idx), - "name": "org {}".format(idx), - "text": "org {}".format(idx), - "colour": None, - "logo": "logo{}.png".format(idx), - "brand_type": "org", - } - for idx in range(1, number_of_brandings + 1) - ] - - for idx, row in enumerate(non_standard_values or {}): - brandings[row["idx"]].update(non_standard_values[idx]) - - if shuffle: - brandings.insert(3, brandings.pop(4)) - - return brandings - - -@pytest.fixture() -def mock_get_all_email_branding(mocker): - def _get_all_email_branding(sort_key=None): - non_standard_values = [ - {"idx": 1, "colour": "red"}, - {"idx": 2, "colour": "orange"}, - {"idx": 3, "text": None}, - {"idx": 4, "colour": "blue"}, - ] - shuffle = sort_key is None - return create_email_brandings( - 5, non_standard_values=non_standard_values, shuffle=shuffle - ) - - return mocker.patch( - "app.notify_client.email_branding_client.email_branding_client.get_all_email_branding", - side_effect=_get_all_email_branding, - ) - - -@pytest.fixture() -def mock_no_email_branding(mocker): - def _get_email_branding(): - return [] - - return mocker.patch( - "app.email_branding_client.get_all_email_branding", - side_effect=_get_email_branding, - ) - - -def create_email_branding(id, non_standard_values=None): - branding = { - "logo": "example.png", - "name": "Organization name", - "text": "Organization text", - "id": id, - "colour": "#f00", - "brand_type": "org", - } - - if non_standard_values: - branding.update(non_standard_values) - - return {"email_branding": branding} - - -@pytest.fixture() -def mock_get_email_branding(mocker, fake_uuid): - def _get_email_branding(id): - return create_email_branding(fake_uuid) - - return mocker.patch( - "app.email_branding_client.get_email_branding", side_effect=_get_email_branding - ) - - -@pytest.fixture() -def mock_get_email_branding_with_govuk_brand_type(mocker, fake_uuid): - def _get_email_branding(id): - return create_email_branding(fake_uuid, {"brand_type": "govuk"}) - - return mocker.patch( - "app.email_branding_client.get_email_branding", side_effect=_get_email_branding - ) - - -@pytest.fixture() -def mock_get_email_branding_with_both_brand_type(mocker, fake_uuid): - def _get_email_branding(id): - return create_email_branding(fake_uuid, {"brand_type": "both"}) - - return mocker.patch( - "app.email_branding_client.get_email_branding", side_effect=_get_email_branding - ) - - -@pytest.fixture() -def mock_get_email_branding_with_org_banner_brand_type(mocker, fake_uuid): - def _get_email_branding(id): - return create_email_branding(fake_uuid, {"brand_type": "org_banner"}) - - return mocker.patch( - "app.email_branding_client.get_email_branding", side_effect=_get_email_branding - ) - - -@pytest.fixture() -def mock_get_email_branding_without_brand_text(mocker, fake_uuid): - def _get_email_branding_without_brand_text(id): - return create_email_branding( - fake_uuid, {"text": "", "brand_type": "org_banner"} - ) - - return mocker.patch( - "app.email_branding_client.get_email_branding", - side_effect=_get_email_branding_without_brand_text, - ) - - -@pytest.fixture() -def mock_create_email_branding(mocker): - def _create_email_branding(logo, name, text, colour, brand_type): - return - - return mocker.patch( - "app.email_branding_client.create_email_branding", - side_effect=_create_email_branding, - ) - - -@pytest.fixture() -def mock_update_email_branding(mocker): - def _update_email_branding(branding_id, logo, name, text, colour, brand_type): - return - - return mocker.patch( - "app.email_branding_client.update_email_branding", - side_effect=_update_email_branding, - ) - - @pytest.fixture() def mock_get_guest_list(mocker): def _get_guest_list(service_id): diff --git a/tests/javascripts/liveSearch.test.js b/tests/javascripts/liveSearch.test.js index e0868285e..548e5505f 100644 --- a/tests/javascripts/liveSearch.test.js +++ b/tests/javascripts/liveSearch.test.js @@ -25,451 +25,6 @@ describe('Live search', () => { } }; - describe("With a list of radios", () => { - - searchLabelText = "Search branding styles by name"; - - beforeEach(() => { - - const departmentData = { - name: 'departments', - hideLegend: true, - fields: [ - { - 'label': 'NHS', - 'id': 'nhs', - 'name': 'branding', - 'value': 'nhs' - }, - { - 'label': 'Department for Work and Pensions', - 'id': 'dwp', - 'name': 'branding', - 'value': 'dwp' - }, - { - 'label': 'Department for Education', - 'id': 'dfe', - 'name': 'branding', - 'value': 'dfe' - }, - { - 'label': 'Home Office', - 'id': 'home-office', - 'name': 'branding', - 'value': 'home-office' - } - ] - }; - - // set up DOM - document.body.innerHTML = ` - -
      -
      `; - - searchTextbox = document.getElementById('search'); - liveRegion = document.querySelector('.live-search__status'); - list = document.querySelector('form'); - - // getRadioGroup returns a DOM node so append once DOM is set up - list.appendChild(helpers.getRadioGroup(departmentData)); - - }); - - describe("When the page loads", () => { - - test("If there is no search term, the results should be unchanged", () => { - - // start the module - window.GOVUK.modules.start(); - - const listItems = list.querySelectorAll('.usa-radio'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(listItems.length); - expect(searchTextbox.hasAttribute('aria-label')).toBe(false); - - }); - - test("If there is a single word search term, only the results that match should show", () => { - - searchTextbox.value = 'Department'; - - // start the module - window.GOVUK.modules.start(); - - const listItems = list.querySelectorAll('.usa-radio'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(2); - expect(searchTextbox.hasAttribute('aria-label')).toBe(true); - expect(searchTextbox.getAttribute('aria-label')).toEqual(`${searchLabelText}, ${liveRegionResults(2)}`); - - }); - - test("If there is a search term made of several words, only the results that match should show", () => { - - searchTextbox.value = 'Department for Work'; - - // start the module - window.GOVUK.modules.start(); - - const listItems = list.querySelectorAll('.usa-radio'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(1); - expect(searchTextbox.hasAttribute('aria-label')).toBe(true); - expect(searchTextbox.getAttribute('aria-label')).toEqual(`${searchLabelText}, ${liveRegionResults(1)}`); - - }); - - test("If an item doesn't match the search term but is selected, it should still show in the results", () => { - - searchTextbox.value = 'Department for Work'; - - // mark an item as selected - checkedItem = list.querySelector('input[id=nhs]'); - checkedItem.checked = true; - - // start the module - window.GOVUK.modules.start(); - - expect(window.getComputedStyle(checkedItem).display).not.toEqual('none'); - - }); - - }); - - describe("When the search text changes", () => { - - test("If there is no search term, the results should be unchanged", () => { - - searchTextbox.value = 'Department'; - - // start the module - window.GOVUK.modules.start(); - - // simulate the input of new search text - searchTextbox.value = ''; - helpers.triggerEvent(searchTextbox, 'input'); - - const listItems = list.querySelectorAll('.usa-radio'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(listItems.length); - expect(liveRegion.textContent.trim()).toEqual(liveRegionResults(listItemsShowing.length)); - - }); - - test("If there is a single word search term, only the results that match should show", () => { - - searchTextbox.value = 'Department'; - - // start the module - window.GOVUK.modules.start(); - - // simulate the input of new search text - searchTextbox.value = 'Home'; - helpers.triggerEvent(searchTextbox, 'input'); - - const listItems = list.querySelectorAll('.usa-radio'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(1); - expect(liveRegion.textContent.trim()).toEqual(liveRegionResults(1)); - - }); - - test("If there is a search term made of several words, only the results that match should show", () => { - - searchTextbox.value = 'Department'; - - // start the module - window.GOVUK.modules.start(); - - // simulate the input of new search text - searchTextbox.value = 'Department for'; - helpers.triggerEvent(searchTextbox, 'input'); - - const listItems = list.querySelectorAll('.usa-radio'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(2); - expect(liveRegion.textContent.trim()).toEqual(liveRegionResults(2)); - - }); - - test("If an item doesn't match the search term but is selected, it should still show in the results", () => { - - searchTextbox.value = 'Department'; - - // mark an item as selected - checkedItem = list.querySelector('input[id=nhs]'); - checkedItem.checked = true; - - // start the module - window.GOVUK.modules.start(); - - // simulate the input of new search text - searchTextbox.value = 'Home Office'; - helpers.triggerEvent(searchTextbox, 'input'); - - expect(window.getComputedStyle(checkedItem).display).not.toEqual('none'); - - }); - - }); - - }); - - describe("With a list of checkboxes", () => { - - searchLabelText = "Search branding styles by name"; - - beforeEach(() => { - - const templatesAndFolders = [ - { - "label": "Appointments", - "type": "folder", - "meta": "2 templates" - }, - { - "label": "New patient", - "type": "template", - "meta": "Email template" - }, - { - "label": "Prescriptions", - "type": "folder", - "meta": "1 template, 1 folder" - }, - { - "label": "New doctor", - "type": "template", - "meta": "Email template" - } - ]; - - // set up DOM - document.body.innerHTML = ` - -
      - -
      `; - - searchTextbox = document.getElementById('search'); - liveRegion = document.querySelector('.live-search__status'); - list = document.querySelector('form'); - - }); - - describe("When the page loads", () => { - - test("If there is no search term, the results should be unchanged", () => { - - // start the module - window.GOVUK.modules.start(); - - const listItems = list.querySelectorAll('.template-list-item'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(listItems.length); - expect(searchTextbox.hasAttribute('aria-label')).toBe(false); - - }); - - test("If there is a single word search term, only the results that match should show", () => { - - searchTextbox.value = 'New'; - - // start the module - window.GOVUK.modules.start(); - - const listItems = list.querySelectorAll('.template-list-item'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - // should match 'New patient' and 'New doctor' - expect(listItemsShowing.length).toEqual(2); - expect(searchTextbox.hasAttribute('aria-label')).toBe(true); - expect(searchTextbox.getAttribute('aria-label')).toEqual(`${searchLabelText}, ${liveRegionResults(2)}`); - - }); - - test("If there is a search term made of several words, only the results that match should show", () => { - - searchTextbox.value = 'New patient'; - - // start the module - window.GOVUK.modules.start(); - - const listItems = list.querySelectorAll('.template-list-item'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(1); - expect(searchTextbox.hasAttribute('aria-label')).toBe(true); - expect(searchTextbox.getAttribute('aria-label')).toEqual(`${searchLabelText}, ${liveRegionResults(1)}`); - - }); - - test("If an item doesn't match the search term but is selected, it should still show in the results", () => { - - searchTextbox.value = 'New patient'; - - // mark 'Appointments' item as selected - checkedItem = list.querySelector('input[id=templates-or-folder-0]'); - checkedItem.checked = true; - - // start the module - window.GOVUK.modules.start(); - - // should show despite not matching - expect(window.getComputedStyle(checkedItem).display).not.toEqual('none'); - - }); - - test("If the items have a block of text to match against, only results that match it should show", () => { - - searchTextbox.value = 'Email template'; - - // start the module - window.GOVUK.modules.start(); - - const listItems = list.querySelectorAll('.template-list-item'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - // 2 items contain the "Email template" text - // only the text containing the name of the item is matched against (ie 'New patient') - expect(listItemsShowing.length).toEqual(0); - expect(searchTextbox.getAttribute('aria-label')).toEqual(`${searchLabelText}, ${liveRegionResults(0)}`); - - }); - - }); - - describe("When the search text changes", () => { - - test("If there is no search term, the results should be unchanged", () => { - - searchTextbox.value = 'Appointments'; - - // start the module - window.GOVUK.modules.start(); - - // simulate input of new search text - searchTextbox.value = ''; - helpers.triggerEvent(searchTextbox, 'input'); - - const listItems = list.querySelectorAll('.template-list-item'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(listItems.length); - expect(liveRegion.textContent.trim()).toEqual(liveRegionResults(listItemsShowing.length)); - - }); - - test("If there is a single word search term, only the results that match should show", () => { - - searchTextbox.value = 'Appointments'; - - // start the module - window.GOVUK.modules.start(); - - // simulate input of new search text - searchTextbox.value = 'Prescriptions'; - helpers.triggerEvent(searchTextbox, 'input'); - - const listItems = list.querySelectorAll('.template-list-item'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(1); - expect(liveRegion.textContent.trim()).toEqual(liveRegionResults(1)); - - }); - - test("If there is a search term made of several words, only the results that match should show", () => { - - searchTextbox.value = 'Appointments'; - - // start the module - window.GOVUK.modules.start(); - - // simulate input of new search text - searchTextbox.value = 'New doctor'; - helpers.triggerEvent(searchTextbox, 'input'); - - const listItems = list.querySelectorAll('.template-list-item'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - expect(listItemsShowing.length).toEqual(1); - expect(liveRegion.textContent.trim()).toEqual(liveRegionResults(1)); - - }); - - test("If an item doesn't match the search term but is selected, it should still show in the results", () => { - - searchTextbox.value = 'Appointments'; - - // mark 'Appointments' item as selected - checkedItem = list.querySelector('input[id=templates-or-folder-0]'); - checkedItem.checked = true; - - // start the module - window.GOVUK.modules.start(); - - // simulate input of new search text - searchTextbox.value = 'Prescriptions'; - helpers.triggerEvent(searchTextbox, 'input'); - - // should show despite not matching - expect(window.getComputedStyle(checkedItem).display).not.toEqual('none'); - - }); - - test("If the items have a block of text to match against, only results that match it should show", () => { - - searchTextbox.value = 'Appointments'; - - // start the module - window.GOVUK.modules.start(); - - // simulate input of new search text - searchTextbox.value = 'Email template'; - helpers.triggerEvent(searchTextbox, 'input'); - - const listItems = list.querySelectorAll('.template-list-item'); - const listItemsShowing = Array.from(listItems).filter(item => window.getComputedStyle(item).display !== 'none'); - - // 2 items contain the "Email template" text - // only the text containing the name of the item is matched against (ie 'New patient') - expect(listItemsShowing.length).toEqual(0); - expect(liveRegion.textContent.trim()).toEqual(liveRegionResults(0)); - - }); - - }); - - }) - describe("With a list of content items", () => { searchLabelText = "Search by name or email address"; diff --git a/tests/javascripts/previewPane.test.js b/tests/javascripts/previewPane.test.js deleted file mode 100644 index beacaa0cb..000000000 --- a/tests/javascripts/previewPane.test.js +++ /dev/null @@ -1,234 +0,0 @@ -const helpers = require('./support/helpers.js'); - -const emailPageURL = '/services/6658542f-0cad-491f-bec8-ab8457700ead/service-settings/set-email-branding'; -const emailPreviewConfirmationURL = '/services/6658542f-0cad-491f-bec8-ab8457700ead/service-settings/preview-email-branding'; -const letterPageURL = '/services/6658542f-0cad-491f-bec8-ab8457700ead/service-settings/set-letter-branding'; -const letterPreviewConfirmationURL = '/services/6658542f-0cad-491f-bec8-ab8457700ead/service-settings/preview-letter-branding'; - -let locationMock; - -beforeAll(() => { - - // mock calls to window.location - // default to the email page, the pathname can be changed inside specific tests - locationMock = new helpers.LocationMock(emailPageURL); - -}); - -afterAll(() => { - - // reset window.location to its original state - locationMock.reset(); - require('./support/teardown.js'); - -}); - -describe('Preview pane', () => { - - let form; - let radios; - - beforeEach(() => { - - const brands = { - "name": "branding_style", - "label": "Branding style", - "cssClasses": [], - "fields": [ - { - "label": "Department for Education", - "value": "dfe", - "checked": true - }, - { - "label": "Home Office", - "value": "ho", - "checked": false - }, - { - "label": "Her Majesty's Revenue and Customs", - "value": "hmrc", - "checked": false - }, - { - "label": "Department for Work and Pensions", - "value": "dwp", - "checked": false - } - ] - }; - - // set up DOM - document.body.innerHTML = - `
      -
      -
      -
      -
      - -
      -
      -
      - -
      `; - - document.querySelector('.govuk-grid-column-full').appendChild(helpers.getRadioGroup(brands)); - form = document.querySelector('form'); - radios = form.querySelector('fieldset'); - - }); - - afterEach(() => { - - document.body.innerHTML = ''; - - // we run the previewPane.js script every test - // the module cache needs resetting each time for the script to execute - jest.resetModules(); - - }); - - describe("If the page type is 'email'", () => { - - describe("When the page loads", () => { - - test("it should add the preview pane", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - expect(document.querySelector('iframe')).not.toBeNull(); - - }); - - test("it should change the form to submit the selection instead of posting to a preview page", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - expect(form.getAttribute('action')).toEqual(emailPreviewConfirmationURL); - - }); - - test("the preview pane should show the page for the selected brand", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - const selectedValue = Array.from(radios.querySelectorAll('input[type=radio]')).filter(radio => radio.checked)[0].value; - - expect(document.querySelector('iframe').getAttribute('src')).toEqual(`/_email?branding_style=${selectedValue}`); - - }); - - test("the submit button should change from 'Preview' to 'Save'", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - expect(document.querySelector('button[type=submit]').textContent).toEqual('Save'); - - }); - - }); - - describe("If the selection changes", () => { - - test("the page shown should match the selected brand", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - const newSelection = radios.querySelectorAll('input[type=radio]')[1]; - - helpers.moveSelectionToRadio(newSelection); - - expect(document.querySelector('iframe').getAttribute('src')).toEqual(`/_email?branding_style=${newSelection.value}`); - - }); - - }); - - }); - - describe("If the page type is 'letter'", () => { - - beforeEach(() => { - - // set page URL and page type to 'letter' - window.location.pathname = letterPreviewConfirmationURL; - form.setAttribute('data-preview-type', 'letter'); - - }); - - describe("When the page loads", () => { - - test("it should add the preview pane", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - expect(document.querySelector('iframe')).not.toBeNull(); - - }); - - test("it should change the form to submit the selection instead of posting to a preview page", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - expect(form.getAttribute('action')).toEqual(letterPreviewConfirmationURL); - - }); - - test("the preview pane should show the page for the selected brand", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - const selectedValue = Array.from(radios.querySelectorAll('input[type=radio]')).filter(radio => radio.checked)[0].value; - - expect(document.querySelector('iframe').getAttribute('src')).toEqual(`/_letter?branding_style=${selectedValue}`); - - }); - - test("the submit button should change from 'Preview' to 'Save'", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - expect(document.querySelector('button[type=submit]').textContent).toEqual('Save'); - - }); - - }); - - describe("If the selection changes", () => { - - test("the page shown should match the selected brand", () => { - - // run preview pane script - require('../../app/assets/javascripts/previewPane.js'); - - const newSelection = radios.querySelectorAll('input[type=radio]')[1]; - - helpers.moveSelectionToRadio(newSelection); - - expect(document.querySelector('iframe').getAttribute('src')).toEqual(`/_letter?branding_style=${newSelection.value}`); - - }); - - }); - - }); - -});