-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 [#4065] Skip validation in serializer fields when components are no…
…t visible This mimicks the validation logic from Formio itself, which forces a component to be valid when it's not visible or conditionally hidden. Backport-of: #4066
- Loading branch information
1 parent
08c82d0
commit 3d98575
Showing
3 changed files
with
165 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/openforms/tests/e2e/test_input_validation_regressions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from django.test import override_settings, tag | ||
from django.urls import reverse | ||
|
||
from asgiref.sync import sync_to_async | ||
from furl import furl | ||
from playwright.async_api import expect | ||
|
||
from openforms.forms.tests.factories import FormFactory | ||
|
||
from .base import E2ETestCase, browser_page | ||
|
||
|
||
# allow all origins, since we don't know exactly the generated live server port number | ||
@override_settings(CORS_ALLOW_ALL_ORIGINS=True) | ||
class InputValidationRegressionTests(E2ETestCase): | ||
|
||
@tag("gh-4065") | ||
async def test_hidden_components_validation(self): | ||
|
||
@sync_to_async | ||
def setUpTestData(): | ||
form = FormFactory.create( | ||
slug="validation", | ||
generate_minimal_setup=True, | ||
registration_backend=None, | ||
translation_enabled=False, # force Dutch | ||
ask_privacy_consent=False, | ||
ask_statement_of_truth=False, | ||
formstep__next_text="Volgende", | ||
formstep__form_definition__configuration={ | ||
"components": [ | ||
{ | ||
"type": "textfield", | ||
"key": "textfield", | ||
"label": "Visible text field", | ||
"validate": {"required": True}, | ||
}, | ||
{ | ||
"type": "number", | ||
"key": "number", | ||
"label": "Hidden number, clearOnHide", | ||
"validate": {"required": True}, | ||
"hidden": True, | ||
"clearOnHide": True, | ||
}, | ||
{ | ||
"type": "date", | ||
"key": "date", | ||
"label": "Hidden number, no clearOnHide", | ||
"validate": {"required": True}, | ||
"hidden": True, | ||
"clearOnHide": False, | ||
"defaultValue": "2024-03-27", | ||
}, | ||
{ | ||
"type": "bsn", | ||
"key": "bsn", | ||
"label": "Conditionally hidden", | ||
"validate": {"required": True}, | ||
"conditional": { | ||
"show": True, | ||
"when": "textfield", | ||
"eq": "show me the bsn", | ||
}, | ||
"clearOnHide": False, | ||
"defaultValue": "123456781", # invalid | ||
}, | ||
] | ||
}, | ||
) | ||
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() | ||
|
||
# Fill out the visible field | ||
await page.get_by_label("Visible text field").fill("testing") | ||
await page.get_by_role("button", name="Volgende").click() | ||
|
||
# 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() |