Add a form to filter notifications by recipient

Because manually editing the URL isn’t a great user interface, this
commit adds a search field to do this on the user’s behalf.

For this pass at the story it doesn’t do any validation – the user will
just get no results if they search by something which isn’t a phone
number or email address.

If the user navigates to a different ‘bucket’ of notifications (eg
delivered, failed) then the search term is reset, because they’ve
changed the filter which is at a level above the search term.
This commit is contained in:
Chris Hill-Scott
2017-05-30 13:51:25 +01:00
parent f41830e5d3
commit b9bf18b936
5 changed files with 97 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ from bs4 import BeautifulSoup
from app.main.views.jobs import get_time_left, get_status_filters
from tests import notification_json
from tests.conftest import SERVICE_ONE_ID
from freezegun import freeze_time
@@ -381,6 +382,54 @@ def test_can_show_notifications(
assert json_content.keys() == {'counts', 'notifications'}
@pytest.mark.parametrize("initial_query_arguments, expected_status_field_value, expected_search_box_contents", [
(
{
'message_type': 'sms',
},
'sending,delivered,failed',
'',
),
(
{
'status': 'failed',
'message_type': 'email',
'page': '99',
'to': 'test@example.com',
},
'failed',
'test@example.com',
),
])
def test_search_recipient_form(
logged_in_client,
mock_get_notifications,
mock_get_detailed_service,
initial_query_arguments,
expected_status_field_value,
expected_search_box_contents,
):
response = logged_in_client.get(url_for(
'main.view_notifications',
service_id=SERVICE_ONE_ID,
**initial_query_arguments
))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
action_url = page.find("form")['action']
url = urlparse(action_url)
assert url.path == '/services/{}/notifications/{}'.format(
SERVICE_ONE_ID,
initial_query_arguments['message_type']
)
query_dict = parse_qs(url.query)
assert query_dict == {}
assert page.find("input", {'name': 'status'})['value'] == expected_status_field_value
assert page.find("input", {'name': 'to'})['value'] == expected_search_box_contents
def test_should_show_notifications_for_a_service_with_next_previous(
logged_in_client,
service_one,