mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 22:40:31 -04:00
Merge pull request #4163 from alphagov/branding-previews
Show a preview of GOV.UK and NHS email branding and apply straight away
This commit is contained in:
@@ -14,6 +14,7 @@ from notifications_utils.clients.zendesk.zendesk_client import (
|
||||
)
|
||||
|
||||
import app
|
||||
from app.main.views.service_settings import NHS_BRANDING_ID
|
||||
from tests import (
|
||||
find_element_by_tag_and_partial_text,
|
||||
invite_json,
|
||||
@@ -4771,6 +4772,7 @@ def test_update_service_organisation_does_not_update_if_same_value(
|
||||
def test_show_email_branding_request_page_when_no_branding_is_set(
|
||||
service_one,
|
||||
client_request,
|
||||
mocker,
|
||||
mock_get_email_branding,
|
||||
mock_get_letter_branding_by_id,
|
||||
organisation_type,
|
||||
@@ -4779,11 +4781,18 @@ def test_show_email_branding_request_page_when_no_branding_is_set(
|
||||
service_one['email_branding'] = None
|
||||
service_one['organisation_type'] = organisation_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('iframe')['src'] == url_for('main.email_template', branding_style='__NONE__')
|
||||
assert mock_get_letter_branding_by_id.called is False
|
||||
|
||||
button_text = normalize_spaces(page.select_one('.page-footer button').text)
|
||||
@@ -4983,17 +4992,22 @@ def test_show_email_branding_request_page_when_email_branding_is_set(
|
||||
client_request,
|
||||
mock_get_email_branding,
|
||||
mock_get_service_organisation,
|
||||
active_user_with_permissions,
|
||||
):
|
||||
service_one['email_branding'] = sample_uuid()
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
return_value=organisation_json(),
|
||||
)
|
||||
mocker.patch(
|
||||
'app.models.service.Service.email_branding_id',
|
||||
new_callable=PropertyMock,
|
||||
return_value='1234-abcd',
|
||||
)
|
||||
|
||||
page = client_request.get(
|
||||
'.email_branding_request', service_id=SERVICE_ONE_ID
|
||||
)
|
||||
assert page.find('iframe')['src'] == url_for('main.email_template', branding_style='1234-abcd')
|
||||
assert [
|
||||
(
|
||||
radio['value'],
|
||||
@@ -5432,24 +5446,19 @@ def test_submit_branding_when_something_else_is_only_option(
|
||||
) in mock_create_ticket.call_args_list[0][1]['message']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('endpoint, service_org_type, expected_heading', [
|
||||
('main.email_branding_govuk', 'central', 'Before you request new branding'),
|
||||
('main.email_branding_govuk_and_org', 'central', 'Before you request new branding'),
|
||||
('main.email_branding_govuk', 'central', 'Before you request new branding'),
|
||||
('main.email_branding_nhs', 'nhs_local', 'Before you request new branding'),
|
||||
('main.email_branding_organisation', 'central', 'When you request new branding'),
|
||||
@pytest.mark.parametrize('endpoint, expected_heading', [
|
||||
('main.email_branding_govuk_and_org', 'Before you request new branding'),
|
||||
('main.email_branding_organisation', 'When you request new branding'),
|
||||
])
|
||||
def test_get_email_branding_description_pages(
|
||||
def test_get_email_branding_description_pages_for_org_branding(
|
||||
client_request,
|
||||
mocker,
|
||||
service_one,
|
||||
organisation_one,
|
||||
mock_get_email_branding,
|
||||
endpoint,
|
||||
service_org_type,
|
||||
expected_heading,
|
||||
):
|
||||
organisation_one['organisation_type'] = service_org_type
|
||||
service_one['email_branding'] = sample_uuid()
|
||||
service_one['organisation'] = organisation_one
|
||||
|
||||
@@ -5466,6 +5475,39 @@ def test_get_email_branding_description_pages(
|
||||
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__'),
|
||||
('main.email_branding_nhs', 'nhs_local', NHS_BRANDING_ID),
|
||||
])
|
||||
def test_get_email_branding_govuk_and_nhs_pages(
|
||||
client_request,
|
||||
mocker,
|
||||
service_one,
|
||||
organisation_one,
|
||||
mock_get_email_branding,
|
||||
endpoint,
|
||||
service_org_type,
|
||||
branding_preview_id,
|
||||
):
|
||||
organisation_one['organisation_type'] = service_org_type
|
||||
service_one['email_branding'] = sample_uuid()
|
||||
service_one['organisation'] = organisation_one
|
||||
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
return_value=organisation_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'
|
||||
|
||||
|
||||
def test_get_email_branding_something_else_page(client_request):
|
||||
page = client_request.get(
|
||||
'main.email_branding_something_else',
|
||||
@@ -5495,11 +5537,43 @@ def test_get_email_branding_description_pages_give_404_if_selected_branding_not_
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('branding_choice, branding_description', [
|
||||
('govuk', 'GOV.UK'),
|
||||
('govuk_and_org', 'GOV.UK and organisation one'),
|
||||
])
|
||||
def test_submit_email_branding_request_from_govuk_description_page(
|
||||
def test_update_email_branding_from_govuk_preview_page(
|
||||
mocker,
|
||||
client_request,
|
||||
service_one,
|
||||
organisation_one,
|
||||
mock_get_service_settings_page_common,
|
||||
no_reply_to_email_addresses,
|
||||
mock_get_email_branding,
|
||||
single_sms_sender,
|
||||
mock_update_service,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
return_value=organisation_one,
|
||||
)
|
||||
mocker.patch(
|
||||
'app.models.service.Service.organisation_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'
|
||||
|
||||
|
||||
def test_submit_email_branding_request_from_govuk_and_org_description_page(
|
||||
mocker,
|
||||
client_request,
|
||||
service_one,
|
||||
@@ -5508,8 +5582,6 @@ def test_submit_email_branding_request_from_govuk_description_page(
|
||||
no_reply_to_email_addresses,
|
||||
mock_get_email_branding,
|
||||
single_sms_sender,
|
||||
branding_choice,
|
||||
branding_description,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
@@ -5529,9 +5601,8 @@ def test_submit_email_branding_request_from_govuk_description_page(
|
||||
)
|
||||
|
||||
page = client_request.post(
|
||||
'.email_branding_govuk',
|
||||
'.email_branding_govuk_and_org',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={'branding_choice': branding_choice},
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
@@ -5544,7 +5615,7 @@ def test_submit_email_branding_request_from_govuk_description_page(
|
||||
'',
|
||||
'---',
|
||||
'Current branding: Organisation name',
|
||||
f'Branding requested: {branding_description}\n',
|
||||
'Branding requested: GOV.UK and organisation one\n',
|
||||
]),
|
||||
subject='Email branding request - service one',
|
||||
ticket_type='question',
|
||||
@@ -5561,7 +5632,7 @@ def test_submit_email_branding_request_from_govuk_description_page(
|
||||
)
|
||||
|
||||
|
||||
def test_submit_email_branding_request_from_nhs_description_page(
|
||||
def test_update_email_branding_from_nhs_preview_page(
|
||||
mocker,
|
||||
client_request,
|
||||
service_one,
|
||||
@@ -5570,46 +5641,23 @@ def test_submit_email_branding_request_from_nhs_description_page(
|
||||
no_reply_to_email_addresses,
|
||||
mock_get_email_branding,
|
||||
single_sms_sender,
|
||||
mock_update_service,
|
||||
):
|
||||
service_one['email_branding'] = sample_uuid()
|
||||
service_one['organisation_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_nhs',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
mock_create_ticket.assert_called_once_with(
|
||||
ANY,
|
||||
message='\n'.join([
|
||||
'Organisation: Can’t tell (domain is user.gov.uk)',
|
||||
'Service: service one',
|
||||
'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb',
|
||||
'',
|
||||
'---',
|
||||
'Current branding: Organisation name',
|
||||
'Branding requested: NHS\n',
|
||||
]),
|
||||
subject='Email branding request - service one',
|
||||
ticket_type='question',
|
||||
user_name='Test User',
|
||||
user_email='test@user.gov.uk',
|
||||
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.'
|
||||
mock_update_service.assert_called_once_with(
|
||||
SERVICE_ONE_ID,
|
||||
email_branding=NHS_BRANDING_ID,
|
||||
)
|
||||
assert page.h1.text == 'Settings'
|
||||
assert normalize_spaces(page.select_one('.banner-default').text) == 'You’ve updated your email branding'
|
||||
|
||||
|
||||
def test_submit_email_branding_request_from_organisation_description_page(
|
||||
|
||||
Reference in New Issue
Block a user