@@ -492,13 +492,18 @@ describe( 'Schema', () => {
492492 schema . registerItem ( 'p' , '$block' ) ;
493493 schema . registerItem ( 'h1' , '$block' ) ;
494494 schema . registerItem ( 'img' , '$inline' ) ;
495+ schema . registerItem ( 'figure' ) ;
495496
496497 // Bold text is allowed only in P.
497498 schema . allow ( { name : '$text' , attributes : 'bold' , inside : 'p' } ) ;
498499 schema . allow ( { name : 'p' , attributes : 'bold' , inside : '$root' } ) ;
499500
500501 // Disallow bold on image.
501502 schema . disallow ( { name : 'img' , attributes : 'bold' , inside : '$root' } ) ;
503+
504+ // Figure must have name attribute and optional title attribute.
505+ schema . requireAttributes ( 'figure' , [ 'name' ] ) ;
506+ schema . allow ( { name : 'figure' , attributes : [ 'title' , 'name' ] , inside : '$root' } ) ;
502507 } ) ;
503508
504509 describe ( 'when selection is collapsed' , ( ) => {
@@ -544,6 +549,16 @@ describe( 'Schema', () => {
544549 setData ( doc , '<p>foo[<img /><img />]bar</p>' ) ;
545550 expect ( schema . checkAttributeInSelection ( doc . selection , attribute ) ) . to . be . false ;
546551 } ) ;
552+
553+ it ( 'should return true when checking element with required attribute' , ( ) => {
554+ setData ( doc , '[<figure name="figure"></figure>]' ) ;
555+ expect ( schema . checkAttributeInSelection ( doc . selection , 'title' ) ) . to . be . true ;
556+ } ) ;
557+
558+ it ( 'should return true when checking element when attribute is already present' , ( ) => {
559+ setData ( doc , '[<figure name="figure" title="title"></figure>]' ) ;
560+ expect ( schema . checkAttributeInSelection ( doc . selection , 'title' ) ) . to . be . true ;
561+ } ) ;
547562 } ) ;
548563 } ) ;
549564
0 commit comments