Skip to content

Commit

Permalink
TSS-2016: policy teams search (#776)
Browse files Browse the repository at this point in the history
* Building forms

* Building views

* Adding views to URLs file

* Building HTML files

* Adding funcs to get data from API

* Adding policy team section to barrier details page

* Formatting

* Adding policy team dummy data to metadata file

* Adding new tests

* Updating dummy barrier to include policy team info

* Adding history functionality

* Formatting

* Amending for Flake8 error

* Making policy team descriptions dynamic

* Formatting

* Removing Barrier Category from page

* Removing comments

* Frontend test for policy teams

* Formatting

* removing unused imports

* Cleaning up tests

* Formatting

* updating to absolute imports

* Formatting

* fixing faulty test

* Adding HTML

* Primary functionality

* Frontend test

* Formatting

* Removing category filtering from search page

* Removing category search tests

---------

Co-authored-by: abarolo <[email protected]>
  • Loading branch information
EPedley and abarolo authored Aug 19, 2024
1 parent 95169ed commit e43eac3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
13 changes: 13 additions & 0 deletions barriers/forms/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class BarrierSearchForm(forms.Form):
label="Category",
required=False,
)
policy_team = forms.MultipleChoiceField(
label="Policy team",
required=False,
)
region = forms.MultipleChoiceField(
label="Overseas region",
required=False,
Expand Down Expand Up @@ -260,6 +264,7 @@ def __init__(self, metadata, *args, **kwargs):
self.set_sector_choices()
self.set_organisation_choices()
self.set_category_choices()
self.set_policy_team_choices()
self.set_region_choices()
self.set_status_choices()
self.set_tags_choices()
Expand Down Expand Up @@ -335,6 +340,13 @@ def set_category_choices(self):
choices.sort(key=itemgetter(1))
self.fields["category"].choices = choices

def set_policy_team_choices(self):
choices = [
(str(policy_team["id"]), policy_team["title"])
for policy_team in self.metadata.data["policy_teams"]
]
self.fields["policy_team"].choices = choices

def set_region_choices(self):
choices = [
(country["id"], country["name"])
Expand Down Expand Up @@ -454,6 +466,7 @@ def get_api_search_parameters(self):
params["ignore_all_sectors"] = self.cleaned_data.get("ignore_all_sectors")
params["organisation"] = ",".join(self.cleaned_data.get("organisation", []))
params["category"] = ",".join(self.cleaned_data.get("category", []))
params["policy_team"] = ",".join(self.cleaned_data.get("policy_team", []))
params["status"] = ",".join(self.cleaned_data.get("status", []))
params["tags"] = ",".join(self.cleaned_data.get("tags", []))
for status_value in STATUS_WITH_DATE_FILTER:
Expand Down
6 changes: 3 additions & 3 deletions templates/barriers/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
]
)
ReactApp.renderMultiSelectFilter("organisation")
ReactApp.renderMultiSelectFilter("category", "Search categories")
ReactApp.renderMultiSelectFilter("policy_team", "Search policy teams")
ReactApp.renderMultiSelectFilter("region")
ReactApp.renderAsyncSearchResults()
})
Expand Down Expand Up @@ -63,7 +63,7 @@ <h2 class="filter-list-title">Filter barriers by:</h2>
{% include "partials/forms/checkbox_filter.html" with field=form.trade_direction %}
{% include "partials/forms/checkbox_filter.html" with field=form.sector %}
{% include "partials/forms/checkbox_filter.html" with field=form.organisation %}
{% include "partials/forms/checkbox_filter.html" with field=form.category %}
{% include "partials/forms/checkbox_filter.html" with field=form.policy_team %}
{% include "partials/forms/checkbox_filter.html" with field=form.region %}
{% comment %} {% include 'partials/forms/checkbox_filter.html' with field=form.top_priority_status %}
{% include 'partials/forms/checkbox_filter.html' with field=form.priority_level %} {% endcomment %}
Expand Down Expand Up @@ -154,7 +154,7 @@ <h3 class="visually-hidden">Active filters:</h3>
{% include 'barriers/partials/active_filter.html' with filter=filters.trade_direction %}
{% include 'barriers/partials/active_filter.html' with filter=filters.sector %}
{% include 'barriers/partials/active_filter.html' with filter=filters.organisation %}
{% include 'barriers/partials/active_filter.html' with filter=filters.category %}
{% include 'barriers/partials/active_filter.html' with filter=filters.policy_team %}
{% include 'barriers/partials/active_filter.html' with filter=filters.search %}
{% include 'barriers/partials/active_filter.html' with filter=filters.region %}
{% include 'barriers/partials/active_filter.html' with filter=filters.combined_priority %}
Expand Down
20 changes: 19 additions & 1 deletion test_frontend/test_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from playwright.sync_api import expect

