Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't validate step that is not applicable #4075

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading