Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sentence casing on subject area, entity type labels when filters are selected #829

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion home/templatetags/clear_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def get_keys(dictionary: dict[str, dict]) -> list[str] | list:

@register.filter
def format_label(label: str) -> str:
return label.replace("_", " ").title() if "_" in label else label
return label.replace("_", " ").capitalize() if "_" in label else label
2 changes: 1 addition & 1 deletion templates/partial/selected_filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2 class="govuk-heading-m">{% translate "Selected filters" %}</h2>
</div>
{% for key in remove_filter_hrefs|get_keys %}
{% if remove_filter_hrefs|get_item:key|length > 0 %}
<h3 class="govuk-heading-s govuk-!-margin-bottom-0">{{key|title}}</h3>
<h3 class="govuk-heading-s govuk-!-margin-bottom-0">{{key|capfirst}}</h3>
<ul class="moj-filter-tags">
<input type="hidden" name="clear_label" value="">
{% for label, href in remove_filter_hrefs|get_items:key %}
Expand Down
40 changes: 0 additions & 40 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
from home.service.search_facet_fetcher import SearchFacetFetcher
from home.service.search_tag_fetcher import SearchTagFetcher

TMP_DIR = (Path(__file__).parent / "tmp").resolve()

fake = Faker()


Expand Down Expand Up @@ -88,44 +86,6 @@ def selenium(live_server) -> Generator[RemoteWebDriver, Any, None]:
selenium.quit()


phase_report_key = StashKey[dict[str, CollectReport]]()


@pytest.hookimpl(wrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
rep = yield

# store test results for each phase of a call, which can
# be "setup", "call", "teardown"
item.stash.setdefault(phase_report_key, {})[rep.when] = rep

return rep


@pytest.fixture(autouse=True)
def screenshotter(request, selenium: RemoteWebDriver):
yield

testname = request.node.name
report = request.node.stash[phase_report_key]

if report["setup"].failed:
# Nothing to screenshot
pass

elif ("call" not in report) or report["call"].failed:
timestamp = datetime.now().strftime(r"%Y%m%d%H%M%S")
TMP_DIR.mkdir(exist_ok=True)
path = str(TMP_DIR / f"{timestamp}-{testname}-failed.png")
total_height = selenium.execute_script(
"return document.body.parentNode.scrollHeight"
)
selenium.set_window_size(1920, total_height)
selenium.save_screenshot(path)
print(f"Screenshot saved to {path}")


class Page:
def __init__(self, selenium):
self.selenium = selenium
Expand Down
10 changes: 10 additions & 0 deletions tests/home/templatetags/test_clearfilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from home.templatetags.clear_filter import format_label


@pytest.mark.parametrize(
"label, expected", [("electronic_monitoring", "Electronic monitoring")]
)
def test_format_label(label, expected):
assert format_label(label) == expected
44 changes: 44 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from datetime import datetime
from pathlib import Path

import pytest
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

phase_report_key = pytest.StashKey[dict[str, pytest.CollectReport]]()

TMP_DIR = (Path(__file__).parent.parent / "tmp").resolve()


@pytest.hookimpl(wrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
rep = yield

# store test results for each phase of a call, which can
# be "setup", "call", "teardown"
item.stash.setdefault(phase_report_key, {})[rep.when] = rep

return rep


@pytest.fixture(autouse=True)
def screenshotter(request, selenium: RemoteWebDriver):
yield

testname = request.node.name
report = request.node.stash[phase_report_key]

if report["setup"].failed:
# Nothing to screenshot
pass

elif ("call" not in report) or report["call"].failed:
timestamp = datetime.now().strftime(r"%Y%m%d%H%M%S")
TMP_DIR.mkdir(exist_ok=True)
path = str(TMP_DIR / f"{timestamp}-{testname}-failed.png")
total_height = selenium.execute_script(
"return document.body.parentNode.scrollHeight"
)
selenium.set_window_size(1920, total_height)
selenium.save_screenshot(path)
print(f"Screenshot saved to {path}")