snapshot: preserve dynamic builder and section ordering work
This commit is contained in:
@@ -3,7 +3,8 @@ import json
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
|
||||
from workflows.models import FormConditionalRuleConfig, FormCustomFieldConfig, FormFieldConfig, FormOption, FormSectionConfig
|
||||
from workflows.models import FormConditionalRuleConfig, FormCustomFieldConfig, FormCustomSectionConfig, FormFieldConfig, FormOption, FormSectionConfig
|
||||
from workflows.roles import ROLE_PLATFORM_OWNER, assign_user_role
|
||||
|
||||
|
||||
class FormBuilderAdminTests(TestCase):
|
||||
@@ -20,6 +21,14 @@ class FormBuilderAdminTests(TestCase):
|
||||
password='secret123',
|
||||
email='builder_user@tub.co',
|
||||
)
|
||||
self.platform_owner = user_model.objects.create_user(
|
||||
username='builder_owner',
|
||||
password='secret123',
|
||||
email='builder_owner@tub.co',
|
||||
is_staff=True,
|
||||
is_superuser=True,
|
||||
)
|
||||
assign_user_role(self.platform_owner, ROLE_PLATFORM_OWNER)
|
||||
|
||||
def test_staff_can_open_form_builder(self):
|
||||
self.client.force_login(self.staff)
|
||||
@@ -118,6 +127,25 @@ class FormBuilderAdminTests(TestCase):
|
||||
self.assertEqual(department.is_required, True)
|
||||
self.assertEqual(contract_start.is_required, None)
|
||||
|
||||
def test_platform_owner_can_modify_locked_field_rules(self):
|
||||
self.client.force_login(self.platform_owner)
|
||||
self.client.get('/admin-tools/form-builder/?form_type=onboarding', HTTP_HOST='localhost')
|
||||
full_name = FormFieldConfig.objects.get(form_type='onboarding', field_name='full_name')
|
||||
|
||||
response = self.client.post(
|
||||
'/admin-tools/form-builder/?form_type=onboarding&option_category=device',
|
||||
data={
|
||||
'builder_action': 'save_field_rules',
|
||||
'field_rule_ids': [str(full_name.id)],
|
||||
f'is_required_{full_name.id}': 'optional',
|
||||
},
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
full_name.refresh_from_db()
|
||||
self.assertEqual(full_name.is_required, False)
|
||||
|
||||
def test_staff_can_save_section_rules_with_locked_sections_preserved(self):
|
||||
self.client.force_login(self.staff)
|
||||
self.client.get('/admin-tools/form-builder/?form_type=onboarding', HTTP_HOST='localhost')
|
||||
@@ -126,6 +154,7 @@ class FormBuilderAdminTests(TestCase):
|
||||
'/admin-tools/form-builder/?form_type=onboarding&option_category=device',
|
||||
data={
|
||||
'builder_action': 'save_section_rules',
|
||||
'section_order': ['itsetup', 'stammdaten', 'vertrag', 'abschluss'],
|
||||
},
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
@@ -135,6 +164,31 @@ class FormBuilderAdminTests(TestCase):
|
||||
stammdaten = FormSectionConfig.objects.get(form_type='onboarding', section_key='stammdaten')
|
||||
self.assertEqual(itsetup.is_visible, False)
|
||||
self.assertEqual(stammdaten.is_visible, True)
|
||||
self.assertEqual(itsetup.sort_order, 0)
|
||||
self.assertEqual(stammdaten.sort_order, 1)
|
||||
|
||||
def test_platform_owner_can_modify_locked_section_rules(self):
|
||||
self.client.force_login(self.platform_owner)
|
||||
self.client.get('/admin-tools/form-builder/?form_type=onboarding', HTTP_HOST='localhost')
|
||||
|
||||
response = self.client.post(
|
||||
'/admin-tools/form-builder/?form_type=onboarding&option_category=device',
|
||||
data={
|
||||
'builder_action': 'save_section_rules',
|
||||
'section_order': ['vertrag', 'stammdaten', 'itsetup', 'abschluss'],
|
||||
'section_visible_vertrag': 'on',
|
||||
'section_visible_itsetup': 'on',
|
||||
'section_visible_abschluss': 'on',
|
||||
},
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
stammdaten = FormSectionConfig.objects.get(form_type='onboarding', section_key='stammdaten')
|
||||
vertrag = FormSectionConfig.objects.get(form_type='onboarding', section_key='vertrag')
|
||||
self.assertEqual(vertrag.sort_order, 0)
|
||||
self.assertEqual(stammdaten.sort_order, 1)
|
||||
self.assertEqual(stammdaten.is_visible, False)
|
||||
|
||||
def test_apply_onboarding_lean_preset_updates_section_and_field_rules(self):
|
||||
self.client.force_login(self.staff)
|
||||
@@ -185,19 +239,19 @@ class FormBuilderAdminTests(TestCase):
|
||||
'conditional_field_employment-end-box_0': 'employment_type',
|
||||
'conditional_operator_employment-end-box_0': 'equals',
|
||||
'conditional_value_employment-end-box_0': 'befristet',
|
||||
'conditional_active_phone-box': 'on',
|
||||
'conditional_field_phone-box_0': 'successor_required_choice',
|
||||
'conditional_operator_phone-box_0': 'equals',
|
||||
'conditional_value_phone-box_0': 'ja',
|
||||
'conditional_field_phone-box_1': 'inherit_phone_number_choice',
|
||||
'conditional_operator_phone-box_1': 'not_equals',
|
||||
'conditional_value_phone-box_1': 'ja',
|
||||
'conditional_active_successor-box': 'on',
|
||||
'conditional_field_successor-box_0': 'successor_required_choice',
|
||||
'conditional_operator_successor-box_0': 'equals',
|
||||
'conditional_value_successor-box_0': 'ja',
|
||||
'conditional_field_successor-box_1': 'inherit_phone_number_choice',
|
||||
'conditional_operator_successor-box_1': 'not_equals',
|
||||
'conditional_value_successor-box_1': 'ja',
|
||||
},
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
rule = FormConditionalRuleConfig.objects.get(form_type='onboarding', target_key='phone-box')
|
||||
rule = FormConditionalRuleConfig.objects.get(form_type='onboarding', target_key='successor-box')
|
||||
self.assertEqual(rule.is_active, True)
|
||||
self.assertEqual(len(rule.clauses), 2)
|
||||
self.assertEqual(rule.clauses[0]['field'], 'successor_required_choice')
|
||||
@@ -258,3 +312,62 @@ class FormBuilderAdminTests(TestCase):
|
||||
custom_field.refresh_from_db()
|
||||
self.assertEqual(custom_field.section_key, 'itsetup')
|
||||
self.assertEqual(custom_field.sort_order, 2)
|
||||
|
||||
def test_staff_can_add_custom_section(self):
|
||||
self.client.force_login(self.staff)
|
||||
response = self.client.post(
|
||||
'/admin-tools/form-builder/?form_type=onboarding&option_category=device',
|
||||
data={
|
||||
'builder_action': 'add_custom_section',
|
||||
'custom_section_title': 'Benefits',
|
||||
'custom_section_title_en': 'Benefits',
|
||||
'custom_section_sort_order': '5',
|
||||
},
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
section = FormCustomSectionConfig.objects.get(form_type='onboarding', section_key='benefits')
|
||||
self.assertEqual(section.title, 'Benefits')
|
||||
self.assertEqual(section.sort_order, 5)
|
||||
|
||||
def test_save_order_accepts_custom_section_column(self):
|
||||
self.client.force_login(self.staff)
|
||||
FormCustomSectionConfig.objects.create(
|
||||
form_type='onboarding',
|
||||
section_key='benefits',
|
||||
sort_order=10,
|
||||
title='Benefits',
|
||||
is_active=True,
|
||||
)
|
||||
custom_field = FormCustomFieldConfig.objects.create(
|
||||
form_type='onboarding',
|
||||
field_key='meal_allowance',
|
||||
section_key='stammdaten',
|
||||
sort_order=99,
|
||||
field_type='text',
|
||||
label='Essenszuschuss',
|
||||
)
|
||||
self.client.get('/admin-tools/form-builder/?form_type=onboarding', HTTP_HOST='localhost')
|
||||
|
||||
payload = {
|
||||
'form_type': 'onboarding',
|
||||
'columns': {
|
||||
'stammdaten': ['department'],
|
||||
'vertrag': ['contract_start'],
|
||||
'itsetup': [],
|
||||
'abschluss': [],
|
||||
'benefits': ['custom__meal_allowance'],
|
||||
},
|
||||
}
|
||||
|
||||
response = self.client.post(
|
||||
'/admin-tools/form-builder/save-order/',
|
||||
data=json.dumps(payload),
|
||||
content_type='application/json',
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
custom_field.refresh_from_db()
|
||||
self.assertEqual(custom_field.section_key, 'benefits')
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
|
||||
from workflows.branding import get_company_email_domain
|
||||
from workflows.models import FormConditionalRuleConfig, FormCustomFieldConfig, FormFieldConfig, FormSectionConfig, OnboardingRequest
|
||||
from workflows.models import FormConditionalRuleConfig, FormCustomFieldConfig, FormCustomSectionConfig, FormFieldConfig, FormSectionConfig, OnboardingRequest
|
||||
|
||||
|
||||
class OnboardingFlowTests(TestCase):
|
||||
@@ -153,7 +153,7 @@ class OnboardingFlowTests(TestCase):
|
||||
self.assertIn('business-card-box', html)
|
||||
self.assertIn('employment-end-box', html)
|
||||
self.assertIn('data-conditional-target="business-card-box"', html)
|
||||
self.assertIn('data-conditional-target="phone-box"', html)
|
||||
self.assertNotIn('data-conditional-target="phone-box"', html)
|
||||
|
||||
def test_onboarding_page_uses_stored_conditional_rule_config(self):
|
||||
FormConditionalRuleConfig.objects.update_or_create(
|
||||
@@ -193,6 +193,39 @@ class OnboardingFlowTests(TestCase):
|
||||
|
||||
self.assertLess(html.index('Bürostandort'), html.index('Anrede'))
|
||||
|
||||
def test_phone_direct_dial_field_is_visible_without_successor(self):
|
||||
response = self.client.get('/onboarding/new/', HTTP_HOST='localhost')
|
||||
html = response.content.decode('utf-8')
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('Telefon-Direktwahl', html)
|
||||
self.assertNotIn('data-conditional-target="phone-box"', html)
|
||||
|
||||
def test_onboarding_custom_section_is_rendered_in_navigation(self):
|
||||
FormCustomSectionConfig.objects.create(
|
||||
form_type='onboarding',
|
||||
section_key='benefits',
|
||||
sort_order=10,
|
||||
title='Benefits',
|
||||
is_active=True,
|
||||
)
|
||||
FormCustomFieldConfig.objects.create(
|
||||
form_type='onboarding',
|
||||
field_key='meal_allowance',
|
||||
section_key='benefits',
|
||||
sort_order=0,
|
||||
field_type='text',
|
||||
is_active=True,
|
||||
label='Essenszuschuss',
|
||||
)
|
||||
|
||||
response = self.client.get('/onboarding/new/', HTTP_HOST='localhost')
|
||||
html = response.content.decode('utf-8')
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('Benefits', html)
|
||||
self.assertIn('Essenszuschuss', html)
|
||||
|
||||
@patch('workflows.views.process_onboarding_request.delay')
|
||||
def test_onboarding_custom_field_is_rendered_and_saved(self, mock_delay):
|
||||
FormCustomFieldConfig.objects.create(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from workflows.models import FormCustomFieldConfig, FormFieldConfig, FormSectionConfig, OffboardingRequest, OnboardingRequest
|
||||
from workflows.models import FormCustomFieldConfig, FormCustomSectionConfig, FormFieldConfig, FormSectionConfig, OffboardingRequest, OnboardingRequest
|
||||
from workflows.pdf_sections import build_pdf_sections
|
||||
|
||||
|
||||
@@ -123,3 +123,38 @@ class PDFSectionBuilderTests(TestCase):
|
||||
|
||||
self.assertEqual(custom_field['label'], 'Bürostandort')
|
||||
self.assertEqual(custom_field['display_value'], 'Berlin Mitte')
|
||||
|
||||
def test_custom_section_title_is_used_in_pdf_sections(self):
|
||||
FormCustomSectionConfig.objects.create(
|
||||
form_type='onboarding',
|
||||
section_key='benefits',
|
||||
sort_order=10,
|
||||
title='Benefits',
|
||||
is_active=True,
|
||||
)
|
||||
FormCustomFieldConfig.objects.create(
|
||||
form_type='onboarding',
|
||||
field_key='meal_allowance',
|
||||
section_key='benefits',
|
||||
sort_order=0,
|
||||
field_type='text',
|
||||
is_active=True,
|
||||
label='Essenszuschuss',
|
||||
)
|
||||
request_obj = OnboardingRequest.objects.create(
|
||||
full_name='Max Mustermann',
|
||||
gender='herr',
|
||||
job_title='Consultant',
|
||||
department='IT-Service',
|
||||
work_email='max.mustermann@workdock.de',
|
||||
contract_start='2026-11-01',
|
||||
employment_type='unbefristet',
|
||||
agreement='accepted',
|
||||
custom_field_values={'meal_allowance': 'Ja'},
|
||||
)
|
||||
|
||||
sections = build_pdf_sections('onboarding', request_obj, 'de')
|
||||
|
||||
custom_section = next(section for section in sections if section['key'] == 'benefits')
|
||||
self.assertEqual(custom_section['title'], 'Benefits')
|
||||
self.assertIn('custom__meal_allowance', [field['name'] for field in custom_section['fields']])
|
||||
|
||||
Reference in New Issue
Block a user