Skip to content

Commit

Permalink
adding test for page with conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
srh-sloan committed Jul 18, 2024
1 parent c6f342a commit 6c5442b
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tasks/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@
from app.db.models import Subcriteria
from app.db.models import Theme

BASIC_FUND_INFO = {
"name_json": {"en": "Unit Test Fund"},
"title_json": {"en": "funding to improve testing"},
"description_json": {"en": "A £10m fund to improve testing across the devolved nations."},
"welsh_available": False,
}
BASIC_ROUND_INFO = {
"audit_info": {"user": "dummy_user", "timestamp": datetime.now().isoformat(), "action": "create"},
"title_json": {"en": "round the first"},
"opens": datetime.now(),
"deadline": datetime.now(),
"assessment_start": datetime.now(),
"reminder_date": datetime.now(),
"assessment_deadline": datetime.now(),
"prospectus_link": "http://www.google.com",
"privacy_notice_link": "http://www.google.com",
}


def init_salmon_fishing_fund():

Expand Down
128 changes: 128 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
from app.db.models import Form
from app.db.models import Fund
from app.db.models import Lizt
from app.db.models import Page
from app.db.models import Round
from app.db.models import Section
from app.db.queries.application import get_component_by_id
from app.db.queries.fund import get_fund_by_id
from app.question_reuse.generate_assessment_config import build_assessment_config
from app.question_reuse.generate_form import build_form_json
from tasks.test_data import BASIC_FUND_INFO
from tasks.test_data import BASIC_ROUND_INFO


def test_build_form_json_no_conditions(seed_dynamic_data):
Expand Down Expand Up @@ -52,6 +57,129 @@ def test_build_form_json_no_conditions(seed_dynamic_data):
assert summary


fund_id = uuid4()
round_id = uuid4()
section_id = uuid4()
form_id = uuid4()
page_1_id = uuid4()
page_2_id = uuid4()


@pytest.mark.seed_config(
{
"funds": [Fund(fund_id=fund_id, short_name="UTFWC", **BASIC_FUND_INFO)],
"rounds": [Round(round_id=round_id, fund_id=fund_id, short_name="UTRWC", **BASIC_ROUND_INFO)],
"sections": [
Section(
section_id=section_id, index=1, round_id=round_id, name_in_apply_json={"en": "Organisation Information"}
)
],
"forms": [
Form(
form_id=form_id,
section_id=section_id,
name_in_apply_json={"en": "About your organisation"},
section_index=1,
runner_publish_name="about-your-org",
)
],
"pages": [
Page(
page_id=page_1_id,
form_id=form_id,
display_path="organisation-name",
name_in_apply_json={"en": "Organisation Name"},
form_index=1,
),
Page(
page_id=page_2_id,
form_id=None,
display_path="organisation-alternative-names",
name_in_apply_json={"en": "Alternative names of your organisation"},
form_index=2,
is_template=True,
),
],
"components": [
Component(
component_id=uuid4(),
page_id=page_1_id,
title="What is your organisation's name?",
hint_text="This must match the regsitered legal organisation name",
type=ComponentType.TEXT_FIELD,
page_index=1,
theme_id=None,
options={"hideTitle": False, "classes": ""},
runner_component_name="organisation_name",
),
Component(
component_id=uuid4(),
page_id=page_1_id,
title="Does your organisation use any other names?",
type=ComponentType.YES_NO_FIELD,
page_index=2,
theme_id=None,
options={"hideTitle": False, "classes": ""},
runner_component_name="does_your_organisation_use_other_names",
is_template=True,
conditions=[
{
"name": "organisation_other_names_no",
"value": "false", # this must be lowercaes or the navigation doesn't work
"operator": "is",
"destination_page_path": "CONTINUE",
},
{
"name": "organisation_other_names_yes",
"value": "true", # this must be lowercaes or the navigation doesn't work
"operator": "is",
"destination_page_path": "organisation-alternative-names",
},
],
),
Component(
component_id=uuid4(),
page_id=page_2_id,
title="Alternative Name 1",
type=ComponentType.TEXT_FIELD,
page_index=1,
theme_id=None,
options={"hideTitle": False, "classes": ""},
runner_component_name="alt_name_1",
is_template=True,
),
],
}
)
def test_build_form_json_with_conditions(seed_dynamic_data):

f: Fund = get_fund_by_id(seed_dynamic_data["funds"][0].fund_id)
form: Form = f.rounds[0].sections[0].forms[0]

result = build_form_json(form=form)
assert result
assert len(result["pages"]) == 4
exp_start_path = "/intro-about-your-organisation"
exp_second_path = "/organisation-name"
assert result["startPage"] == exp_start_path
intro_page = next((p for p in result["pages"] if p["path"] == exp_start_path), None)
assert intro_page
assert intro_page["next"][0]["path"] == exp_second_path

org_name_page = next((p for p in result["pages"] if p["path"] == exp_second_path), None)
assert org_name_page
assert len(org_name_page["next"]) == 2
assert len(org_name_page["components"]) == 2

alt_names_page = next((p for p in result["pages"] if p["path"] == "/organisation-alternative-names"), None)
assert alt_names_page
assert alt_names_page["next"][0]["path"] == "/summary"
assert len(alt_names_page["components"]) == 1

summary = next((p for p in result["pages"] if p["path"] == "/summary"), None)
assert summary


# TODO this fails with components from a template (branching logic)
def test_build_assessment_config(seed_dynamic_data):

Expand Down

0 comments on commit 6c5442b

Please sign in to comment.