Merge pull request #2010 from alphagov/one-off-fixxx

Add pagination to inbox page
This commit is contained in:
Chris Waszczuk
2018-04-09 10:30:24 +01:00
committed by GitHub
7 changed files with 137 additions and 64 deletions

View File

@@ -196,13 +196,16 @@ def test_view_conversation_with_empty_inbound(
):
mock_get_inbound_sms = mocker.patch(
'app.main.views.conversation.service_api_client.get_inbound_sms',
return_value=[{
'user_number': '07900000001',
'notify_number': '07900000002',
'content': '',
'created_at': datetime.utcnow().isoformat(),
'id': fake_uuid
}]
return_value={
'has_next': False,
'data': [{
'user_number': '07900000001',
'notify_number': '07900000002',
'content': '',
'created_at': datetime.utcnow().isoformat(),
'id': fake_uuid
}]
}
)
page = client_request.get(

View File

@@ -164,10 +164,13 @@ def test_inbound_messages_shows_count_of_messages(
@pytest.mark.parametrize('index, expected_row', enumerate([
'07900 900000 message-1 1 hour ago',
'07900 900000 message-2 1 hour ago',
'07900 900000 message-3 1 hour ago',
'07900 900002 message-4 3 hours ago',
'07900 900004 message-5 5 hours ago',
'07900 900006 message-6 7 hours ago',
'07900 900008 message-7 9 hours ago',
'07900 900008 message-8 9 hours ago',
]))
def test_inbox_showing_inbound_messages(
logged_in_client,
@@ -177,7 +180,7 @@ def test_inbox_showing_inbound_messages(
mock_get_detailed_service,
mock_get_template_statistics,
mock_get_usage,
mock_get_inbound_sms,
mock_get_most_recent_inbound_sms,
index,
expected_row,
):
@@ -189,17 +192,35 @@ def test_inbox_showing_inbound_messages(
assert response.status_code == 200
rows = page.select('tbody tr')
assert len(rows) == 5
assert len(rows) == 8
assert normalize_spaces(rows[index].text) == expected_row
assert normalize_spaces(page.select('.table-show-more-link')) == (
'8 messages from 5 users'
)
assert page.select_one('a[download]')['href'] == url_for(
'main.inbox_download',
service_id=SERVICE_ONE_ID,
)
def test_get_inbound_sms_shows_page_links(
logged_in_client,
service_one,
mock_get_service_templates_when_no_templates_exist,
mock_get_jobs,
mock_get_detailed_service,
mock_get_template_statistics,
mock_get_usage,
mock_get_most_recent_inbound_sms,
mock_get_inbound_number_for_service,
):
service_one['permissions'] = ['inbound_sms']
response = logged_in_client.get(url_for('main.inbox', service_id=SERVICE_ONE_ID, page=2))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert 'Next page' in page.find('li', {'class': 'next-page'}).text
assert 'Previous page' in page.find('li', {'class': 'previous-page'}).text
def test_empty_inbox(
logged_in_client,
service_one,
@@ -208,7 +229,7 @@ def test_empty_inbox(
mock_get_detailed_service,
mock_get_template_statistics,
mock_get_usage,
mock_get_inbound_sms_with_no_messages,
mock_get_most_recent_inbound_sms_with_no_messages,
mock_get_inbound_number_for_service,
):
@@ -222,6 +243,8 @@ def test_empty_inbox(
'When users text your services phone number (0781239871) youll see the messages here'
)
assert not page.select('a[download]')
assert not page.select('li.next-page')
assert not page.select('li.previous-page')
@pytest.mark.parametrize('endpoint', [
@@ -244,7 +267,7 @@ def test_anyone_can_see_inbox(
api_user_active,
service_one,
mocker,
mock_get_inbound_sms_with_no_messages,
mock_get_most_recent_inbound_sms_with_no_messages,
mock_get_inbound_number_for_service,
):
@@ -266,7 +289,7 @@ def test_view_inbox_updates(
logged_in_client,
service_one,
mocker,
mock_get_inbound_sms_with_no_messages,
mock_get_most_recent_inbound_sms_with_no_messages,
):
mock_get_partials = mocker.patch(
@@ -333,13 +356,16 @@ def test_download_inbox_strips_formulae(
mocker.patch(
'app.service_api_client.get_inbound_sms',
return_value=[{
'user_number': 'elevenchars',
'notify_number': 'foo',
'content': message_content,
'created_at': datetime.utcnow().isoformat(),
'id': fake_uuid,
}],
return_value={
'has_next': False,
'data': [{
'user_number': 'elevenchars',
'notify_number': 'foo',
'content': message_content,
'created_at': datetime.utcnow().isoformat(),
'id': fake_uuid,
}]
},
)
response = logged_in_client.get(
url_for('main.inbox_download', service_id=SERVICE_ONE_ID)