Skip to content

Commit

Permalink
Fix Departments pagination automatic filter application (lucyparson…
Browse files Browse the repository at this point in the history
…s#1078)

## Fixes issue
Fixes lucyparsons#1077 

## Description of Changes
Changes check if there are "filters" being applied to the list given in
the `departments` view. If there are no filters applied then we generate
a "next" link that does not automatically apply filters.

## Tests and linting
 - [x] This branch is up-to-date with the `develop` branch.
 - [x] `pytest` passes on my local development environment.
 - [x] `pre-commit` passes on my local development environment.

---------

Co-authored-by: sea-kelp <[email protected]>
  • Loading branch information
Spraynard and sea-kelp committed Feb 4, 2024
1 parent 96287a5 commit 7760715
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions OpenOversight/app/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime
from http import HTTPMethod, HTTPStatus
from traceback import format_exc
from typing import Optional

from flask import (
Response,
Expand Down Expand Up @@ -857,7 +858,7 @@ def redirect_list_officer(
unique_internal_identifier=None,
unit=None,
current_job=None,
require_photo: bool = False,
require_photo: Optional[bool] = None,
):
flash(FLASH_MSG_PERMANENT_REDIRECT)
return redirect(
Expand Down Expand Up @@ -897,7 +898,7 @@ def list_officer(
unique_internal_identifier=None,
unit=None,
current_job=None,
require_photo: bool = False,
require_photo: Optional[bool] = None,
):
form = BrowseForm()
form.rank.query = (
Expand Down
20 changes: 18 additions & 2 deletions OpenOversight/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,25 @@ def test_officer_browse_pagination(mockdata, browser, server_port):
total = Officer.query.filter_by(department_id=AC_DEPT).count()

# first page of results
browser.get(f"http://localhost:{server_port}/departments/{AC_DEPT}?page=1")
browser.get(
f"http://localhost:{server_port}/departments/{AC_DEPT}?page=1&gender=Not+Sure"
)
wait_for_element(browser, By.TAG_NAME, "body")
page_text = browser.find_element("tag name", "body").text
expected = f"Showing 1-{current_app.config[KEY_OFFICERS_PER_PAGE]} of {total}"
assert expected in page_text

# check that "Next" pagination link does not automatically add require_photo parameter
next_link = browser.find_elements(By.XPATH, '//li[@class="next"]/a')[
0
].get_attribute("href")
assert "gender" in next_link
assert "require_photo" not in next_link

# last page of results
last_page_index = (total // current_app.config[KEY_OFFICERS_PER_PAGE]) + 1
browser.get(
f"http://localhost:{server_port}/departments/{AC_DEPT}?page={last_page_index}"
f"http://localhost:{server_port}/departments/{AC_DEPT}?page={last_page_index}&gender=Not+Sure"
)
wait_for_element(browser, By.TAG_NAME, "body")
page_text = browser.find_element("tag name", "body").text
Expand All @@ -141,6 +150,13 @@ def test_officer_browse_pagination(mockdata, browser, server_port):
expected = f"Showing {start_of_page}-{total} of {total}"
assert expected in page_text

# check that "Previous" pagination link does not automatically add require_photo parameter
previous_link = browser.find_elements(By.XPATH, '//li[@class="previous"]/a')[
0
].get_attribute("href")
assert "gender" in previous_link
assert "require_photo" not in previous_link


@pytest.mark.xdist_group
def test_find_officer_can_see_uii_question_for_depts_with_uiis(
Expand Down

0 comments on commit 7760715

Please sign in to comment.