|
@@ -1,5 +1,5 @@
|
|
|
/**
|
|
/**
|
|
|
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
|
|
|
|
|
|
|
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
|
|
|
* For licensing, see LICENSE.md.
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
@@ -10,46 +10,46 @@ import Range from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
|
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
|
|
const options = [
|
|
const options = [
|
|
|
- { modelElement: 'heading1', viewElement: 'h2', title: 'H2' },
|
|
|
|
|
- { modelElement: 'heading2', viewElement: 'h3', title: 'H3' },
|
|
|
|
|
- { modelElement: 'heading3', viewElement: 'h4', title: 'H4' }
|
|
|
|
|
|
|
+ { model: 'heading1', view: { name: 'h2' }, title: 'H2' },
|
|
|
|
|
+ { model: 'heading2', view: { name: 'h3' }, title: 'H3' },
|
|
|
|
|
+ { model: 'heading3', view: { name: 'h4' }, title: 'H4' }
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
describe( 'HeadingCommand', () => {
|
|
describe( 'HeadingCommand', () => {
|
|
|
- let editor, document, commands, root, schema;
|
|
|
|
|
|
|
+ let editor, model, document, command, root, schema;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
return ModelTestEditor.create().then( newEditor => {
|
|
return ModelTestEditor.create().then( newEditor => {
|
|
|
editor = newEditor;
|
|
editor = newEditor;
|
|
|
- document = editor.document;
|
|
|
|
|
- commands = {};
|
|
|
|
|
- schema = document.schema;
|
|
|
|
|
|
|
+ model = editor.model;
|
|
|
|
|
+ document = model.document;
|
|
|
|
|
+ schema = model.schema;
|
|
|
|
|
|
|
|
editor.commands.add( 'paragraph', new ParagraphCommand( editor ) );
|
|
editor.commands.add( 'paragraph', new ParagraphCommand( editor ) );
|
|
|
- schema.registerItem( 'paragraph', '$block' );
|
|
|
|
|
|
|
+ schema.register( 'paragraph', { inheritAllFrom: '$block' } );
|
|
|
|
|
+
|
|
|
|
|
+ const modelElements = [];
|
|
|
|
|
|
|
|
for ( const option of options ) {
|
|
for ( const option of options ) {
|
|
|
- commands[ option.modelElement ] = new HeadingCommand( editor, option.modelElement );
|
|
|
|
|
- schema.registerItem( option.modelElement, '$block' );
|
|
|
|
|
|
|
+ modelElements.push( option.model );
|
|
|
|
|
+ schema.register( option.model, { inheritAllFrom: '$block' } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- schema.registerItem( 'notBlock' );
|
|
|
|
|
- schema.allow( { name: 'notBlock', inside: '$root' } );
|
|
|
|
|
- schema.allow( { name: '$text', inside: 'notBlock' } );
|
|
|
|
|
|
|
+ command = new HeadingCommand( editor, modelElements );
|
|
|
|
|
+ editor.commands.add( 'heading', command );
|
|
|
|
|
+ schema.register( 'heading', { inheritAllFrom: '$block' } );
|
|
|
|
|
+
|
|
|
|
|
+ schema.register( 'notBlock' );
|
|
|
|
|
+ schema.extend( 'notBlock', { allowIn: '$root' } );
|
|
|
|
|
+ schema.extend( '$text', { allowIn: 'notBlock' } );
|
|
|
|
|
|
|
|
root = document.getRoot();
|
|
root = document.getRoot();
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- afterEach( () => {
|
|
|
|
|
- for ( const modelElement in commands ) {
|
|
|
|
|
- commands[ modelElement ].destroy();
|
|
|
|
|
- }
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- describe( 'modelElement', () => {
|
|
|
|
|
|
|
+ describe( 'modelElements', () => {
|
|
|
it( 'is set', () => {
|
|
it( 'is set', () => {
|
|
|
- expect( commands.heading1.modelElement ).to.equal( 'heading1' );
|
|
|
|
|
|
|
+ expect( command.modelElements ).to.deep.equal( [ 'heading1', 'heading2', 'heading3' ] );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -58,98 +58,138 @@ describe( 'HeadingCommand', () => {
|
|
|
test( option );
|
|
test( option );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function test( { modelElement } ) {
|
|
|
|
|
|
|
+ function test( { model: modelElement } ) {
|
|
|
it( `equals ${ modelElement } when collapsed selection is placed inside ${ modelElement } element`, () => {
|
|
it( `equals ${ modelElement } when collapsed selection is placed inside ${ modelElement } element`, () => {
|
|
|
- setData( document, `<${ modelElement }>foobar</${ modelElement }>` );
|
|
|
|
|
|
|
+ setData( model, `<${ modelElement }>foobar</${ modelElement }>` );
|
|
|
const element = root.getChild( 0 );
|
|
const element = root.getChild( 0 );
|
|
|
- document.selection.addRange( Range.createFromParentsAndOffsets( element, 3, element, 3 ) );
|
|
|
|
|
-
|
|
|
|
|
- expect( commands[ modelElement ].value ).to.be.true;
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ const ranges = [
|
|
|
|
|
+ ...model.document.selection.getRanges(),
|
|
|
|
|
+ Range.createFromParentsAndOffsets( element, 3, element, 3 )
|
|
|
|
|
+ ];
|
|
|
|
|
+ writer.setSelection( ranges );
|
|
|
|
|
+ } );
|
|
|
|
|
+ expect( command.value ).to.equal( modelElement );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'equals false if inside to non-block element', () => {
|
|
it( 'equals false if inside to non-block element', () => {
|
|
|
- setData( document, '<notBlock>[foo]</notBlock>' );
|
|
|
|
|
|
|
+ setData( model, '<notBlock>[foo]</notBlock>' );
|
|
|
|
|
|
|
|
- expect( commands[ modelElement ].value ).to.be.false;
|
|
|
|
|
|
|
+ expect( command.value ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( `equals false if moved from ${ modelElement } to non-block element`, () => {
|
|
it( `equals false if moved from ${ modelElement } to non-block element`, () => {
|
|
|
- setData( document, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
|
|
|
|
|
|
|
+ setData( model, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
|
|
|
const element = document.getRoot().getChild( 1 );
|
|
const element = document.getRoot().getChild( 1 );
|
|
|
|
|
|
|
|
- document.enqueueChanges( () => {
|
|
|
|
|
- document.selection.setRanges( [ Range.createIn( element ) ] );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( Range.createIn( element ) );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( commands[ modelElement ].value ).to.be.false;
|
|
|
|
|
|
|
+ expect( command.value ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be refreshed after calling refresh()', () => {
|
|
it( 'should be refreshed after calling refresh()', () => {
|
|
|
- const command = commands[ modelElement ];
|
|
|
|
|
- setData( document, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
|
|
|
|
|
|
|
+ setData( model, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
|
|
|
const element = document.getRoot().getChild( 1 );
|
|
const element = document.getRoot().getChild( 1 );
|
|
|
|
|
|
|
|
- // Purposely not putting it in `document.enqueueChanges` to update command manually.
|
|
|
|
|
- document.selection.setRanges( [ Range.createIn( element ) ] );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( Range.createIn( element ) );
|
|
|
|
|
|
|
|
- expect( command.value ).to.be.true;
|
|
|
|
|
- command.refresh();
|
|
|
|
|
- expect( command.value ).to.be.false;
|
|
|
|
|
|
|
+ expect( command.value ).to.equal( modelElement );
|
|
|
|
|
+ command.refresh();
|
|
|
|
|
+ expect( command.value ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'execute()', () => {
|
|
describe( 'execute()', () => {
|
|
|
it( 'should update value after execution', () => {
|
|
it( 'should update value after execution', () => {
|
|
|
- const command = commands.heading1;
|
|
|
|
|
-
|
|
|
|
|
- setData( document, '<paragraph>[]</paragraph>' );
|
|
|
|
|
- command.execute();
|
|
|
|
|
|
|
+ setData( model, '<paragraph>[]</paragraph>' );
|
|
|
|
|
+ command.execute( { value: 'heading1' } );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
|
|
- expect( command.value ).to.be.true;
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
|
|
+ expect( command.value ).to.equal( 'heading1' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5-heading/issues/73
|
|
// https://github.com/ckeditor/ckeditor5-heading/issues/73
|
|
|
- it( 'should not rename blocks which cannot become headings', () => {
|
|
|
|
|
- document.schema.registerItem( 'restricted' );
|
|
|
|
|
- document.schema.allow( { name: 'restricted', inside: '$root' } );
|
|
|
|
|
- document.schema.disallow( { name: 'heading1', inside: 'restricted' } );
|
|
|
|
|
|
|
+ it( 'should not rename blocks which cannot become headings (heading is not allowed in their parent)', () => {
|
|
|
|
|
+ schema.register( 'restricted' );
|
|
|
|
|
+ schema.extend( 'restricted', { allowIn: '$root' } );
|
|
|
|
|
|
|
|
- document.schema.registerItem( 'fooBlock', '$block' );
|
|
|
|
|
- document.schema.allow( { name: 'fooBlock', inside: 'restricted' } );
|
|
|
|
|
|
|
+ schema.register( 'fooBlock', { inheritAllFrom: '$block' } );
|
|
|
|
|
+ schema.extend( 'fooBlock', {
|
|
|
|
|
+ allowIn: [ 'restricted', '$root' ]
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
setData(
|
|
setData(
|
|
|
- document,
|
|
|
|
|
|
|
+ model,
|
|
|
'<paragraph>a[bc</paragraph>' +
|
|
'<paragraph>a[bc</paragraph>' +
|
|
|
'<restricted><fooBlock></fooBlock></restricted>' +
|
|
'<restricted><fooBlock></fooBlock></restricted>' +
|
|
|
- '<paragraph>de]f</paragraph>'
|
|
|
|
|
|
|
+ '<fooBlock>de]f</fooBlock>'
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- commands.heading1.execute();
|
|
|
|
|
|
|
+ command.execute( { value: 'heading1' } );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal(
|
|
|
'<heading1>a[bc</heading1>' +
|
|
'<heading1>a[bc</heading1>' +
|
|
|
'<restricted><fooBlock></fooBlock></restricted>' +
|
|
'<restricted><fooBlock></fooBlock></restricted>' +
|
|
|
'<heading1>de]f</heading1>'
|
|
'<heading1>de]f</heading1>'
|
|
|
);
|
|
);
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'custom options', () => {
|
|
|
|
|
- it( 'should use provided batch', () => {
|
|
|
|
|
- const batch = editor.document.batch();
|
|
|
|
|
- const command = commands.heading1;
|
|
|
|
|
|
|
+ it( 'should not rename blocks which cannot become headings (block is an object)', () => {
|
|
|
|
|
+ schema.register( 'image', {
|
|
|
|
|
+ isBlock: true,
|
|
|
|
|
+ isObject: true,
|
|
|
|
|
+ allowIn: '$root'
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- setData( document, '<paragraph>foo[]bar</paragraph>' );
|
|
|
|
|
|
|
+ setData(
|
|
|
|
|
+ model,
|
|
|
|
|
+ '<paragraph>a[bc</paragraph>' +
|
|
|
|
|
+ '<image></image>' +
|
|
|
|
|
+ '<paragraph>de]f</paragraph>'
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- expect( batch.deltas.length ).to.equal( 0 );
|
|
|
|
|
|
|
+ command.execute( { value: 'heading1' } );
|
|
|
|
|
|
|
|
- command.execute( { batch } );
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal(
|
|
|
|
|
+ '<heading1>a[bc</heading1>' +
|
|
|
|
|
+ '<image></image>' +
|
|
|
|
|
+ '<heading1>de]f</heading1>'
|
|
|
|
|
+ );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- expect( batch.deltas.length ).to.be.above( 0 );
|
|
|
|
|
|
|
+ it( 'should use parent batch', () => {
|
|
|
|
|
+ setData( model, '<paragraph>foo[]bar</paragraph>' );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ expect( writer.batch.deltas.length ).to.equal( 0 );
|
|
|
|
|
+
|
|
|
|
|
+ command.execute( { value: 'heading1' } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( writer.batch.deltas.length ).to.be.above( 0 );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should do nothing on non-registered model elements', () => {
|
|
|
|
|
+ setData( model, '<heading1>[]</heading1>' );
|
|
|
|
|
+ command.execute( { value: 'paragraph' } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
|
|
+ expect( command.value ).to.equal( 'heading1' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should do nothing when empty value is passed', () => {
|
|
|
|
|
+ setData( model, '<heading1>[]</heading1>' );
|
|
|
|
|
+ command.execute();
|
|
|
|
|
+
|
|
|
|
|
+ expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
|
|
+ expect( command.value ).to.equal( 'heading1' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
describe( 'collapsed selection', () => {
|
|
describe( 'collapsed selection', () => {
|
|
|
let convertTo = options[ options.length - 1 ];
|
|
let convertTo = options[ options.length - 1 ];
|
|
|
|
|
|
|
@@ -159,28 +199,28 @@ describe( 'HeadingCommand', () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
it( 'does nothing when executed with already applied option', () => {
|
|
it( 'does nothing when executed with already applied option', () => {
|
|
|
- setData( document, '<heading1>foo[]bar</heading1>' );
|
|
|
|
|
|
|
+ setData( model, '<heading1>foo[]bar</heading1>' );
|
|
|
|
|
|
|
|
- commands.heading1.execute();
|
|
|
|
|
- expect( getData( document ) ).to.equal( '<heading1>foo[]bar</heading1>' );
|
|
|
|
|
|
|
+ command.execute( { value: 'heading1' } );
|
|
|
|
|
+ expect( getData( model ) ).to.equal( '<heading1>foo[]bar</heading1>' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'converts topmost blocks', () => {
|
|
it( 'converts topmost blocks', () => {
|
|
|
- schema.registerItem( 'inlineImage', '$inline' );
|
|
|
|
|
- schema.allow( { name: '$text', inside: 'inlineImage' } );
|
|
|
|
|
|
|
+ schema.register( 'inlineImage', { allowWhere: '$text' } );
|
|
|
|
|
+ schema.extend( '$text', { allowIn: 'inlineImage' } );
|
|
|
|
|
|
|
|
- setData( document, '<paragraph><inlineImage>foo[]</inlineImage>bar</paragraph>' );
|
|
|
|
|
- commands.heading1.execute();
|
|
|
|
|
|
|
+ setData( model, '<paragraph><inlineImage>foo[]</inlineImage>bar</paragraph>' );
|
|
|
|
|
+ command.execute( { value: 'heading1' } );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( '<heading1><inlineImage>foo[]</inlineImage>bar</heading1>' );
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal( '<heading1><inlineImage>foo[]</inlineImage>bar</heading1>' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
function test( from, to ) {
|
|
function test( from, to ) {
|
|
|
- it( `converts ${ from.modelElement } to ${ to.modelElement } on collapsed selection`, () => {
|
|
|
|
|
- setData( document, `<${ from.modelElement }>foo[]bar</${ from.modelElement }>` );
|
|
|
|
|
- commands[ to.modelElement ].execute();
|
|
|
|
|
|
|
+ it( `converts ${ from.model } to ${ to.model } on collapsed selection`, () => {
|
|
|
|
|
+ setData( model, `<${ from.model }>foo[]bar</${ from.model }>` );
|
|
|
|
|
+ command.execute( { value: to.model } );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( `<${ to.modelElement }>foo[]bar</${ to.modelElement }>` );
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal( `<${ to.model }>foo[]bar</${ to.model }>` );
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
@@ -194,43 +234,43 @@ describe( 'HeadingCommand', () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
it( 'converts all elements where selection is applied', () => {
|
|
it( 'converts all elements where selection is applied', () => {
|
|
|
- setData( document, '<heading1>foo[</heading1><heading2>bar</heading2><heading3>baz]</heading3>' );
|
|
|
|
|
|
|
+ setData( model, '<heading1>foo[</heading1><heading2>bar</heading2><heading3>baz]</heading3>' );
|
|
|
|
|
|
|
|
- commands.heading3.execute();
|
|
|
|
|
|
|
+ command.execute( { value: 'heading3' } );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal(
|
|
|
'<heading3>foo[</heading3><heading3>bar</heading3><heading3>baz]</heading3>'
|
|
'<heading3>foo[</heading3><heading3>bar</heading3><heading3>baz]</heading3>'
|
|
|
);
|
|
);
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'does nothing to the elements with same option (#1)', () => {
|
|
it( 'does nothing to the elements with same option (#1)', () => {
|
|
|
- setData( document, '<heading1>[foo</heading1><heading1>bar]</heading1>' );
|
|
|
|
|
- commands.heading1.execute();
|
|
|
|
|
|
|
+ setData( model, '<heading1>[foo</heading1><heading1>bar]</heading1>' );
|
|
|
|
|
+ command.execute( { value: 'heading1' } );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal(
|
|
|
'<heading1>[foo</heading1><heading1>bar]</heading1>'
|
|
'<heading1>[foo</heading1><heading1>bar]</heading1>'
|
|
|
);
|
|
);
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'does nothing to the elements with same option (#2)', () => {
|
|
it( 'does nothing to the elements with same option (#2)', () => {
|
|
|
- setData( document, '<heading1>[foo</heading1><heading1>bar</heading1><heading2>baz]</heading2>' );
|
|
|
|
|
- commands.heading1.execute();
|
|
|
|
|
|
|
+ setData( model, '<heading1>[foo</heading1><heading1>bar</heading1><heading2>baz]</heading2>' );
|
|
|
|
|
+ command.execute( { value: 'heading1' } );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal(
|
|
|
'<heading1>[foo</heading1><heading1>bar</heading1><heading1>baz]</heading1>'
|
|
'<heading1>[foo</heading1><heading1>bar</heading1><heading1>baz]</heading1>'
|
|
|
);
|
|
);
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- function test( { modelElement: fromElement }, { modelElement: toElement } ) {
|
|
|
|
|
|
|
+ function test( { model: fromElement }, { model: toElement } ) {
|
|
|
it( `converts ${ fromElement } to ${ toElement } on non-collapsed selection`, () => {
|
|
it( `converts ${ fromElement } to ${ toElement } on non-collapsed selection`, () => {
|
|
|
setData(
|
|
setData(
|
|
|
- document,
|
|
|
|
|
|
|
+ model,
|
|
|
`<${ fromElement }>foo[bar</${ fromElement }><${ fromElement }>baz]qux</${ fromElement }>`
|
|
`<${ fromElement }>foo[bar</${ fromElement }><${ fromElement }>baz]qux</${ fromElement }>`
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- commands[ toElement ].execute();
|
|
|
|
|
|
|
+ command.execute( { value: toElement } );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model ) ).to.equal(
|
|
|
`<${ toElement }>foo[bar</${ toElement }><${ toElement }>baz]qux</${ toElement }>`
|
|
`<${ toElement }>foo[bar</${ toElement }><${ toElement }>baz]qux</${ toElement }>`
|
|
|
);
|
|
);
|
|
|
} );
|
|
} );
|
|
@@ -240,31 +280,25 @@ describe( 'HeadingCommand', () => {
|
|
|
|
|
|
|
|
describe( 'isEnabled', () => {
|
|
describe( 'isEnabled', () => {
|
|
|
for ( const option of options ) {
|
|
for ( const option of options ) {
|
|
|
- test( option.modelElement );
|
|
|
|
|
|
|
+ test( option.model );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function test( modelElement ) {
|
|
function test( modelElement ) {
|
|
|
- let command;
|
|
|
|
|
-
|
|
|
|
|
- beforeEach( () => {
|
|
|
|
|
- command = commands[ modelElement ];
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
describe( `${ modelElement } command`, () => {
|
|
describe( `${ modelElement } command`, () => {
|
|
|
it( 'should be enabled when inside another block', () => {
|
|
it( 'should be enabled when inside another block', () => {
|
|
|
- setData( document, '<paragraph>f{}oo</paragraph>' );
|
|
|
|
|
|
|
+ setData( model, '<paragraph>f{}oo</paragraph>' );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.true;
|
|
expect( command.isEnabled ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be disabled if inside non-block', () => {
|
|
it( 'should be disabled if inside non-block', () => {
|
|
|
- setData( document, '<notBlock>f{}oo</notBlock>' );
|
|
|
|
|
|
|
+ setData( model, '<notBlock>f{}oo</notBlock>' );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.false;
|
|
expect( command.isEnabled ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be disabled if selection is placed on non-block', () => {
|
|
it( 'should be disabled if selection is placed on non-block', () => {
|
|
|
- setData( document, '[<notBlock>foo</notBlock>]' );
|
|
|
|
|
|
|
+ setData( model, '[<notBlock>foo</notBlock>]' );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.false;
|
|
expect( command.isEnabled ).to.be.false;
|
|
|
} );
|
|
} );
|