1- import { addTags } from '../src/entry-editable'
1+ import { addTags , getTag } from '../src/entry-editable'
22import { entry_global_field , entry_global_field_multiple , entry_modular_block , entry_reference , entry_with_text , entry_with_applied_variants , entry_with_parent_path_variants } from './mock/entry-editable-mock'
33
44describe ( 'Entry editable test' , ( ) => {
@@ -588,6 +588,20 @@ describe('Entry editable test', () => {
588588 expect ( ( entryWithNestedNull as any ) [ '$' ] [ 'title' ] ) . toEqual ( 'data-cslp=content_type.entry_uid_nested_null.en-us.title' )
589589 done ( )
590590 } )
591+
592+ it ( 'getTag with null content returns empty object (covers null guard)' , done => {
593+ const appliedVariants = { _applied_variants : { } , shouldApplyVariant : false , metaKey : '' }
594+ const result = getTag ( null as any , 'some.prefix' , false , 'en-us' , appliedVariants )
595+ expect ( result ) . toEqual ( { } )
596+ done ( )
597+ } )
598+
599+ it ( 'getTag with undefined content returns empty object (covers null guard)' , done => {
600+ const appliedVariants = { _applied_variants : { } , shouldApplyVariant : false , metaKey : '' }
601+ const result = getTag ( undefined as any , 'some.prefix' , true , 'en-us' , appliedVariants )
602+ expect ( result ) . toEqual ( { } )
603+ done ( )
604+ } )
591605 } )
592606
593607 describe ( 'useLowerCaseLocale option' , ( ) => {
@@ -631,4 +645,73 @@ describe('Entry editable test', () => {
631645 } )
632646 } )
633647
648+ describe ( 'Negative and corner cases' , ( ) => {
649+ it ( 'addTags with empty entry object should not throw and should set $ with empty-like tags' , done => {
650+ const emptyEntry = { uid : 'e1' , locale : 'en-us' }
651+ expect ( ( ) => addTags ( emptyEntry , 'ct' , false ) ) . not . toThrow ( )
652+ expect ( ( emptyEntry as any ) . $ ) . toBeDefined ( )
653+ expect ( typeof ( emptyEntry as any ) . $ ) . toBe ( 'object' )
654+ done ( )
655+ } )
656+
657+ it ( 'addTags with empty string contentTypeUid should normalize to lowercase' , done => {
658+ const entry = { uid : 'u1' , locale : 'en-us' , title : 't' }
659+ addTags ( entry , '' , false )
660+ expect ( ( entry as any ) [ '$' ] [ 'title' ] ) . toContain ( '.title' )
661+ done ( )
662+ } )
663+
664+ it ( 'addTags with options as undefined should not throw' , done => {
665+ const entry = { uid : 'u1' , locale : 'en-us' , title : 't' }
666+ expect ( ( ) => addTags ( entry , 'ct' , false , 'en-us' , undefined ) ) . not . toThrow ( )
667+ expect ( ( entry as any ) [ '$' ] [ 'title' ] ) . toBeDefined ( )
668+ done ( )
669+ } )
670+
671+ it ( 'getTag with empty object content should return empty tags object' , done => {
672+ const appliedVariants = { _applied_variants : { } , shouldApplyVariant : false , metaKey : '' }
673+ const result = getTag ( { } , 'prefix' , false , 'en-us' , appliedVariants )
674+ expect ( result ) . toEqual ( { } )
675+ done ( )
676+ } )
677+
678+ it ( 'getTag with content that has only $ key should skip $ and return empty' , done => {
679+ const appliedVariants = { _applied_variants : { } , shouldApplyVariant : false , metaKey : '' }
680+ const result = getTag ( { $ : 'ignored' } , 'prefix' , false , 'en-us' , appliedVariants )
681+ expect ( result ) . toEqual ( { } )
682+ done ( )
683+ } )
684+
685+ it ( 'getTag with appliedVariants._applied_variants null should not throw (getParentVariantisedPath safety)' , done => {
686+ const content = { field : 'value' }
687+ const appliedVariants = { _applied_variants : null as any , shouldApplyVariant : true , metaKey : 'field' }
688+ expect ( ( ) => getTag ( content , 'prefix' , false , 'en-us' , appliedVariants ) ) . not . toThrow ( )
689+ const result = getTag ( content , 'prefix' , false , 'en-us' , appliedVariants )
690+ expect ( result ) . toHaveProperty ( 'field' )
691+ done ( )
692+ } )
693+
694+ it ( 'getTag with appliedVariants.metaKey empty and shouldApplyVariant true should still produce tags' , done => {
695+ const content = { title : 'hello' }
696+ const appliedVariants = { _applied_variants : { } , shouldApplyVariant : true , metaKey : '' }
697+ const result = getTag ( content , 'ct.uid.en-us' , false , 'en-us' , appliedVariants )
698+ expect ( result ) . toHaveProperty ( 'title' )
699+ expect ( ( result as any ) . title ) . toContain ( 'title' )
700+ done ( )
701+ } )
702+
703+ it ( 'addTags with entry that has empty array field should not throw' , done => {
704+ const entry : any = { uid : 'u1' , locale : 'en-us' , items : [ ] }
705+ expect ( ( ) => addTags ( entry , 'ct' , false ) ) . not . toThrow ( )
706+ expect ( ( entry as any ) [ '$' ] [ 'items' ] ) . toBeDefined ( )
707+ done ( )
708+ } )
709+
710+ it ( 'addTags with entry that has nested null object value should not throw' , done => {
711+ const entry : any = { uid : 'u1' , locale : 'en-us' , title : 't' , nested : null }
712+ expect ( ( ) => addTags ( entry , 'ct' , true ) ) . not . toThrow ( )
713+ expect ( ( entry as any ) [ '$' ] [ 'title' ] ) . toEqual ( { 'data-cslp' : expect . stringContaining ( 'title' ) } )
714+ done ( )
715+ } )
716+ } )
634717} )
0 commit comments