瀏覽代碼

Move auto link undo test to own integration suite.

Maciej Gołaszewski 5 年之前
父節點
當前提交
d6ec3a7ad0
共有 2 個文件被更改,包括 56 次插入44 次删除
  1. 1 1
      packages/ckeditor5-link/src/autolink.js
  2. 55 43
      packages/ckeditor5-link/tests/autolink.js

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

@@ -74,7 +74,7 @@ export default class AutoLink extends Plugin {
 			this._applyAutoLink( url, range );
 		} );
 
-		// todo: watcher.bind();
+		watcher.bind( 'isEnabled' ).to( this );
 	}
 
 	/**

+ 55 - 43
packages/ckeditor5-link/tests/autolink.js

@@ -15,16 +15,18 @@ import LinkEditing from '../src/linkediting';
 import AutoLink from '../src/autolink';
 
 describe( 'AutoLink', () => {
+	let editor;
+
 	it( 'should be named', () => {
 		expect( AutoLink.pluginName ).to.equal( 'AutoLink' );
 	} );
 
 	describe( 'auto link behavior', () => {
-		let editor, model;
+		let model;
 
 		beforeEach( async () => {
 			editor = await ModelTestEditor.create( {
-				plugins: [ Paragraph, Input, LinkEditing, AutoLink, UndoEditing, Enter, ShiftEnter ]
+				plugins: [ Paragraph, Input, LinkEditing, AutoLink, Enter, ShiftEnter ]
 			} );
 
 			model = editor.model;
@@ -95,41 +97,6 @@ describe( 'AutoLink', () => {
 			);
 		} );
 
-		it( 'can undo auto-linking (after space)', () => {
-			simulateTyping( 'https://www.cksource.com ' );
-
-			editor.commands.execute( 'undo' );
-
-			expect( getData( model ) ).to.equal(
-				'<paragraph>https://www.cksource.com []</paragraph>'
-			);
-		} );
-
-		it( 'can undo auto-linking (after <softBreak>)', () => {
-			setData( model, '<paragraph>https://www.cksource.com[]</paragraph>' );
-
-			editor.execute( 'shiftEnter' );
-
-			editor.commands.execute( 'undo' );
-
-			expect( getData( model ) ).to.equal(
-				'<paragraph>https://www.cksource.com<softBreak></softBreak>[]</paragraph>'
-			);
-		} );
-
-		it( 'can undo auto-linking (after enter)', () => {
-			setData( model, '<paragraph>https://www.cksource.com[]</paragraph>' );
-
-			editor.execute( 'enter' );
-
-			editor.commands.execute( 'undo' );
-
-			expect( getData( model ) ).to.equal(
-				'<paragraph>https://www.cksource.com</paragraph>' +
-				'<paragraph>[]</paragraph>'
-			);
-		} );
-
 		it( 'adds "mailto://" to link of detected email addresses', () => {
 			simulateTyping( 'newsletter@cksource.com ' );
 
@@ -176,13 +143,58 @@ describe( 'AutoLink', () => {
 					`<paragraph>${ unsupportedURL } []</paragraph>` );
 			} );
 		}
+	} );
 
-		function simulateTyping( text ) {
-			const letters = text.split( '' );
+	describe( 'Undo integration', () => {
+		let model;
 
-			for ( const letter of letters ) {
-				editor.execute( 'input', { text: letter } );
-			}
-		}
+		beforeEach( async () => {
+			editor = await ModelTestEditor.create( {
+				plugins: [ Paragraph, Input, LinkEditing, AutoLink, UndoEditing, Enter, ShiftEnter ]
+			} );
+
+			model = editor.model;
+
+			setData( model, '<paragraph>https://www.cksource.com[]</paragraph>' );
+		} );
+
+		it( 'should undo auto-linking (after space)', () => {
+			simulateTyping( ' ' );
+
+			editor.commands.execute( 'undo' );
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>https://www.cksource.com []</paragraph>'
+			);
+		} );
+
+		it( 'should undo auto-linking (after <softBreak>)', () => {
+			editor.execute( 'shiftEnter' );
+
+			editor.commands.execute( 'undo' );
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>https://www.cksource.com<softBreak></softBreak>[]</paragraph>'
+			);
+		} );
+
+		it( 'should undo auto-linking (after enter)', () => {
+			editor.execute( 'enter' );
+
+			editor.commands.execute( 'undo' );
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>https://www.cksource.com</paragraph>' +
+				'<paragraph>[]</paragraph>'
+			);
+		} );
 	} );
+
+	function simulateTyping( text ) {
+		const letters = text.split( '' );
+
+		for ( const letter of letters ) {
+			editor.execute( 'input', { text: letter } );
+		}
+	}
 } );