Skip to content

Commit

Permalink
🚑 [#4068] Skip step data validation when the step is not applicable
Browse files Browse the repository at this point in the history
Backport-of: #4075
  • Loading branch information
sergei-maertens committed Mar 28, 2024
1 parent b16e14d commit 3fbbca2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/openforms/submissions/api/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ def validate(self, attrs: dict):
for step in submission.steps:
errors = {}
assert step.form_step
components = step.form_step.form_definition.configuration["components"]

step_data_serializer = build_serializer(
components,
data=data,
context={"submission": submission},
)
if not step_data_serializer.is_valid():
errors = step_data_serializer.errors
if step.is_applicable:
components = step.form_step.form_definition.configuration["components"]
step_data_serializer = build_serializer(
components,
data=data,
context={"submission": submission},
)
if not step_data_serializer.is_valid():
errors = step_data_serializer.errors

if errors:
formio_validation_errors.append({"data": errors})
Expand Down
69 changes: 68 additions & 1 deletion src/openforms/tests/e2e/test_input_validation_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from furl import furl
from playwright.async_api import expect

from openforms.forms.tests.factories import FormFactory
from openforms.forms.tests.factories import FormFactory, FormStepFactory

from .base import E2ETestCase, browser_page

Expand Down Expand Up @@ -159,3 +159,70 @@ def setUpTestData():
await expect(
page.get_by_text("Een moment geduld", exact=False)
).to_be_visible()

@tag("gh-4068")
async def test_non_applicable_steps(self):
@sync_to_async
def setUpTestData():
form = FormFactory.create(
slug="validation",
registration_backend=None,
translation_enabled=False, # force Dutch
ask_privacy_consent=False,
ask_statement_of_truth=False,
)
FormStepFactory.create(
form=form,
next_text="Volgende",
form_definition__configuration={
"components": [
{
"type": "textfield",
"key": "textfield",
"label": "Optional textfield",
},
]
},
)
FormStepFactory.create(
form=form,
next_text="Volgende",
is_applicable=False, # should not be validated
form_definition__configuration={
"components": [
{
"type": "textfield",
"key": "textfield2",
"label": "Required textfield",
"validate": {"required": True},
},
]
},
)
return form

form = await setUpTestData()
form_url = str(
furl(self.live_server_url)
/ reverse("forms:form-detail", kwargs={"slug": form.slug})
)

async with browser_page() as page:
await page.goto(form_url)
# Start the form
await page.get_by_role("button", name="Formulier starten").click()

# Submit first step without filling anything out
await page.get_by_role("button", name="Volgende").click()

# Second step is n/a, should be skipped, so we go straight to the
# confirmation page.
await expect(
page.get_by_role("heading", name="Controleer en bevestig")
).to_be_visible()

# Confirm and finish the form
await page.get_by_role("button", name="Verzenden").click()
await expect(
page.get_by_text("Een moment geduld", exact=False)
).to_be_visible()

0 comments on commit 3fbbca2

Please sign in to comment.