Skip to content

Commit

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

When a select box component has a form variable as data source, the 'properties' and 'required' properties in the JSON schema are currently unfilled, because the 'values' option of the component is an empty list.

Solution is to fetch the corresponding form variable and update the 'properties' and 'required' property in the schema accordingly
  • Loading branch information
viktorvanwijk committed Jan 10, 2025
1 parent a887aa9 commit 76c387e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/openforms/forms/tests/test_form_to_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,44 @@ def test_select_component_with_form_variable_as_data_source(self):
schema = form_variables_to_json_schema(form, ["select"])

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

def test_select_boxes_component_with_form_variable_as_data_source(self):
form = FormFactory.create()
form_def_1 = FormDefinitionFactory.create(
configuration={
"components": [
{
"label": "Select Boxes",
"key": "selectBoxes",
"type": "selectboxes",
"openForms": {
"dataSrc": "variable",
"translations": {},
"itemsExpression": {"var": "valuesForSelectBoxes"}
},
"values": []
},
]
}
)
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, ["selectBoxes"])

self.assertEqual(
schema["properties"]["selectBoxes"]["properties"],
{
"A": {"type": "boolean"},
"B": {"type": "boolean"},
"C": {"type": "boolean"},
}
)
self.assertEqual(schema["properties"]["selectBoxes"]["required"], ["A", "B", "C"])

0 comments on commit 76c387e

Please sign in to comment.