from .utils import get_base_url, retry
from test_frontend.utils import clean_full_url, get_base_url, retry


@retry()
Expand Down Expand Up @@ -57,3 +57,21 @@ def test_saved_search(page, create_test_barrier, session_data):

# back to search page
expect(page.get_by_role("link", name="Export type: Goods Activate")).to_be_visible()


@retry()
def test_search_for_a_barrier_with_policy_name_filter(
page, create_test_barrier, session_data
):

title = session_data["barrier_title"]
url = create_test_barrier(title=title)
page.goto(clean_full_url(url))

page.goto(get_search_page())
page.get_by_role("group", name="Policy team").locator("svg").click()
page.get_by_text("Gender", exact=True).click()
# remove focus on search box to allow the search results to update
page.get_by_role("heading", name="Market access barriers Search").click()

expect(page.get_by_text(title)).to_be_visible()
9 changes: 9 additions & 0 deletions tests/barriers/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def test_search_form_choices(self, mock_list):
category_choices = form.fields["category"].choices
assert len(category_choices) == len(category_list)

policy_team_list = set(
[policy_team["id"] for policy_team in metadata.data["policy_teams"]]
)
policy_team_choices = form.fields["policy_team"].choices
assert len(policy_team_choices) == len(policy_team_list)

region_list = set(
[region["id"] for region in metadata.get_overseas_region_list()]
)
Expand All @@ -81,6 +87,7 @@ def test_search_filters(self, mock_list):
"aa22c9d2-5f95-e211-a939-e4115bead28a",
],
"category": ["130", "141"],
"policy_team": ["10", "11"],
"region": [
"3e6809d6-89f6-4590-8458-1d0dab73ad1a",
"5616ccf5-ab4a-4c2c-9624-13c69be3c46b",
Expand All @@ -104,6 +111,7 @@ def test_search_filters(self, mock_list):
"aa22c9d2-5f95-e211-a939-e4115bead28a",
]
assert form.cleaned_data["category"] == ["130", "141"]
assert form.cleaned_data["policy_team"] == ["10", "11"]
assert form.cleaned_data["region"] == [
"3e6809d6-89f6-4590-8458-1d0dab73ad1a",
"5616ccf5-ab4a-4c2c-9624-13c69be3c46b",
Expand All @@ -128,6 +136,7 @@ def test_search_filters(self, mock_list):
"aa22c9d2-5f95-e211-a939-e4115bead28a"
),
category="130,141",
policy_team="10,11",
status="2",
user="1",
archived="0",
Expand Down
2 changes: 1 addition & 1 deletion tests/barriers/test_search_filter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BarrierSearchFilterValuesTestCase(MarketAccessTestCase):
form_class = BarrierSearchForm
parsed_checkboxes = None

excluded_fields = ["extra_location"]
excluded_fields = ["extra_location", "category"]

@classmethod
def generate_test_for_checkbox_values_equal_to_choices(cls, field_name):
Expand Down

0 comments on commit e43eac3

Please sign in to comment.