diff --git a/tests/data/hidden_required_field/hidden_required_field.bpmn b/tests/data/hidden_required_field/hidden_required_field.bpmn new file mode 100644 index 00000000..5e4ace06 --- /dev/null +++ b/tests/data/hidden_required_field/hidden_required_field.bpmn @@ -0,0 +1,116 @@ + + + + + Flow_0zt7wv5 + + + + + + + + + + + + + + + + Flow_0fb4w15 + Flow_0c2rym0 + + + + Flow_0cm6imh + Flow_0fb4w15 + if not 'require_yes_no' in globals(): + require_yes_no = True +if not 'hide_yes_no' in globals(): + hide_yes_no = True + + + + <H1>Good Bye{% if name %} {{ name }}{% endif %}</H1> + Flow_1qkjkbh + Flow_1udbzd6 + + + Flow_1udbzd6 + + + + <H1>Hello</H1> + Flow_0zt7wv5 + Flow_0cm6imh + + + + + + + + + + + + + + + + + Flow_0c2rym0 + Flow_1qkjkbh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/workflow/test_workflow_hidden_required_field.py b/tests/workflow/test_workflow_hidden_required_field.py new file mode 100644 index 00000000..fb22f6b9 --- /dev/null +++ b/tests/workflow/test_workflow_hidden_required_field.py @@ -0,0 +1,37 @@ +from tests.base_test import BaseTest +import json + + +class TestWorkflowHiddenRequiredField(BaseTest): + + def test_require_default(self): + # We have a field that can be hidden and required. + # Validation should fail if we don't have a default value. + spec_model = self.load_test_spec('hidden_required_field') + rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers()) + + json_data = json.loads(rv.get_data(as_text=True)) + self.assertEqual(json_data[0]['code'], 'hidden and required field missing default') + + def test_default_used(self): + # If a field is hidden and required, make sure we use the default value + + workflow = self.create_workflow('hidden_required_field') + workflow_api = self.get_workflow_api(workflow) + + first_task = workflow_api.next_task + self.assertEqual('Activity_Hello', first_task.name) + workflow_api = self.get_workflow_api(workflow) + + self.complete_form(workflow_api, first_task, {}) + workflow_api = self.get_workflow_api(workflow) + + second_task = workflow_api.next_task + self.assertEqual('Activity_HiddenField', second_task.name) + self.complete_form(workflow_api, second_task, {}) + workflow_api = self.get_workflow_api(workflow) + + # The color field is hidden and required. Make sure we use the default value + third_task = workflow_api.next_task + self.assertEqual('Activity_CheckDefault', third_task.name) + self.assertEqual('Gray', third_task.data['color'])