Sfoglia il codice sorgente

Add tests for auto link expected behavior.

Maciej Gołaszewski 5 anni fa
parent
commit
bbdc501af2
1 ha cambiato i file con 49 aggiunte e 0 eliminazioni
  1. 49 0
      packages/ckeditor5-link/tests/autolink.js

+ 49 - 0
packages/ckeditor5-link/tests/autolink.js

@@ -3,10 +3,59 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
  */
 
 
+import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+
+import Link from '../src/link';
 import AutoLink from '../src/autolink';
 import AutoLink from '../src/autolink';
 
 
 describe( 'AutoLink', () => {
 describe( 'AutoLink', () => {
 	it( 'should be named', () => {
 	it( 'should be named', () => {
 		expect( AutoLink.pluginName ).to.equal( 'AutoLink' );
 		expect( AutoLink.pluginName ).to.equal( 'AutoLink' );
 	} );
 	} );
+
+	describe( 'auto link behavior', () => {
+		let editor;
+
+		beforeEach( async () => {
+			editor = ModelTestEditor.create( { plugins: [ Paragraph, Link, AutoLink ] } );
+
+			setData( editor.model, '<paragraph>[]</paragraph>' );
+		} );
+
+		it( 'does not add linkHref attribute to a text link while typing', () => {
+			simulateTyping( editor, 'https://www.cksource.com' );
+
+			expect( getData( editor.model ) ).to.equal(
+				'<paragraph>https://www.cksource.com[]</paragraph>'
+			);
+		} );
+
+		it( 'adds linkHref attribute to a text link after space', () => {
+			simulateTyping( editor, 'https://www.cksource.com ' );
+
+			expect( getData( editor.model ) ).to.equal(
+				'<paragraph><$text linkHref="https://www.cksource.com">https://www.cksource.com</$text> []</paragraph>'
+			);
+		} );
+
+		it( 'can undo auto-linking', () => {
+			simulateTyping( editor, 'https://www.cksource.com ' );
+
+			editor.commands.execute( 'undo' );
+
+			expect( getData( editor.model ) ).to.equal(
+				'<paragraph>https://www.cksource.com []</paragraph>'
+			);
+		} );
+
+		function simulateTyping( text ) {
+			const letters = text.split( '' );
+
+			for ( const letter of letters ) {
+				editor.execute( 'input', { text: letter } );
+			}
+		}
+	} );
 } );
 } );