浏览代码

Add tests for force-disabling AutoLink.

Maciej Gołaszewski 5 年之前
父节点
当前提交
239de3d2e3
共有 2 个文件被更改,包括 37 次插入4 次删除
  1. 1 1
      packages/ckeditor5-link/src/autolink.js
  2. 36 3
      packages/ckeditor5-link/tests/autolink.js

+ 1 - 1
packages/ckeditor5-link/src/autolink.js

@@ -215,7 +215,7 @@ export default class AutoLink extends Plugin {
 	_applyAutoLink( url, range ) {
 		const model = this.editor.model;
 
-		if ( !isLinkAllowedOnRange( range, model ) ) {
+		if ( !this.isEnabled || !isLinkAllowedOnRange( range, model ) ) {
 			return;
 		}
 

+ 36 - 3
packages/ckeditor5-link/tests/autolink.js

@@ -77,6 +77,39 @@ describe( 'AutoLink', () => {
 			);
 		} );
 
+		it( 'does not add linkHref attribute if plugin is force-disabled (on space)', () => {
+			editor.plugins.get( 'AutoLink' ).forceDisabled( 'test' );
+
+			simulateTyping( 'https://www.cksource.com ' );
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>https://www.cksource.com []</paragraph>'
+			);
+		} );
+
+		it( 'does not add linkHref attribute if plugin is force-disabled (on enter)', () => {
+			setData( model, '<paragraph>https://www.cksource.com[]</paragraph>' );
+			editor.plugins.get( 'AutoLink' ).forceDisabled( 'test' );
+
+			editor.execute( 'enter' );
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>https://www.cksource.com</paragraph>' +
+				'<paragraph>[]</paragraph>'
+			);
+		} );
+
+		it( 'does not add linkHref attribute if plugin is force-disabled (on shift enter)', () => {
+			setData( model, '<paragraph>https://www.cksource.com[]</paragraph>' );
+			editor.plugins.get( 'AutoLink' ).forceDisabled( 'test' );
+
+			editor.execute( 'shiftEnter' );
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>https://www.cksource.com<softBreak></softBreak>[]</paragraph>'
+			);
+		} );
+
 		it( 'adds linkHref attribute to a text link after space (inside paragraph)', () => {
 			setData( model, '<paragraph>Foo Bar [] Baz</paragraph>' );
 
@@ -87,7 +120,7 @@ describe( 'AutoLink', () => {
 			);
 		} );
 
-		it( 'adds linkHref attribute to a text link after a soft break', () => {
+		it( 'adds linkHref attribute to a text link on shift enter', () => {
 			setData( model, '<paragraph>https://www.cksource.com[]</paragraph>' );
 
 			editor.execute( 'shiftEnter' );
@@ -95,8 +128,8 @@ describe( 'AutoLink', () => {
 			// TODO: should test with selection but master has a bug. See: https://github.com/ckeditor/ckeditor5/issues/7459.
 			expect( getData( model, { withoutSelection: true } ) ).to.equal(
 				'<paragraph>' +
-					'<$text linkHref="https://www.cksource.com">https://www.cksource.com</$text>' +
-					'<softBreak></softBreak>' +
+				'<$text linkHref="https://www.cksource.com">https://www.cksource.com</$text>' +
+				'<softBreak></softBreak>' +
 				'</paragraph>'
 			);
 		} );