Skip to content

Commit

Permalink
Merge pull request #41 from Crown-Commercial-Service/upgrade-to-govuk…
Browse files Browse the repository at this point in the history
…-frontend-v5

Update for use with GOV.UK Frontend v5.1
  • Loading branch information
tim-s-ccs authored Apr 17, 2024
2 parents 3ff515e + 94010f3 commit eb43a4e
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 104 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The following table shows the version of Digital Marketplace Frontend Jinja that

| Digital Marketplace Frontend Jinja Version | Target CCS Digital Marketplace GOV.UK Frontend Version |
| ----------------------------- | ------------------------------ |
| [2.0.0](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/2.0.0) | [6.0.0](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/6.0.0) |
| [1.4.1](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/1.4.1) | [5.5.0](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/5.5.0) |
| [1.4.0](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/1.4.0) | [5.5.0](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/5.5.0) |
| [1.3.3](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/1.3.3) | [5.4.3](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/5.4.3) |
Expand Down
2 changes: 1 addition & 1 deletion digitalmarketplace_frontend_jinja/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.4.1'
__version__ = '2.0.0'
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% set _ = params.__setitem__("maxwords", params.form.widget.max_length_in_words) %}

{% set _ = params.__setitem__("value", params.form.data) if params.form.data %}
{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint %}
{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint and "hint" not in params %}
{% set _ = params.__setitem__("errorMessage", { "text": params.form.errors[0] }) if params.form.errors %}

