diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 5eb1b21f6..e7c87f6a7 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -34,6 +34,7 @@ from app.main.forms import ( OrganisationTypeForm, RenameServiceForm, RequestToGoLiveForm, + SearchTemplatesForm, ServiceContactDetailsForm, ServiceDataRetentionEditForm, ServiceDataRetentionForm, @@ -886,7 +887,9 @@ def service_set_email_branding(service_id): return render_template( 'views/service-settings/set-email-branding.html', form=form, - branding_dict=get_branding_as_dict(email_branding) + branding_dict=get_branding_as_dict(email_branding), + search_form=SearchTemplatesForm(), + show_search_box=(len(email_branding) > 6) ) diff --git a/app/templates/views/service-settings/set-email-branding.html b/app/templates/views/service-settings/set-email-branding.html index 62661d00d..bbdd7d86c 100644 --- a/app/templates/views/service-settings/set-email-branding.html +++ b/app/templates/views/service-settings/set-email-branding.html @@ -1,6 +1,7 @@ {% extends "withnav_template.html" %} {% from "components/radios.html" import radios %} {% from "components/page-footer.html" import page_footer %} +{% from "components/live-search.html" import live_search %} {% block service_page_title %} Set email branding @@ -10,11 +11,16 @@

Set email branding

+
+
+
+
{{ radios(form.branding_type) }}
-
+
+ {{ live_search(target_selector='.brand_styles .multiple-choice', show=show_search_box, form=search_form, label='Search branding styles by name') }} {{ radios(form.branding_style) }}
diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index a63c4e0b7..b87f834bd 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -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, diff --git a/tests/conftest.py b/tests/conftest.py index a8ccfcc22..8dc9cd751 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2472,6 +2472,28 @@ def mock_get_all_email_branding(mocker): ) +@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():