mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
Merge branch 'master' into add-brand-type-to-email-branding
This commit is contained in:
@@ -278,6 +278,34 @@ def test_conversation_reply_shows_templates(
|
||||
)
|
||||
|
||||
|
||||
def test_conversation_reply_shows_live_search_if_list_of_templates_taller_than_screen(
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mock_get_more_service_templates_than_can_fit_onscreen,
|
||||
):
|
||||
page = client_request.get(
|
||||
'main.conversation_reply',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
notification_id=fake_uuid,
|
||||
)
|
||||
|
||||
assert page.select('.live-search')
|
||||
|
||||
|
||||
def test_conversation_reply_shows_live_search_if_list_of_templates_fits_onscreen(
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mock_get_service_templates,
|
||||
):
|
||||
page = client_request.get(
|
||||
'main.conversation_reply',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
notification_id=fake_uuid,
|
||||
)
|
||||
|
||||
assert not page.select('.live-search')
|
||||
|
||||
|
||||
def test_conversation_reply_redirects_with_phone_number_from_notification(
|
||||
client_request,
|
||||
fake_uuid,
|
||||
|
||||
@@ -20,19 +20,26 @@ def test_email_branding_page_shows_full_branding_list(
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
radio_labels = page.select('div.multiple-choice > label')
|
||||
brand_names = [element.get_text().strip() for idx, element in enumerate(radio_labels)]
|
||||
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
|
||||
) == "Select an email branding to update or create a new email branding"
|
||||
) == "Email branding"
|
||||
|
||||
assert page.select_one('.column-three-quarters a')['href'] == url_for('main.create_email_branding')
|
||||
|
||||
first_label = radio_labels[0]
|
||||
assert normalize_spaces(first_label.text) == 'org 1'
|
||||
assert brand_names == [
|
||||
'org 1', 'org 2', 'org 3', 'org 4', 'org 5', 'Create a new email branding']
|
||||
|
||||
assert normalize_spaces((radio_labels[-1]).text) == 'Create a new email branding'
|
||||
'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(
|
||||
|
||||
@@ -1782,6 +1782,34 @@ def test_should_show_branding_styles(
|
||||
app.service_api_client.get_service.assert_called_once_with(service_one['id'])
|
||||
|
||||
|
||||
def test_should_show_live_search_if_list_of_brand_styles_fits_onscreen(
|
||||
logged_in_platform_admin_client,
|
||||
service_one,
|
||||
mock_get_email_branding_that_can_fit_onscreen,
|
||||
):
|
||||
response = logged_in_platform_admin_client.get(url_for(
|
||||
'main.service_set_email_branding', service_id=service_one['id']
|
||||
))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert not page.select('.live-search')
|
||||
|
||||
|
||||
def test_should_show_live_search_if_list_of_brand_styles_taller_than_page(
|
||||
logged_in_platform_admin_client,
|
||||
service_one,
|
||||
mock_get_more_email_branding_than_can_fit_onscreen,
|
||||
):
|
||||
response = logged_in_platform_admin_client.get(url_for(
|
||||
'main.service_set_email_branding', service_id=service_one['id']
|
||||
))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.select('.live-search')
|
||||
|
||||
|
||||
def test_should_send_branding_and_organisations_to_preview(
|
||||
logged_in_platform_admin_client,
|
||||
service_one,
|
||||
|
||||
@@ -147,6 +147,32 @@ def test_should_not_show_template_nav_if_only_one_type_of_template(
|
||||
assert not page.select('.pill')
|
||||
|
||||
|
||||
def test_should_not_show_live_search_if_list_of_templates_fits_onscreen(
|
||||
client_request,
|
||||
mock_get_service_templates
|
||||
):
|
||||
|
||||
page = client_request.get(
|
||||
'main.choose_template',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
|
||||
assert not page.select('.live-search')
|
||||
|
||||
|
||||
def test_should_show_live_search_if_list_of_templates_taller_than_screen(
|
||||
client_request,
|
||||
mock_get_more_service_templates_than_can_fit_onscreen
|
||||
):
|
||||
|
||||
page = client_request.get(
|
||||
'main.choose_template',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
|
||||
assert page.select('.live-search')
|
||||
|
||||
|
||||
def test_should_show_page_for_one_template(
|
||||
logged_in_client,
|
||||
mock_get_service_template,
|
||||
|
||||
@@ -956,40 +956,41 @@ def mock_update_service_template_400_content_too_big(mocker):
|
||||
side_effect=_update)
|
||||
|
||||
|
||||
def create_service_templates(service_id, number_of_templates=6):
|
||||
template_types = ["sms", "sms", "email", "email", "letter", "letter"]
|
||||
service_templates = []
|
||||
|
||||
for _ in range(1, number_of_templates + 1):
|
||||
template_number = "two" if _ % 2 == 0 else "one"
|
||||
template_type = template_types[(_ % 6) - 1]
|
||||
|
||||
service_templates.append(template_json(
|
||||
service_id,
|
||||
TEMPLATE_ONE_ID if _ == 1 else str(generate_uuid),
|
||||
"{}_template_{}".format(template_type, template_number),
|
||||
template_type,
|
||||
"{} template {} content".format(template_type, template_number),
|
||||
subject="{} template {} subject".format(template_type, template_number)
|
||||
if template_type in ["email", "letter"] else None
|
||||
))
|
||||
|
||||
return {'data': service_templates}
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_service_templates(mocker):
|
||||
uuid1 = TEMPLATE_ONE_ID
|
||||
uuid2 = str(generate_uuid())
|
||||
uuid3 = str(generate_uuid())
|
||||
uuid4 = str(generate_uuid())
|
||||
uuid5 = str(generate_uuid())
|
||||
uuid6 = str(generate_uuid())
|
||||
|
||||
def _create(service_id):
|
||||
return {'data': [
|
||||
template_json(
|
||||
service_id, uuid1, "sms_template_one", "sms", "sms template one content"
|
||||
),
|
||||
template_json(
|
||||
service_id, uuid2, "sms_template_two", "sms", "sms template two content"
|
||||
),
|
||||
template_json(
|
||||
service_id, uuid3, "email_template_one", "email", "email template one content",
|
||||
subject='email template one subject',
|
||||
),
|
||||
template_json(
|
||||
service_id, uuid4, "email_template_two", "email", "email template two content",
|
||||
subject='email template two subject',
|
||||
),
|
||||
template_json(
|
||||
service_id, uuid5, "letter_template_one", "letter", "letter template one content",
|
||||
subject='letter template one subject',
|
||||
),
|
||||
template_json(
|
||||
service_id, uuid6, "letter_template_two", "letter", "letter template two content",
|
||||
subject='letter template two subject',
|
||||
),
|
||||
]}
|
||||
return create_service_templates(service_id)
|
||||
|
||||
return mocker.patch(
|
||||
'app.service_api_client.get_service_templates',
|
||||
side_effect=_create)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_more_service_templates_than_can_fit_onscreen(mocker):
|
||||
def _create(service_id):
|
||||
return create_service_templates(service_id, number_of_templates=20)
|
||||
|
||||
return mocker.patch(
|
||||
'app.service_api_client.get_service_templates',
|
||||
@@ -2436,37 +2437,65 @@ 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={}, 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):
|
||||
brandings[row['idx']].update(non_standard_values)
|
||||
|
||||
if shuffle:
|
||||
brandings.insert(3, brandings.pop(4))
|
||||
|
||||
return brandings
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_all_email_branding(mocker):
|
||||
def _get_all_email_branding(sort_key=None):
|
||||
if sort_key:
|
||||
return [
|
||||
{'id': '1', 'name': 'org 1', 'text': 'org 1', 'colour': 'red', 'logo': 'logo1.png',
|
||||
'brand_type': 'govuk'},
|
||||
{'id': '2', 'name': 'org 2', 'text': 'org 2', 'colour': 'orange', 'logo': 'logo2.png',
|
||||
'brand_type': 'both'},
|
||||
{'id': '3', 'name': 'org 3', 'text': None, 'colour': None, 'logo': 'logo3.png', 'brand_type': 'org'},
|
||||
{'id': '4', 'name': 'org 4', 'text': 'org 4', 'colour': None, 'logo': 'logo4.png',
|
||||
'brand_type': 'org_banner'},
|
||||
{'id': '5', 'name': 'org 5', 'text': None, 'colour': 'blue', 'logo': 'logo5.png', 'brand_type': 'org'},
|
||||
]
|
||||
else:
|
||||
return [
|
||||
{'id': '1', 'name': 'org 1', 'text': 'org 1', 'colour': 'red', 'logo': 'logo1.png',
|
||||
'brand_type': 'govuk'},
|
||||
{'id': '2', 'name': 'org 2', 'text': 'org 2', 'colour': 'orange', 'logo': 'logo2.png',
|
||||
'brand_type': 'both'},
|
||||
{'id': '3', 'name': 'org 3', 'text': None, 'colour': None, 'logo': 'logo3.png', 'brand_type': 'org'},
|
||||
{'id': '5', 'name': 'org 5', 'text': None, 'colour': 'blue', 'logo': 'logo5.png',
|
||||
'brand_type': 'org_banner'},
|
||||
{'id': '4', 'name': 'org 4', 'text': 'org 4', 'colour': None, 'logo': 'logo4.png', 'brand_type': 'org'},
|
||||
]
|
||||
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.email_branding_client.get_all_email_branding', side_effect=_get_all_email_branding
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_more_email_branding_than_can_fit_onscreen(mocker):
|
||||
def _get_more_email_branding_than_can_fit_onscreen():
|
||||
return create_email_brandings(8)
|
||||
|
||||
return mocker.patch(
|
||||
'app.email_branding_client.get_all_email_branding',
|
||||
side_effect=_get_more_email_branding_than_can_fit_onscreen
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_email_branding_that_can_fit_onscreen(mocker):
|
||||
def _get_email_branding_that_can_fit_onscreen():
|
||||
return create_email_brandings(4)
|
||||
|
||||
return mocker.patch(
|
||||
'app.email_branding_client.get_all_email_branding',
|
||||
side_effect=_get_email_branding_that_can_fit_onscreen
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_letter_email_branding(mocker):
|
||||
def _get_letter_email_branding():
|
||||
|
||||
Reference in New Issue
Block a user