Răsfoiți Sursa

Change manual test.

panr 5 ani în urmă
părinte
comite
e9b938eabb

+ 16 - 9
packages/ckeditor5-link/tests/manual/protocol.html

@@ -35,18 +35,25 @@
 	}
 </style>
 
-<h2>The default configuration for the link protocol has been set to <code id="default-protocol"></code>.</h2>
 
-<h3>...but you can dynamically change it:</h3>
-<form id="protocol-settings" style="margin: 20px 0;">
-	<label for="none"><input type="radio" name="option" id="none" value="none" />DISABLE FEATURE</label>
-	<label for="http"><input type="radio" name="option" id="http" value="http://" />HTTP</label>
-	<label for="https"><input type="radio" name="option" id="https" value="https://" />HTTPS</label>
-	<label for="mailto"><input type="radio" name="option" id="mailto" value="mailto:" />MAILTO</label>
-</form>
+<h2><code>Feature is disabled</code></h2>
+<div id="editor0">
+	<p>This is <a href="http://ckeditor.com">CKEditor5</a> from <a href="http://cksource.com">CKSource</a>. If you need more information please contact us at support@example.com.</p>
+</div>
 
-<div id="editor">
+<h2><code>http://</code></h2>
+<div id="editor1">
 	<p>This is <a href="http://ckeditor.com">CKEditor5</a> from <a href="http://cksource.com">CKSource</a>. If you need more information please contact us at support@example.com <sup class="indicator">[1]</sup>.</p>
 </div>
 
 <p><sup>[1]</sup><strong>When feature enabled:</strong> copy the email address and create a link with it (<code>mailto:</code> protocol will be added automatically).</p>
+
+<h2><code>https://</code></h2>
+<div id="editor2">
+	<p>This is <a href="http://ckeditor.com">CKEditor5</a> from <a href="http://cksource.com">CKSource</a>. If you need more information please contact us at support@example.com.</p>
+</div>
+
+<h2><code>mailto:</code></h2>
+<div id="editor3">
+	<p>This is <a href="http://ckeditor.com">CKEditor5</a> from <a href="http://cksource.com">CKSource</a>. If you need more information please contact us at support@example.com.</p>
+</div>

+ 21 - 33
packages/ckeditor5-link/tests/manual/protocol.js

@@ -13,37 +13,25 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import Undo from '@ckeditor/ckeditor5-undo/src/undo';
 import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript';
 
-ClassicEditor
-	.create( document.querySelector( '#editor' ), {
-		plugins: [ Link, Typing, Paragraph, Undo, Enter, Superscript ],
-		toolbar: [ 'link', 'undo', 'redo' ],
-		link: {
-			addTargetToExternalLinks: true,
-			defaultProtocol: 'http://'
-		}
-	} )
-	.then( editor => {
-		window.editor = editor;
-
-		const LinkUIPlugin = editor.plugins.get( 'LinkUI' );
-		const formView = LinkUIPlugin.formView;
-		const defaultProtocol = editor.config.get( 'link.defaultProtocol' );
-
-		document.getElementById( 'default-protocol' ).innerText = defaultProtocol;
-
-		document.querySelectorAll( '#protocol-settings input[type="radio"]' ).forEach( radio => {
-			radio.checked = radio.value === defaultProtocol;
-
-			radio.addEventListener( 'click', ( {
-				target: { value: protocol }
-			} ) => {
-				editor.config.set( 'link.defaultProtocol', protocol === 'none' ? undefined : protocol );
-
-				// Change input placeholder just for manual test's case to provide more dynamic behavior.
-				formView.urlInputView.fieldView.placeholder = protocol === 'none' ? 'https://example.com' : protocol + 'example.com';
-			} );
+createEditorWithDefaultProtocol( '#editor0' );
+createEditorWithDefaultProtocol( '#editor1', 'http://' );
+createEditorWithDefaultProtocol( '#editor2', 'https://' );
+createEditorWithDefaultProtocol( '#editor3', 'mailto:' );
+
+function createEditorWithDefaultProtocol( editor, defaultProtocol ) {
+	return ClassicEditor
+		.create( document.querySelector( editor ), {
+			plugins: [ Link, Typing, Paragraph, Undo, Enter, Superscript ],
+			toolbar: [ 'link', 'undo', 'redo' ],
+			link: {
+				addTargetToExternalLinks: true,
+				...defaultProtocol && { defaultProtocol }
+			}
+		} )
+		.then( editor => {
+			window.editor = editor;
+		} )
+		.catch( err => {
+			console.error( err.stack );
 		} );
-	} )
-	.catch( err => {
-		console.error( err.stack );
-	} );
+}

+ 1 - 3
packages/ckeditor5-link/tests/manual/protocol.md

@@ -2,7 +2,5 @@
 
 This test checks whether:
 - `config.link.defaultProtocol` applies.
-- user is able to dynamically change the link protocol (just as an extended example of usage).
+- when input value starts with a protocol-like syntax (like `http://` etc.) or any non-word (like `#` or `/`) then `defaultProtocol` won't be applied.
 - the plugin dynamically change link protocol to `mailto:` when email address was detected.
-
-When you dynamically change the value of the link protocol, the form input placeholder should change as well.