Skip to content

Commit

Permalink
🧪 [#4980] Add test for select component with a form variable as a dat…
Browse files Browse the repository at this point in the history
…a source

When a select component has a form variable as data source, the 'enum' property in the JSON schema is currently unfilled, because the 'values' option of the component is an empty list.

Solution is to fetch the corresponding form variable and update the 'enum' property in the schema accordingly
  • Loading branch information
viktorvanwijk committed Jan 10, 2025
1 parent 7997531 commit a887aa9
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/openforms/forms/tests/test_form_to_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
FormDefinitionFactory,
FormFactory,
FormStepFactory,
FormVariableFactory,
)
from openforms.forms.utils import form_variables_to_json_schema

Expand Down Expand Up @@ -80,8 +81,43 @@ def test_form_to_json_schema(self):
"auth_bsn",
"today",
)
var_properties = form_variables_to_json_schema(form, vars_to_include)
schema = form_variables_to_json_schema(form, vars_to_include)

from pprint import pprint
pprint(var_properties)
def test_select_component_with_form_variable_as_data_source(self):
form = FormFactory.create()
form_def_1 = FormDefinitionFactory.create(
configuration={
"components": [
{
"label": "Select",
"key": "select",
"type": "select",
"openForms": {
"dataSrc": "variable",
"translations": {},
"itemsExpression": {"var": "valuesForSelect"}
},
"data": {
"values": [],
"json": "",
"url": "",
"resource": "",
"custom": "",
},
},
]
}
)
form_step_1 = FormStepFactory.create(form=form, form_definition=form_def_1)

FormVariableFactory.create(
form=form,
name="Values for select",
key="valuesForSelect",
user_defined=True,
initial_value=["A", "B", "C"]
)

schema = form_variables_to_json_schema(form, ["select"])

self.assertEqual(schema["properties"]["select"]["enum"], ["A", "B", "C"])

0 comments on commit a887aa9

Please sign in to comment.