Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach( () => {
document = new Document();
document.createRoot();
document.schema.registerItem( 'p', '$block' );
document.schema.registerItem( 'h1', '$block' );
document.schema.registerItem( 'img', '$inline' );
// Bold text is allowed only in P.
document.schema.allow( { name: '$text', attributes: 'bold', inside: 'p' } );
document.schema.allow( { name: 'p', attributes: 'bold', inside: '$root' } );
// Disallow bold on image.
document.schema.disallow( { name: 'img', attributes: 'bold', inside: '$root' } );
} );
beforeEach( () => {
editor = new Editor();
editor.document = new Document();
modelDoc = editor.document;
root = modelDoc.createRoot();
command = new ToggleAttributeCommand( editor, attrKey );
modelDoc.schema.registerItem( 'p', '$block' );
modelDoc.schema.registerItem( 'h1', '$block' );
modelDoc.schema.registerItem( 'img', '$inline' );
// Allow block in "root" (DIV)
modelDoc.schema.allow( { name: '$block', inside: '$root' } );
// Bold text is allowed only in P.
modelDoc.schema.allow( { name: '$text', attributes: 'bold', inside: 'p' } );
modelDoc.schema.allow( { name: 'p', attributes: 'bold', inside: '$root' } );
it( 'should use provided batch for storing undo steps', () => {
const batch = new Batch( new Document() );
setData( modelDoc, '<p>a[bc<$text bold="true">fo]obarxyz</p>' );
expect( batch.deltas.length ).to.equal( 0 );
command.execute( { batch } );
expect( batch.deltas.length ).to.equal( 1 );
expect( getData( modelDoc ) ).to.equal( '<p>a[<$text bold="true">bcfo]obarxyz</p>' );
} );
beforeEach( () => {
document = new Document();
schema = document.schema;
root = document.createRoot();
schema.registerItem( 'p', '$block' );
schema.registerItem( 'h1', '$block' );
schema.registerItem( 'img', '$inline' );
schema.allow( { name: '$text', attributes: 'bold', inside: 'p' } );
schema.allow( { name: 'p', attributes: 'bold', inside: '$root' } );
setData( document, '<p>foo<img>bar</p>' );
ranges = [ Range.createOn( root.getChild( 0 ) ) ];
} );