snapshot: preserve custom field parity across forms timeline and pdf

This commit is contained in:
Md Bayazid Bostame
2026-03-27 13:21:25 +01:00
parent 2e5e941d41
commit fdc27f2123
20 changed files with 2294 additions and 545 deletions

View File

@@ -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, FormFieldConfig, FormSectionConfig, OnboardingRequest
from workflows.models import FormConditionalRuleConfig, FormCustomFieldConfig, FormFieldConfig, FormSectionConfig, OnboardingRequest
class OnboardingFlowTests(TestCase):
@@ -171,3 +171,168 @@ class OnboardingFlowTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertIn('employment-end-box', html)
self.assertIn('"value": "unbefristet"', html)
def test_onboarding_custom_field_uses_combined_order(self):
FormCustomFieldConfig.objects.create(
form_type='onboarding',
field_key='office_location',
section_key='stammdaten',
sort_order=1,
field_type='text',
is_active=True,
label='Bürostandort',
)
FormFieldConfig.objects.update_or_create(
form_type='onboarding',
field_name='gender',
defaults={'sort_order': 2, 'page_key': 'stammdaten'},
)
response = self.client.get('/onboarding/new/', HTTP_HOST='localhost')
html = response.content.decode('utf-8')
self.assertLess(html.index('Bürostandort'), html.index('Anrede'))
@patch('workflows.views.process_onboarding_request.delay')
def test_onboarding_custom_field_is_rendered_and_saved(self, mock_delay):
FormCustomFieldConfig.objects.create(
form_type='onboarding',
field_key='office_location',
section_key='stammdaten',
sort_order=0,
field_type='text',
is_active=True,
is_required=True,
label='Bürostandort',
)
response = self.client.get('/onboarding/new/', HTTP_HOST='localhost')
self.assertContains(response, 'Bürostandort')
payload = {
'first_name': 'Mara',
'last_name': 'Muster',
'gender': 'frau',
'job_title': 'Consultant',
'department': 'IT-Service',
'work_email': f'mara.muster@{self.company_domain}',
'contract_start': '2026-11-01',
'employment_type': 'unbefristet',
'group_mailboxes_required_choice': 'nein',
'additional_hardware_needed_choice': 'nein',
'additional_software_needed_choice': 'nein',
'additional_access_needed_choice': 'nein',
'successor_required_choice': 'nein',
'inherit_phone_number_choice': 'nein',
'custom__office_location': 'Berlin Mitte',
'agreement_confirm': 'on',
}
submit_response = self.client.post('/onboarding/new/', payload, HTTP_HOST='localhost')
self.assertEqual(submit_response.status_code, 302)
obj = OnboardingRequest.objects.get(work_email=f'mara.muster@{self.company_domain}')
self.assertEqual(obj.custom_field_values, {'office_location': 'Berlin Mitte'})
mock_delay.assert_called_once_with(obj.id)
@patch('workflows.views.process_onboarding_request.delay')
def test_hidden_required_custom_field_does_not_block_submission(self, mock_delay):
FormCustomFieldConfig.objects.create(
form_type='onboarding',
field_key='visitor_badge_name',
section_key='stammdaten',
sort_order=0,
field_type='text',
is_active=True,
is_required=True,
label='Besucherausweis',
)
FormConditionalRuleConfig.objects.update_or_create(
form_type='onboarding',
target_key='custom__visitor_badge_name',
defaults={
'is_active': True,
'clauses': [{'field': 'order_business_cards', 'operator': 'checked', 'value': True}],
},
)
response = self.client.get('/onboarding/new/', HTTP_HOST='localhost')
html = response.content.decode('utf-8')
self.assertIn('custom__visitor_badge_name', html)
self.assertIn('"custom__visitor_badge_name"', html)
payload = {
'first_name': 'Lea',
'last_name': 'Leicht',
'gender': 'frau',
'job_title': 'Consultant',
'department': 'IT-Service',
'work_email': f'lea.leicht@{self.company_domain}',
'contract_start': '2026-11-01',
'employment_type': 'unbefristet',
'group_mailboxes_required_choice': 'nein',
'additional_hardware_needed_choice': 'nein',
'additional_software_needed_choice': 'nein',
'additional_access_needed_choice': 'nein',
'successor_required_choice': 'nein',
'inherit_phone_number_choice': 'nein',
'agreement_confirm': 'on',
}
submit_response = self.client.post('/onboarding/new/', payload, HTTP_HOST='localhost')
self.assertEqual(submit_response.status_code, 302)
obj = OnboardingRequest.objects.get(work_email=f'lea.leicht@{self.company_domain}')
self.assertEqual(obj.custom_field_values, {'visitor_badge_name': ''})
mock_delay.assert_called_once_with(obj.id)
@patch('workflows.views.process_onboarding_request.delay')
def test_visible_required_custom_field_blocks_submission(self, mock_delay):
FormCustomFieldConfig.objects.create(
form_type='onboarding',
field_key='visitor_badge_name',
section_key='stammdaten',
sort_order=0,
field_type='text',
is_active=True,
is_required=True,
label='Besucherausweis',
)
FormConditionalRuleConfig.objects.update_or_create(
form_type='onboarding',
target_key='custom__visitor_badge_name',
defaults={
'is_active': True,
'clauses': [{'field': 'order_business_cards', 'operator': 'checked', 'value': True}],
},
)
payload = {
'first_name': 'Lia',
'last_name': 'Laut',
'gender': 'frau',
'job_title': 'Consultant',
'department': 'IT-Service',
'work_email': f'lia.laut@{self.company_domain}',
'contract_start': '2026-11-01',
'employment_type': 'unbefristet',
'order_business_cards': 'on',
'business_card_name': 'Lia Laut',
'business_card_title': 'Consultant',
'business_card_email': f'lia.laut@{self.company_domain}',
'business_card_phone': '030 123456',
'group_mailboxes_required_choice': 'nein',
'additional_hardware_needed_choice': 'nein',
'additional_software_needed_choice': 'nein',
'additional_access_needed_choice': 'nein',
'successor_required_choice': 'nein',
'inherit_phone_number_choice': 'nein',
'agreement_confirm': 'on',
}
response = self.client.post('/onboarding/new/', payload, HTTP_HOST='localhost')
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Besucherausweis')
self.assertFalse(OnboardingRequest.objects.filter(work_email=f'lia.laut@{self.company_domain}').exists())
mock_delay.assert_not_called()