Skip to content

Commit 90cc9d7

Browse files
authored
Add benefits appeal category (#73)
1 parent 3bd8aa3 commit 90cc9d7

File tree

9 files changed

+140
-4
lines changed

9 files changed

+140
-4
lines changed

app/categories/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .housing import bp as housing_bp
66
from .mental_capacity import bp as mental_capacity_bp
77
from .community_care import bp as community_care_bp
8+
from .benefits import bp as benefits_bp
89
from .results import bp as results_bp
910

1011
bp = Blueprint("categories", __name__)
@@ -15,5 +16,6 @@
1516
bp.register_blueprint(results_bp)
1617
bp.register_blueprint(asylum_immigration_bp)
1718
bp.register_blueprint(community_care_bp)
19+
bp.register_blueprint(benefits_bp)
1820

1921
from app.categories import urls # noqa: E402,F401

app/categories/benefits/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from flask import Blueprint
2+
3+
bp = Blueprint(
4+
"benefits",
5+
__name__,
6+
)
7+
8+
from app.categories.benefits import urls # noqa: E402,F401

app/categories/benefits/forms.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from wtforms import RadioField
2+
from wtforms.validators import InputRequired
3+
from flask_babel import lazy_gettext as _
4+
from app.categories.widgets import CategoryRadioInput
5+
from app.categories.forms import QuestionForm
6+
7+
8+
FALA_REDIRECT = {
9+
"endpoint": "find-a-legal-adviser.search",
10+
"category": "wb",
11+
}
12+
13+
14+
class AppealQuestionForm(QuestionForm):
15+
category = "Benefits"
16+
title = _("Legal aid only covers appeals to the")
17+
next_step_mapping = {
18+
"supreme_court": FALA_REDIRECT,
19+
"upper_tribunal": FALA_REDIRECT,
20+
"appeal_court": FALA_REDIRECT,
21+
"none": "categories.results.refer",
22+
}
23+
question = RadioField(
24+
title,
25+
widget=CategoryRadioInput(show_divider=True),
26+
validators=[InputRequired(message=_("Select where the appeal will be held"))],
27+
choices=[
28+
("upper_tribunal", _("Upper Tribunal (Administrative Appeals Chamber)")),
29+
("supreme_court", _("Supreme Court")),
30+
("appeal_court", _("Court of Appeal")),
31+
("", ""),
32+
("none", _("None of the above")),
33+
],
34+
)

app/categories/benefits/urls.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from . import bp
2+
from .forms import AppealQuestionForm
3+
from ..views import QuestionPage
4+
5+
bp.add_url_rule(
6+
"/benefits/appeal",
7+
view_func=QuestionPage.as_view(
8+
"appeal",
9+
form_class=AppealQuestionForm,
10+
template="categories/benefits/appeal.html",
11+
),
12+
)

app/categories/views.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@ class QuestionPage(View):
7979
- Routing to the next appropriate page
8080
"""
8181

82+
template: str = "categories/question-page.html"
8283
form_class: type[QuestionForm] | None = None
8384

84-
def __init__(self, form_class: type[QuestionForm]):
85+
def __init__(self, form_class: type[QuestionForm], template=None):
8586
"""Initialize the view with a form class.
8687
8788
Args:
8889
form_class: The WTForms form class to use for this question page
90+
template: The template to use for this question page
8991
"""
9092
self.form_class = form_class
93+
self.template = template or self.template
9194

9295
def get_next_page(self, answer: str) -> redirect:
9396
"""Determine and redirect to the next page based on the user's answer.
@@ -104,7 +107,10 @@ def get_next_page(self, answer: str) -> redirect:
104107
if answer not in self.form_class.next_step_mapping:
105108
raise ValueError(f"No mapping found for answer: {answer}")
106109

107-
return redirect(url_for(self.form_class.next_step_mapping[answer]))
110+
next_page = self.form_class.next_step_mapping[answer]
111+
if isinstance(next_page, dict):
112+
return redirect(url_for(**next_page))
113+
return redirect(url_for(next_page))
108114

109115
def update_session(self, answer: str | None = None) -> None:
110116
"""
@@ -142,6 +148,6 @@ def dispatch_request(self):
142148
form.question.data = previous_answer
143149

144150
return render_template(
145-
"categories/question-page.html",
151+
self.template,
146152
form=form,
147153
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{% extends "base.html" %}
2+
{%- from 'govuk_frontend_jinja/components/back-link/macro.html' import govukBackLink -%}
3+
{%- from 'govuk_frontend_jinja/components/exit-this-page/macro.html' import govukExitThisPage -%}
4+
5+
{% block pageTitle %}{%- if form.errors %}Error: {% endif -%}{{ form.title }} - GOV.UK{% endblock %}
6+
7+
{% block beforeContent%}
8+
{{ super() }}
9+
{{ govukBackLink({
10+
'href': back_link,
11+
'text': "Back"
12+
}) }}
13+
14+
{% if form.category == "Domestic Abuse" %}
15+
{{ govukExitThisPage("Exit this page")}}
16+
{% endif %}
17+
18+
{% endblock %}
19+
20+
{% block content %}
21+
22+
{{ super() }}
23+
24+
<div class="govuk-grid-row">
25+
<div class="govuk-grid-column-two-thirds">
26+
27+
<h1 class="govuk-heading-xl">{% trans %}Appeal a decision about your benefits{% endtrans %}</h1>
28+
<p class="govuk-body govuk-!-margin-bottom-0">{% trans %}Legal aid only covers appeals to the:{% endtrans %}</p>
29+
<ul class="govuk-list govuk-list--bullet">
30+
<li>{% trans %}Upper Tribunal (Administrative Appeals Chamber){% endtrans %}</li>
31+
<li>{% trans %}Supreme Court{% endtrans %}</li>
32+
<li>{% trans %}Court of Appeal{% endtrans %}</li>
33+
</ul>
34+
<p class="govuk-body">{% trans %}For all other benefits appeals, go to GOV.UK and read <a href="https://www.gov.uk/appeal-benefit-decision" target="_blank">Appeal a benefits decision (opens in new tab)</a>.{% endtrans %}</p>
35+
36+
<form class="govuk-!-margin-top-6" action="" method="get" novalidate>
37+
38+
{{ form.question() }}
39+
40+
{{ form.submit }}
41+
</form>
42+
43+
</div>
44+
</div>
45+
{% endblock %}

app/templates/categories/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h3 class="govuk-heading-m">Other problems covered by legal aid</h3>
6666

6767
{{ list_item_small("Benefits",
6868
"Appeal a decision about your benefits",
69-
url_for("categories.index")) }}
69+
url_for("categories.benefits.appeal")) }}
7070

7171
{{ list_item_small("Legal action against public organisations",
7272
"Includes schools, the police, government, prisons, NHS, the council.",

tests/functional_tests/categories/benefits/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from playwright.sync_api import Page, expect
2+
import pytest
3+
4+
5+
@pytest.mark.usefixtures("live_server")
6+
class TestAsylumAndImmigrationLandingPage:
7+
def assert_outcome(self, page: Page, option: str) -> None:
8+
page.get_by_label(option).check()
9+
page.get_by_role("button", name="Continue").click()
10+
expect(page.get_by_text("Find a legal adviser")).to_be_visible()
11+
expect(page.get_by_text("For welfare benefits")).to_be_visible()
12+
13+
def test_appeal_upper_tribunal(self, page: Page):
14+
page.get_by_role("link", name="Benefits").click()
15+
self.assert_outcome(page, "Upper Tribunal (Administrative Appeals Chamber)")
16+
17+
def test_appeal_supreme_court(self, page: Page):
18+
page.get_by_role("link", name="Benefits").click()
19+
self.assert_outcome(page, "Supreme Court")
20+
21+
def test_appeal_appeal_court(self, page: Page):
22+
page.get_by_role("link", name="Benefits").click()
23+
self.assert_outcome(page, "Court of Appeal")
24+
25+
def test_appeal_none(self, page: Page):
26+
page.get_by_role("link", name="Benefits").click()
27+
page.get_by_label("None of the above").check()
28+
page.get_by_role("button", name="Continue").click()
29+
expect(page.get_by_text("Referral page")).to_be_visible()

0 commit comments

Comments
 (0)