|
|
@@ -13,7 +13,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
|
|
|
|
describe( 'BlockAutoformatEditing', () => {
|
|
|
- let editor, model, doc;
|
|
|
+ let editor, model, doc, plugin;
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
@@ -26,6 +26,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
editor = newEditor;
|
|
|
model = editor.model;
|
|
|
doc = model.document;
|
|
|
+ plugin = editor.plugins.get( 'Autoformat' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -36,7 +37,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
|
|
|
editor.commands.add( 'testCommand', testCommand );
|
|
|
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
|
|
|
@@ -53,7 +54,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
|
|
|
editor.commands.add( 'testCommand', testCommand );
|
|
|
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
|
|
|
@@ -75,7 +76,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
|
|
|
editor.commands.add( 'testCommand', testCommand );
|
|
|
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
|
|
|
@@ -90,7 +91,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
describe( 'callback', () => {
|
|
|
it( 'should run callback when the pattern is matched', () => {
|
|
|
const spy = testUtils.sinon.spy();
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s$/, spy ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
model.change( writer => {
|
|
|
@@ -100,9 +101,23 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
sinon.assert.calledOnce( spy );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should not call callback when the pattern is matched and plugin is disabled', () => {
|
|
|
+ const callbackSpy = testUtils.sinon.spy().named( 'callback' );
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s$/, callbackSpy ); // eslint-disable-line no-new
|
|
|
+
|
|
|
+ plugin.isEnabled = false;
|
|
|
+
|
|
|
+ setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.insertText( ' ', doc.selection.getFirstPosition() );
|
|
|
+ } );
|
|
|
+
|
|
|
+ sinon.assert.notCalled( callbackSpy );
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should ignore other delta operations', () => {
|
|
|
const spy = testUtils.sinon.spy();
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s/, spy ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
model.change( writer => {
|
|
|
@@ -114,7 +129,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
|
|
|
it( 'should stop if there is no text to run matching on', () => {
|
|
|
const spy = testUtils.sinon.spy();
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s/, spy ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>[]</paragraph>' );
|
|
|
model.change( writer => {
|
|
|
@@ -142,7 +157,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
} );
|
|
|
|
|
|
const spy = testUtils.sinon.spy();
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s/, spy ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>*<softBreak></softBreak>[]</paragraph>' );
|
|
|
model.change( writer => {
|
|
|
@@ -170,7 +185,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
} );
|
|
|
|
|
|
const spy = testUtils.sinon.spy();
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s/, spy ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>* <softBreak></softBreak>[]</paragraph>' );
|
|
|
|
|
|
@@ -182,7 +197,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should stop if callback returned false', () => {
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s$/, () => false ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s$/, () => false ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
model.change( writer => {
|
|
|
@@ -195,7 +210,7 @@ describe( 'BlockAutoformatEditing', () => {
|
|
|
|
|
|
it( 'should ignore transparent batches', () => {
|
|
|
const spy = testUtils.sinon.spy();
|
|
|
- new BlockAutoformatEditing( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
|
|
|
+ new BlockAutoformatEditing( editor, plugin, /^[*]\s$/, spy ); // eslint-disable-line no-new
|
|
|
|
|
|
setData( model, '<paragraph>*[]</paragraph>' );
|
|
|
model.enqueueChange( 'transparent', writer => {
|