Label the search box dependent on message type

It doesn’t make sense to say ‘Search by email address or phone number’
when you’re only looking at emails.
This commit is contained in:
Chris Hill-Scott
2018-08-07 14:44:09 +01:00
parent bb4c77fd59
commit 214bfa9873
3 changed files with 32 additions and 4 deletions

View File

@@ -871,7 +871,19 @@ class SearchUsersForm(StripWhitespaceForm):
class SearchNotificationsForm(StripWhitespaceForm):
to = SearchField('Search by phone number or email address')
to = SearchField()
labels = {
'email': 'Search by email address',
'sms': 'Search by phone number',
}
def __init__(self, message_type, *args, **kwargs):
super().__init__(*args, **kwargs)
self.to.label.text = self.labels.get(
message_type,
'Search by phone number or email address',
)
class PlaceholderForm(StripWhitespaceForm):

View File

@@ -183,7 +183,10 @@ def view_notifications(service_id, message_type=None):
status=request.args.get('status') or 'sending,delivered,failed',
page=request.args.get('page', 1),
to=request.form.get('to', ''),
search_form=SearchNotificationsForm(to=request.form.get('to', '')),
search_form=SearchNotificationsForm(
message_type=message_type,
to=request.form.get('to', ''),
),
download_link=url_for(
'.download_notifications_csv',
service_id=current_service.id,

View File

@@ -297,13 +297,21 @@ def test_shows_message_when_no_notifications(
@pytest.mark.parametrize((
'initial_query_arguments,'
'form_post_data,'
'expected_search_box_label,'
'expected_search_box_contents'
), [
(
{},
{},
'Search by phone number or email address',
'',
),
(
{
'message_type': 'sms',
},
{},
'Search by phone number',
'',
),
(
@@ -313,6 +321,7 @@ def test_shows_message_when_no_notifications(
{
'to': '+33(0)5-12-34-56-78',
},
'Search by phone number',
'+33(0)5-12-34-56-78',
),
(
@@ -324,6 +333,7 @@ def test_shows_message_when_no_notifications(
{
'to': 'test@example.com',
},
'Search by email address',
'test@example.com',
),
])
@@ -333,6 +343,7 @@ def test_search_recipient_form(
mock_get_service_statistics,
initial_query_arguments,
form_post_data,
expected_search_box_label,
expected_search_box_contents,
):
response = logged_in_client.post(
@@ -351,11 +362,13 @@ def test_search_recipient_form(
url = urlparse(action_url)
assert url.path == '/services/{}/notifications/{}'.format(
SERVICE_ONE_ID,
initial_query_arguments['message_type']
)
initial_query_arguments.get('message_type', '')
).rstrip('/')
query_dict = parse_qs(url.query)
assert query_dict == {}
assert page.select_one('label[for=to]').text.strip() == expected_search_box_label
recipient_inputs = page.select("input[name=to]")
assert(len(recipient_inputs) == 2)