From 3069858a9f3346fb2277b7009955413a1748d1a0 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 30 Sep 2016 15:17:17 +0100 Subject: [PATCH] Fix pagination on activity page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The activity page was AJAXified in https://github.com/alphagov/notifications-admin/pull/952 but this didn’t take pagination into account. So if you visited page 2, the contents of the page would be replaced by Javascript with the contents of page 1. So you’d never be able to see anything beyond page 1, expect for a brief fraction of a second when the page loaded. This commit makes sure the AJAX request uses whatever page parameter is in the URL of the original page. --- app/main/views/jobs.py | 3 ++- app/templates/views/notifications.html | 2 +- tests/app/main/views/test_jobs.py | 24 +++++++++++++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index be376a989..756394bcc 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -173,7 +173,8 @@ def view_notifications(service_id, message_type): 'views/notifications.html', partials=get_notifications(service_id, message_type), message_type=message_type, - status=request.args.get('status') + status=request.args.get('status'), + page=request.args.get('page', 1) ) diff --git a/app/templates/views/notifications.html b/app/templates/views/notifications.html index 8ee8c5da6..48e809358 100644 --- a/app/templates/views/notifications.html +++ b/app/templates/views/notifications.html @@ -20,7 +20,7 @@ {{ ajax_block( partials, - url_for('.get_notifications_as_json', service_id=current_service.id, message_type=message_type, status=status), + url_for('.get_notifications_as_json', service_id=current_service.id, message_type=message_type, status=status, page=page), 'notifications' ) }} diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 0693d02f5..ab2813a57 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -279,6 +279,13 @@ def test_should_show_updates_for_one_job_as_json( ) ] ) +@pytest.mark.parametrize( + "page_argument, expected_page_argument", [ + (1, 1), + (22, 22), + (None, 1) + ] +) def test_can_show_notifications( app_, service_one, @@ -289,7 +296,9 @@ def test_can_show_notifications( message_type, page_title, status_argument, - expected_api_call + expected_api_call, + page_argument, + expected_page_argument ): with app_.test_request_context(): with app_.test_client() as client: @@ -298,7 +307,8 @@ def test_can_show_notifications( 'main.view_notifications', service_id=service_one['id'], message_type=message_type, - status=status_argument)) + status=status_argument, + page=page_argument)) assert response.status_code == 200 content = response.get_data(as_text=True) @@ -317,9 +327,17 @@ def test_can_show_notifications( status=status_argument ) == page.findAll("a", {"download": "download"})[0]['href'] + assert url_for( + '.get_notifications_as_json', + service_id=service_one['id'], + message_type=message_type, + status=status_argument, + page=expected_page_argument + ) == page.find("div", {'data-key': 'notifications'})['data-resource'] + mock_get_notifications.assert_called_with( limit_days=7, - page=1, + page=expected_page_argument, service_id=service_one['id'], status=expected_api_call, template_type=[message_type]