@@ -519,6 +519,77 @@ describe('Entry editable test', () => {
519519 } )
520520 } )
521521
522+ describe ( 'Null and undefined content handling (Issue #193)' , ( ) => {
523+ it ( 'should not throw when entry has a null field value' , done => {
524+ const entryWithNullField : any = {
525+ "uid" : "entry_uid_null" ,
526+ "locale" : "en-us" ,
527+ "title" : "Valid title" ,
528+ "description" : null
529+ }
530+
531+ expect ( ( ) => addTags ( entryWithNullField , 'content_type' , false ) ) . not . toThrow ( )
532+ expect ( ( entryWithNullField as any ) [ '$' ] [ 'title' ] ) . toEqual ( 'data-cslp=content_type.entry_uid_null.en-us.title' )
533+ done ( )
534+ } )
535+
536+ it ( 'should not throw when entry has an undefined field value' , done => {
537+ const entryWithUndefinedField : any = {
538+ "uid" : "entry_uid_undef" ,
539+ "locale" : "en-us" ,
540+ "title" : "Valid title" ,
541+ "description" : undefined
542+ }
543+
544+ expect ( ( ) => addTags ( entryWithUndefinedField , 'content_type' , false ) ) . not . toThrow ( )
545+ expect ( ( entryWithUndefinedField as any ) [ '$' ] [ 'title' ] ) . toEqual ( 'data-cslp=content_type.entry_uid_undef.en-us.title' )
546+ done ( )
547+ } )
548+
549+ it ( 'should return empty tags for a null entry' , done => {
550+ const nullEntry : any = null
551+
552+ expect ( ( ) => addTags ( nullEntry , 'content_type' , false ) ) . not . toThrow ( )
553+ done ( )
554+ } )
555+
556+ it ( 'should return empty tags for an undefined entry' , done => {
557+ const undefinedEntry : any = undefined
558+
559+ expect ( ( ) => addTags ( undefinedEntry , 'content_type' , false ) ) . not . toThrow ( )
560+ done ( )
561+ } )
562+
563+ it ( 'should handle entry with multiple null field values' , done => {
564+ const entryWithMultipleNulls : any = {
565+ "uid" : "entry_uid_multi_null" ,
566+ "locale" : "en-us" ,
567+ "title" : "Valid title" ,
568+ "field_a" : null ,
569+ "field_b" : null ,
570+ "field_c" : "valid"
571+ }
572+
573+ expect ( ( ) => addTags ( entryWithMultipleNulls , 'content_type' , true ) ) . not . toThrow ( )
574+ expect ( ( entryWithMultipleNulls as any ) [ '$' ] [ 'title' ] ) . toEqual ( { 'data-cslp' : 'content_type.entry_uid_multi_null.en-us.title' } )
575+ expect ( ( entryWithMultipleNulls as any ) [ '$' ] [ 'field_c' ] ) . toEqual ( { 'data-cslp' : 'content_type.entry_uid_multi_null.en-us.field_c' } )
576+ done ( )
577+ } )
578+
579+ it ( 'should handle entry with nested null object' , done => {
580+ const entryWithNestedNull : any = {
581+ "uid" : "entry_uid_nested_null" ,
582+ "locale" : "en-us" ,
583+ "title" : "Valid title" ,
584+ "group" : null
585+ }
586+
587+ expect ( ( ) => addTags ( entryWithNestedNull , 'content_type' , false ) ) . not . toThrow ( )
588+ expect ( ( entryWithNestedNull as any ) [ '$' ] [ 'title' ] ) . toEqual ( 'data-cslp=content_type.entry_uid_nested_null.en-us.title' )
589+ done ( )
590+ } )
591+ } )
592+
522593 describe ( 'useLowerCaseLocale option' , ( ) => {
523594 it ( 'should preserve locale casing when useLowerCaseLocale is false' , done => {
524595 const entry = {
0 commit comments