@@ -436,4 +436,197 @@ describe('ProfileForm', () => {
436436 // Should render as a text field since no field definition exists
437437 expect ( getByTestId ( 'edit_profile_form.customAttributes.unknownField' ) ) . toBeTruthy ( ) ;
438438 } ) ;
439+
440+ describe ( 'SAML Field Disabling' , ( ) => {
441+ it ( 'should disable custom fields when SAML-linked' , ( ) => {
442+ const customFields = [
443+ TestHelper . fakeCustomProfileFieldModel ( {
444+ id : 'saml-field' ,
445+ name : 'SAML Field' ,
446+ type : 'text' ,
447+ attrs : {
448+ saml : 'Department' , // SAML-linked
449+ } ,
450+ } ) ,
451+ TestHelper . fakeCustomProfileFieldModel ( {
452+ id : 'normal-field' ,
453+ name : 'Normal Field' ,
454+ type : 'text' ,
455+ attrs : {
456+ saml : '' , // Not SAML-linked
457+ } ,
458+ } ) ,
459+ ] ;
460+
461+ const props = {
462+ ...baseProps ,
463+ enableCustomAttributes : true ,
464+ customFields,
465+ userInfo : {
466+ ...baseProps . userInfo ,
467+ customAttributes : {
468+ 'saml-field' : {
469+ id : 'saml-field' ,
470+ name : 'SAML Field' ,
471+ type : 'text' ,
472+ value : 'Engineering' ,
473+ } ,
474+ 'normal-field' : {
475+ id : 'normal-field' ,
476+ name : 'Normal Field' ,
477+ type : 'text' ,
478+ value : 'Mobile Team' ,
479+ } ,
480+ } ,
481+ } ,
482+ } ;
483+
484+ const { getByTestId} = renderWithIntl (
485+ < ProfileForm { ...props } /> ,
486+ ) ;
487+
488+ const samlField = getByTestId ( 'edit_profile_form.customAttributes.saml-field.input.disabled' ) ;
489+ const normalField = getByTestId ( 'edit_profile_form.customAttributes.normal-field.input' ) ;
490+
491+ // SAML field should be disabled
492+ expect ( samlField . props . editable ) . toBe ( false ) ;
493+
494+ // Normal field should be enabled
495+ expect ( normalField . props . editable ) . toBe ( true ) ;
496+ } ) ;
497+
498+ it ( 'should enable custom fields when SAML attribute is empty' , ( ) => {
499+ const customFields = [
500+ TestHelper . fakeCustomProfileFieldModel ( {
501+ id : 'normal-field' ,
502+ name : 'Normal Field' ,
503+ type : 'text' ,
504+ attrs : {
505+ saml : '' , // Empty SAML attribute
506+ } ,
507+ } ) ,
508+ ] ;
509+
510+ const props = {
511+ ...baseProps ,
512+ enableCustomAttributes : true ,
513+ customFields,
514+ userInfo : {
515+ ...baseProps . userInfo ,
516+ customAttributes : {
517+ 'normal-field' : {
518+ id : 'normal-field' ,
519+ name : 'Normal Field' ,
520+ type : 'text' ,
521+ value : 'Some value' ,
522+ } ,
523+ } ,
524+ } ,
525+ } ;
526+
527+ const { getByTestId} = renderWithIntl (
528+ < ProfileForm { ...props } /> ,
529+ ) ;
530+
531+ const normalField = getByTestId ( 'edit_profile_form.customAttributes.normal-field.input' ) ;
532+ expect ( normalField . props . editable ) . toBe ( true ) ;
533+ } ) ;
534+
535+ it ( 'should enable custom fields when SAML attribute is missing' , ( ) => {
536+ const customFields = [
537+ TestHelper . fakeCustomProfileFieldModel ( {
538+ id : 'normal-field' ,
539+ name : 'Normal Field' ,
540+ type : 'text' ,
541+ attrs : {
542+
543+ // No saml attribute at all
544+ } ,
545+ } ) ,
546+ ] ;
547+
548+ const props = {
549+ ...baseProps ,
550+ enableCustomAttributes : true ,
551+ customFields,
552+ userInfo : {
553+ ...baseProps . userInfo ,
554+ customAttributes : {
555+ 'normal-field' : {
556+ id : 'normal-field' ,
557+ name : 'Normal Field' ,
558+ type : 'text' ,
559+ value : 'Some value' ,
560+ } ,
561+ } ,
562+ } ,
563+ } ;
564+
565+ const { getByTestId} = renderWithIntl (
566+ < ProfileForm { ...props } /> ,
567+ ) ;
568+
569+ const normalField = getByTestId ( 'edit_profile_form.customAttributes.normal-field.input' ) ;
570+ expect ( normalField . props . editable ) . toBe ( true ) ;
571+ } ) ;
572+
573+ it ( 'should handle custom fields without field definitions (defaults to enabled)' , ( ) => {
574+ const props = {
575+ ...baseProps ,
576+ enableCustomAttributes : true ,
577+ customFields : [ ] , // No field definitions
578+ userInfo : {
579+ ...baseProps . userInfo ,
580+ customAttributes : {
581+ 'unknown-field' : {
582+ id : 'unknown-field' ,
583+ name : 'Unknown Field' ,
584+ type : 'text' ,
585+ value : 'Some value' ,
586+ } ,
587+ } ,
588+ } ,
589+ } ;
590+
591+ const { getByTestId} = renderWithIntl (
592+ < ProfileForm { ...props } /> ,
593+ ) ;
594+
595+ const unknownField = getByTestId ( 'edit_profile_form.customAttributes.unknown-field.input' ) ;
596+
597+ // Should default to enabled when no field definition exists
598+ expect ( unknownField . props . editable ) . toBe ( true ) ;
599+ } ) ;
600+
601+ it ( 'should disable standard profile fields when SAML/LDAP locked' , ( ) => {
602+ const props = {
603+ ...baseProps ,
604+ currentUser : TestHelper . fakeUserModel ( {
605+ ...baseProps . currentUser ,
606+ authService : 'saml' ,
607+ } ) ,
608+ lockedFirstName : true ,
609+ lockedLastName : false ,
610+ lockedNickname : true ,
611+ lockedPosition : false ,
612+ } ;
613+
614+ const { getByTestId} = renderWithIntl (
615+ < ProfileForm { ...props } /> ,
616+ ) ;
617+
618+ const firstNameField = getByTestId ( 'edit_profile_form.firstName.input.disabled' ) ;
619+ const lastNameField = getByTestId ( 'edit_profile_form.lastName.input' ) ;
620+ const nicknameField = getByTestId ( 'edit_profile_form.nickname.input.disabled' ) ;
621+ const positionField = getByTestId ( 'edit_profile_form.position.input' ) ;
622+
623+ // Locked fields should be disabled
624+ expect ( firstNameField . props . editable ) . toBe ( false ) ;
625+ expect ( nicknameField . props . editable ) . toBe ( false ) ;
626+
627+ // Unlocked fields should be enabled
628+ expect ( lastNameField . props . editable ) . toBe ( true ) ;
629+ expect ( positionField . props . editable ) . toBe ( true ) ;
630+ } ) ;
631+ } ) ;
439632} ) ;
0 commit comments