{{ govukCharacterCount(params) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{% set _ = params.__setitem__("name", name) %}
{% set _ = params.__setitem__("idPrefix", "input-" + name) %}

{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint %}
{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint and "hint" not in params %}
{% set _ = params.__setitem__("errorMessage", { "text": params.form.errors[0] }) if params.form.errors %}

{{ govukCheckboxes(params) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% set _ = params.__setitem__("id", "input-" + name) %}

{% set _ = params.__setitem__("value", params.form.data) if params.form.data %}
{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint %}
{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint and "hint" not in params %}
{% set _ = params.__setitem__("errorMessage", { "text": params.form.errors[0] }) if params.form.errors %}

{{ govukFileUpload(params) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% set _ = params.__setitem__("id", "input-" + name) %}

{% set _ = params.__setitem__("value", params.form.data) if params.form.data %}
{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint %}
{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint and "hint" not in params %}
{% set _ = params.__setitem__("errorMessage", { "text": params.form.errors[0] }) if params.form.errors %}

{{ govukInput(params) }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% macro digitalmarketplaceQuestionPricing(params) %}
{%- from "govuk_frontend_jinja/components/fieldset/macro.html" import govukFieldset -%}
{%- from "govuk_frontend_jinja/components/input/macro.html" import govukInput -%}
{%- from "govuk_frontend_jinja/components/select/macro.html" import govukSelect -%}
{%- from "govuk_frontend_jinja/components/error-message/macro.html" import govukErrorMessage -%}
{%- from "digitalmarketplace_frontend_jinja/components/select/macro.html" import govukSelect -%}

{% set name = params.question.id %}
{% set errorMessage = params.errors[name] if params.errors %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{% set _ = params.__setitem__("name", name) %}
{% set _ = params.__setitem__("idPrefix", "input-" + name) %}

{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint %}
{% set _ = params.__setitem__("hint", { "text": params.form.hint }) if params.form.hint and "hint" not in params %}
{% set _ = params.__setitem__("errorMessage", { "text": params.form.errors[0] }) if params.form.errors %}

{{ govukRadios(params) }}
Expand Down
84 changes: 8 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"author": "CCS",
"license": "MIT",
"devDependencies": {
"ccs-digitalmarketplace-govuk-frontend": "^5.5.0"
"ccs-digitalmarketplace-govuk-frontend": "^6.0.0"
}
}
8 changes: 4 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ccs-digitalmarketplace-apiclient==25.0.0
ccs-digitalmarketplace-utils==65.8.0
# via
# -r requirements.txt
# sanitized-package
# ccs-digitalmarketplace-frontend-jinja
certifi==2023.11.17
# via
# -r requirements.txt
Expand Down Expand Up @@ -100,10 +100,10 @@ govuk-country-register==0.5.0
# via
# -r requirements.txt
# ccs-digitalmarketplace-utils
govuk-frontend-jinja==2.8.0
govuk-frontend-jinja==3.0.0
# via
# -r requirements.txt
# sanitized-package
# ccs-digitalmarketplace-frontend-jinja
idna==3.6
# via
# -r requirements.txt
Expand All @@ -118,9 +118,9 @@ itsdangerous==2.1.2
jinja2==3.1.3
# via
# -r requirements.txt
# ccs-digitalmarketplace-frontend-jinja
# flask
# govuk-frontend-jinja
# sanitized-package
jmespath==1.0.1
# via
# -r requirements.txt
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cachelib==0.10.2
ccs-digitalmarketplace-apiclient==25.0.0
# via ccs-digitalmarketplace-utils
ccs-digitalmarketplace-utils==65.8.0
# via sanitized-package
# via ccs-digitalmarketplace-frontend-jinja
certifi==2023.11.17
# via requests
cffi==1.16.0
Expand Down Expand Up @@ -55,8 +55,8 @@ fleep==1.0.1
# via ccs-digitalmarketplace-utils
govuk-country-register==0.5.0
# via ccs-digitalmarketplace-utils
govuk-frontend-jinja==2.8.0
# via sanitized-package
govuk-frontend-jinja==3.0.0
# via ccs-digitalmarketplace-frontend-jinja
idna==3.6
# via requests
itsdangerous==2.1.2
Expand All @@ -65,9 +65,9 @@ itsdangerous==2.1.2
# flask-wtf
jinja2==3.1.3
# via
# ccs-digitalmarketplace-frontend-jinja
# flask
# govuk-frontend-jinja
# sanitized-package
jmespath==1.0.1
# via
# boto3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
include_package_data=True,
install_requires=[
'jinja2>3',
'govuk-frontend-jinja>=2.8.0,<3',
'govuk-frontend-jinja>=3,<4',
'ccs-digitalmarketplace-utils>=65.0.0',
],
python_requires=">=3.9,<3.12",
Expand Down
36 changes: 25 additions & 11 deletions tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def html_to_one_line(html: str):
return html


def assert_generated_html_matches_fixture(response, component_name, fixture_name, fixture_html):
assert response.status_code == 200
assert (
html_to_one_line(response.get_data().decode("utf-8")) == html_to_one_line(fixture_html)
), f"Did not match for '{component_name}' component with example: '{fixture_name}'"


@pytest.fixture(scope="session")
def component_fixtures():
return get_component_fixtures()
Expand All @@ -111,10 +118,12 @@ def test_render_component(client, component_fixtures, component_name, fixture_na
'params': fixture_options
})
)
assert response.status_code == 200
assert (
html_to_one_line(response.get_data().decode("utf-8")) == html_to_one_line(fixture_html)
), f"Did not match for '{component_name}' component with example: '{fixture_name}'"
assert_generated_html_matches_fixture(
response,
component_name,
fixture_name,
fixture_html
)


def test_all_jinja_templates_exist():
Expand All @@ -139,10 +148,12 @@ def test_all_jinja_templates_exist():
# 'params': fixture_options
# })
# )
# assert response.status_code == 200
# assert (
# html_to_one_line(response.get_data().decode("utf-8")) == html_to_one_line(fixture_html)
# ), f"Did not match for '{component_name}' component with example: '{fixture_name}'"
# assert_generated_html_matches_fixture(
# response,
# component_name,
# fixture_name,
# fixture_html
# )


# # Debugging test case for testing one component example
Expand All @@ -164,6 +175,9 @@ def test_all_jinja_templates_exist():
# print('---TEST---')
# print(html_to_one_line(fixture_html))
# print(html_to_one_line(response.get_data().decode("utf-8")))
# assert (
# html_to_one_line(response.get_data().decode("utf-8")) == html_to_one_line(fixture_html)
# ), f"Did not match for '{component_name}' component with example: '{fixture_name}'"
# assert_generated_html_matches_fixture(
# response,
# component_name,
# fixture_name,
# fixture_html
# )

0 comments on commit eb43a4e

Please sign in to comment.