From 797e4ad6419c02f8fd5316496bfcc3d1503827d9 Mon Sep 17 00:00:00 2001 From: Mitch Dawson <86007219+mitchdawson1982@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:26:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Live=20filtering=20(#520)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * initial commit * remove apply filter button * refactored to remove addition script function * update from oninput to onchange * remove apply filters methods --- home/forms/search.py | 13 +++++++++++-- templates/partial/filter.html | 4 ---- tests/selenium/conftest.py | 5 ----- tests/selenium/test_search_controls.py | 9 --------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/home/forms/search.py b/home/forms/search.py index 23b653ff..70449642 100644 --- a/home/forms/search.py +++ b/home/forms/search.py @@ -93,6 +93,7 @@ class SearchForm(forms.Form): "form": "searchform", "class": "govuk-select", "aria-label": "Domain", + "onchange": "document.getElementById('searchform').submit();", } ), ) @@ -107,14 +108,22 @@ class SearchForm(forms.Form): choices=get_where_to_access_choices, required=False, widget=forms.CheckboxSelectMultiple( - attrs={"class": "govuk-checkboxes__input", "form": "searchform"} + attrs={ + "class": "govuk-checkboxes__input", + "form": "searchform", + "onchange": "document.getElementById('searchform').submit();", + } ), ) entity_types = forms.MultipleChoiceField( choices=get_entity_types, required=False, widget=forms.CheckboxSelectMultiple( - attrs={"class": "govuk-checkboxes__input", "form": "searchform"} + attrs={ + "class": "govuk-checkboxes__input", + "form": "searchform", + "onchange": "document.getElementById('searchform').submit();", + } ), ) sort = forms.ChoiceField( diff --git a/templates/partial/filter.html b/templates/partial/filter.html index 352d5e92..b2740217 100644 --- a/templates/partial/filter.html +++ b/templates/partial/filter.html @@ -14,10 +14,6 @@

Filter

{% include "partial/selected_filters.html" %} {% endif %}
- Skip to results -
Domain diff --git a/tests/selenium/conftest.py b/tests/selenium/conftest.py index 5401cf44..8238d8e8 100644 --- a/tests/selenium/conftest.py +++ b/tests/selenium/conftest.py @@ -217,11 +217,6 @@ def selected_filter_tag(self, value) -> WebElement: def clear_filters(self) -> WebElement: return self.selenium.find_element(By.ID, "clear_filter") - def apply_filters_button(self) -> WebElement: - return self.selenium.find_element( - By.CSS_SELECTOR, 'button[data-test-id="apply-filters"]' - ) - def current_page(self) -> WebElement: return self.selenium.find_element( By.CLASS_NAME, "govuk-pagination__item--current" diff --git a/tests/selenium/test_search_controls.py b/tests/selenium/test_search_controls.py index cbe121aa..4124348b 100644 --- a/tests/selenium/test_search_controls.py +++ b/tests/selenium/test_search_controls.py @@ -47,7 +47,6 @@ def test_apply_domain_filters(self): domain = "Prisons" self.start_on_the_search_page() self.select_domain(domain) - self.click_apply_filters() self.verify_i_am_on_the_search_page() self.verify_i_have_results() self.verify_domain_selected(domain) @@ -88,7 +87,6 @@ def test_filters_query_and_sort_persist(self): domain = "Prisons" self.start_on_the_search_page() self.select_domain(domain) - self.click_apply_filters() self.enter_a_query_and_submit("nomis") self.click_option("Ascending") self.click_on_the_search_button() @@ -117,9 +115,7 @@ def test_adding_a_filter_resets_pagination(self): self.start_on_the_search_page() self.click_next_page() self.verify_page("2") - self.select_domain("Prisons") - self.click_apply_filters() self.verify_page("1") def test_clear_single_filter(self): @@ -130,7 +126,6 @@ def test_clear_single_filter(self): domain = "Prisons" self.start_on_the_search_page() self.select_domain(domain) - self.click_apply_filters() self.verify_domain_selected(domain) self.click_clear_selected_filter(domain) self.verify_unselected_domain() @@ -147,7 +142,6 @@ def test_clear_all_filters(self): 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() @@ -207,9 +201,6 @@ def select_domain(self, domain): def click_option(self, sortby): self.search_page.sort_label(sortby).click() - def click_apply_filters(self): - self.search_page.apply_filters_button().click() - def click_clear_selected_filter(self, name): self.search_page.selected_filter_tag(name).click()