Skip to content

Commit

Permalink
Fix clear filter for entity type (#224)
Browse files Browse the repository at this point in the history
* fix clear filter for entity types

* improve clear_filter selenium test

* no head required
  • Loading branch information
LavMatt authored Apr 2, 2024
1 parent fd0d237 commit 12c9862
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion templates/partial/selected_filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2 class="govuk-heading-m">Selected filters</h2>
<p>
{% if label_clear_href|get_keys|length > 0 %}
<a class="govuk-link govuk-link--no-visited-state"
href="{% url 'home:search' %}{% query_string domain=None classifications=None where_to_access=None %}"
href="{% url 'home:search' %}{% query_string domain=None entity_types=None where_to_access=None %}"
id="clear_filter">
Clear filter
</a>
Expand Down
17 changes: 17 additions & 0 deletions tests/selenium/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ def get_selected_subdomain(self) -> WebElement:
select = self.subdomain_select()
return select.first_selected_option

def get_all_filter_names(self) -> list:
filter_names = [
item.text
for item in self.selenium.find_elements(
By.CLASS_NAME, "govuk-checkboxes__item"
)
]
return filter_names

def get_selected_checkbox_filter_names(self) -> list:
selected_filters = [
item.accessible_name
for item in self.selenium.find_elements(By.TAG_NAME, "input")
if item.aria_role == "checkbox" and item.is_selected()
]
return selected_filters

def sort_label(self, name) -> WebElement:
return self.selenium.find_element(By.XPATH, f"//label[ text() = '{name}' ]")

Expand Down
21 changes: 18 additions & 3 deletions tests/selenium/test_search_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_sorting(self):
# FIXME: this isn't preselected if the `new` query param is missing
self.verify_sort_selected("Relevance")

self.click_sort_option("Ascending")
self.click_option("Ascending")
self.click_on_the_search_button()
self.verify_i_have_results()
self.verify_sort_selected("Ascending")
Expand All @@ -121,7 +121,7 @@ def test_filters_query_and_sort_persist(self):
# self.select_subdomain(subdomain)
self.click_apply_filters()
self.enter_a_query_and_submit("nomis")
self.click_sort_option("Ascending")
self.click_option("Ascending")
self.click_on_the_search_button()

self.verify_i_have_results()
Expand Down Expand Up @@ -173,12 +173,19 @@ def test_clear_all_filters(self):
Users can click a button to clear all filters.
"""
domain = "Prison"

self.start_on_the_search_page()

filters = self.search_page.get_all_filter_names()
self.select_domain(domain)
for filter in filters:
self.click_option(filter)
self.click_apply_filters()
self.verify_domain_selected(domain)
self.verify_checkbox_filters_selected(filters)
self.click_clear_filters()
self.verify_unselected_domain()
self.verfiy_unselected_checkbox_filters()

def test_automated_accessibility_home(self):
self.start_on_the_home_page()
Expand Down Expand Up @@ -225,6 +232,14 @@ def click_on_the_glossary_link(self):
def click_on_the_search_button(self):
self.search_page.search_button().click()

def verify_checkbox_filters_selected(self, filters):
selected_filters = self.search_page.get_selected_checkbox_filter_names()
assert selected_filters == filters

def verfiy_unselected_checkbox_filters(self):
selected_filters = self.search_page.get_selected_checkbox_filter_names()
assert selected_filters == []

def verify_i_am_on_the_search_page(self):
assert "Search" in self.selenium.title
assert "Find MOJ Data" in self.search_page.primary_heading().text
Expand Down Expand Up @@ -263,7 +278,7 @@ def select_domain(self, domain):
def select_subdomain(self, domain):
self.search_page.select_subdomain(domain)

def click_sort_option(self, sortby):
def click_option(self, sortby):
self.search_page.sort_label(sortby).click()

def click_apply_filters(self):
Expand Down

0 comments on commit 12c9862

Please sign in to comment.