@@ -165,6 +165,14 @@ describe('updateStructuredContentById', () => {
165165 schema = null ;
166166 } ) ;
167167
168+ it ( 'throws error when updating ID with a non-integer value' , ( ) => {
169+ expect ( ( ) => {
170+ editor . commands . updateStructuredContentById ( INLINE_ID , {
171+ attrs : { id : 'abc-123' } ,
172+ } ) ;
173+ } ) . toThrow ( 'Invalid structured content id - must be an integer, got: abc-123' ) ;
174+ } ) ;
175+
168176 describe ( 'keepTextNodeStyles option' , ( ) => {
169177 it ( 'preserves marks from the first text node when keepTextNodeStyles is true' , ( ) => {
170178 const didUpdate = editor . commands . updateStructuredContentById ( INLINE_ID , {
@@ -407,6 +415,14 @@ describe('updateStructuredContentByGroup', () => {
407415 schema = null ;
408416 } ) ;
409417
418+ it ( 'throws error when updating ID with a non-integer value' , ( ) => {
419+ expect ( ( ) => {
420+ editor . commands . updateStructuredContentByGroup ( GROUP_NAME , {
421+ attrs : { id : 'abc-123' } ,
422+ } ) ;
423+ } ) . toThrow ( 'Invalid structured content id - must be an integer, got: abc-123' ) ;
424+ } ) ;
425+
410426 describe ( 'keepTextNodeStyles option' , ( ) => {
411427 it ( 'preserves marks from the first text node for all nodes in group when keepTextNodeStyles is true' , ( ) => {
412428 const didUpdate = editor . commands . updateStructuredContentByGroup ( GROUP_NAME , {
@@ -539,3 +555,126 @@ describe('updateStructuredContentByGroup', () => {
539555 } ) ;
540556 } ) ;
541557} ) ;
558+
559+ describe ( 'StructuredContent ID Validation' , ( ) => {
560+ let editor ;
561+
562+ beforeEach ( ( ) => {
563+ ( { editor } = initTestEditor ( { mode : 'text' , content : '<p></p>' } ) ) ;
564+ } ) ;
565+
566+ afterEach ( ( ) => {
567+ editor ?. destroy ( ) ;
568+ editor = null ;
569+ } ) ;
570+
571+ describe ( 'insertStructuredContentInline' , ( ) => {
572+ it ( 'accepts valid integer string IDs' , ( ) => {
573+ expect ( ( ) => {
574+ editor . commands . insertStructuredContentInline ( {
575+ attrs : { id : '123' } ,
576+ text : 'Test content' ,
577+ } ) ;
578+ } ) . not . toThrow ( ) ;
579+ } ) ;
580+
581+ it ( 'accepts valid negative integer string IDs' , ( ) => {
582+ expect ( ( ) => {
583+ editor . commands . insertStructuredContentInline ( {
584+ attrs : { id : '-456' } ,
585+ text : 'Test content' ,
586+ } ) ;
587+ } ) . not . toThrow ( ) ;
588+ } ) ;
589+
590+ it ( 'accepts numeric integer IDs' , ( ) => {
591+ expect ( ( ) => {
592+ editor . commands . insertStructuredContentInline ( {
593+ attrs : { id : 789 } ,
594+ text : 'Test content' ,
595+ } ) ;
596+ } ) . not . toThrow ( ) ;
597+ } ) ;
598+
599+ it ( 'auto-generates ID when not provided' , ( ) => {
600+ expect ( ( ) => {
601+ editor . commands . insertStructuredContentInline ( {
602+ text : 'Test content' ,
603+ } ) ;
604+ } ) . not . toThrow ( ) ;
605+ } ) ;
606+
607+ it ( 'throws error for non-integer string IDs' , ( ) => {
608+ expect ( ( ) => {
609+ editor . commands . insertStructuredContentInline ( {
610+ attrs : { id : 'abc-123' } ,
611+ text : 'Test content' ,
612+ } ) ;
613+ } ) . toThrow ( 'Invalid structured content id - must be an integer, got: abc-123' ) ;
614+ } ) ;
615+
616+ it ( 'throws error for float IDs' , ( ) => {
617+ expect ( ( ) => {
618+ editor . commands . insertStructuredContentInline ( {
619+ attrs : { id : '123.45' } ,
620+ text : 'Test content' ,
621+ } ) ;
622+ } ) . toThrow ( 'Invalid structured content id - must be an integer, got: 123.45' ) ;
623+ } ) ;
624+
625+ it ( 'throws error for UUID-style IDs' , ( ) => {
626+ expect ( ( ) => {
627+ editor . commands . insertStructuredContentInline ( {
628+ attrs : { id : 'a1b2c3d4-e5f6-7890-abcd-ef1234567890' } ,
629+ text : 'Test content' ,
630+ } ) ;
631+ } ) . toThrow ( 'Invalid structured content id - must be an integer, got: a1b2c3d4-e5f6-7890-abcd-ef1234567890' ) ;
632+ } ) ;
633+ } ) ;
634+
635+ describe ( 'insertStructuredContentBlock' , ( ) => {
636+ it ( 'accepts valid integer string IDs' , ( ) => {
637+ expect ( ( ) => {
638+ editor . commands . insertStructuredContentBlock ( {
639+ attrs : { id : '123' } ,
640+ html : '<p>Test content</p>' ,
641+ } ) ;
642+ } ) . not . toThrow ( ) ;
643+ } ) ;
644+
645+ it ( 'accepts valid negative integer string IDs' , ( ) => {
646+ expect ( ( ) => {
647+ editor . commands . insertStructuredContentBlock ( {
648+ attrs : { id : '-456' } ,
649+ html : '<p>Test content</p>' ,
650+ } ) ;
651+ } ) . not . toThrow ( ) ;
652+ } ) ;
653+
654+ it ( 'auto-generates ID when not provided' , ( ) => {
655+ expect ( ( ) => {
656+ editor . commands . insertStructuredContentBlock ( {
657+ html : '<p>Test content</p>' ,
658+ } ) ;
659+ } ) . not . toThrow ( ) ;
660+ } ) ;
661+
662+ it ( 'throws error for non-integer string IDs' , ( ) => {
663+ expect ( ( ) => {
664+ editor . commands . insertStructuredContentBlock ( {
665+ attrs : { id : 'my-block-id' } ,
666+ html : '<p>Test content</p>' ,
667+ } ) ;
668+ } ) . toThrow ( 'Invalid structured content id - must be an integer, got: my-block-id' ) ;
669+ } ) ;
670+
671+ it ( 'throws error for float IDs' , ( ) => {
672+ expect ( ( ) => {
673+ editor . commands . insertStructuredContentBlock ( {
674+ attrs : { id : '99.99' } ,
675+ html : '<p>Test content</p>' ,
676+ } ) ;
677+ } ) . toThrow ( 'Invalid structured content id - must be an integer, got: 99.99' ) ;
678+ } ) ;
679+ } ) ;
680+ } ) ;
0 commit comments