Skip to content

Commit

Permalink
Update functional tests to do full traversal to get to the means pages
Browse files Browse the repository at this point in the history
  • Loading branch information
said-moj committed Mar 11, 2025
1 parent 5b79b09 commit 1ddd7fa
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/categories/send/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


class SendChildInCareQuestionForm(ChildInCareQuestionForm):
category = EDUCATION
category = EDUCATION.sub.tribunals
20 changes: 18 additions & 2 deletions tests/functional_tests/means_test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,31 @@ def navigate_to_means_test(page: Page):

@pytest.fixture
def complete_about_you_form(
page: Page, about_you_answers: dict, navigate_to_means_test
page: Page, navigate_to_means_test, about_you_answers: dict
):
for question, answer in about_you_answers.items():
questions = {
"Do you have a partner?": "No",
"Do you receive any benefits (including Child Benefit)?": "No",
"Do you have any children aged 15 or under?": "No",
"Do you have any dependants aged 16 or over?": "No",
"Do you own any property?": "No",
"Are you employed?": "No",
"Are you self-employed?": "No",
"Are you or your partner (if you have one) aged 60 or over?": "No",
"Do you have any savings or investments?": "No",
"Do you have any valuable items worth over £500 each?": "No",
}

questions.update(about_you_answers)
for question, answer in questions.items():
form_group = page.get_by_role("group", name=question)
if question == "Do you have a partner?":
locator = "#has_partner" if answer == "Yes" else "#has_partner-2"
form_group.locator(locator).check()
elif question == "How many children aged 15 or under?":
page.locator("#num_children").fill(answer)
elif question == "How many dependants aged 16 or over?":
page.locator("#num_dependents").fill(answer)
else:
form_group.get_by_label(answer).first.check()

Expand Down
53 changes: 24 additions & 29 deletions tests/functional_tests/means_test/test_benefits_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from flask import url_for
from playwright.sync_api import Page, expect
from app.means_test import YES, NO


next_page_heading = "Check your answers and confirm"
Expand Down Expand Up @@ -100,36 +99,32 @@ def test_child_benefits_not_available(page: Page, client):


@pytest.mark.usefixtures("live_server")
def test_child_benefits_available_have_children(page: Page, client):
#
with client.session_transaction() as session:
# update the session
session.get_eligibility().add(
"about-you", {"have_children": YES, "have_dependents": NO}
)

url = url_for("means_test.benefits", _external=True)
response = client.get(url)
assert response.status_code == 200 # Ensure the response is valid

# Load the response HTML into the Playwright page
page.set_content(response.data.decode("utf-8"))
@pytest.mark.parametrize(
"about_you_answers",
[
{
"Do you receive any benefits (including Child Benefit)?": "Yes",
"Do you have any children aged 15 or under?": "Yes",
"How many children aged 15 or under?": "1",
}
],
)
def test_child_benefits_available_have_children(page: Page, complete_about_you_form):
assert page.title() == "Which benefits do you receive? - GOV.UK"
expect(page.get_by_label("Child Benefit")).to_have_count(1)


@pytest.mark.usefixtures("live_server")
def test_child_benefits_available_have_dependents(page: Page, client):
#
with client.session_transaction() as session:
# update the session
session.get_eligibility().add(
"about-you", {"have_children": NO, "have_dependents": YES}
)

url = url_for("means_test.benefits", _external=True)
response = client.get(url)
assert response.status_code == 200 # Ensure the response is valid

# Load the response HTML into the Playwright page
page.set_content(response.data.decode("utf-8"))
@pytest.mark.parametrize(
"about_you_answers",
[
{
"Do you receive any benefits (including Child Benefit)?": "Yes",
"Do you have any dependants aged 16 or over?": "Yes",
"How many dependants aged 16 or over?": "1",
}
],
)
def test_child_benefits_available_have_dependents(page: Page, complete_about_you_form):
assert page.title() == "Which benefits do you receive? - GOV.UK"
expect(page.get_by_label("Child Benefit")).to_have_count(1)
1 change: 1 addition & 0 deletions tests/functional_tests/means_test/test_income.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def fill_about_form(page: Page, questions: dict) -> None:
],
)
@pytest.mark.usefixtures("live_server")
@pytest.mark.usefixtures("navigate_to_means_test")
def test_about_form(page: Page, scenario: str, form_inputs: dict, expected: dict):
page.goto(url_for("means_test.about-you", _external=True))

Expand Down
2 changes: 2 additions & 0 deletions tests/functional_tests/means_test/test_savings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def fill_about_form(page: Page, questions: dict) -> None:
],
)
@pytest.mark.usefixtures("live_server")
@pytest.mark.usefixtures("navigate_to_means_test")
def test_savings_form(page: Page, scenario: str, form_inputs: dict, expected: dict):
page.goto(url_for("means_test.about-you", _external=True))

Expand Down Expand Up @@ -196,6 +197,7 @@ def test_savings_form(page: Page, scenario: str, form_inputs: dict, expected: di
],
)
@pytest.mark.usefixtures("live_server")
@pytest.mark.usefixtures("navigate_to_means_test")
def test_savings_form_validators(
page: Page,
scenario: str,
Expand Down
2 changes: 2 additions & 0 deletions tests/functional_tests/test_back_link.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from flask import url_for
from playwright.sync_api import Page, expect
from tests.functional_tests.means_test.conftest import navigate_to_means_test # noqa: F401


@pytest.mark.usefixtures("live_server")
Expand Down Expand Up @@ -74,6 +75,7 @@ def test_fala_journey(page: Page):


@pytest.mark.usefixtures("live_server")
@pytest.mark.usefixtures("navigate_to_means_test")
def test_fallback(page: Page):
"""Test that we go to session expired page if we press back when referred from an external page"""
page.goto("https://www.gov.uk")
Expand Down

0 comments on commit 1ddd7fa

Please sign in to comment.