Skip to content

Commit

Permalink
Change manual test.
Browse files Browse the repository at this point in the history
  • Loading branch information
panr committed Jun 10, 2020
1 parent de6f4d9 commit e9b938e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 45 deletions.
25 changes: 16 additions & 9 deletions packages/ckeditor5-link/tests/manual/protocol.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
54 changes: 21 additions & 33 deletions packages/ckeditor5-link/tests/manual/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );
}
4 changes: 1 addition & 3 deletions packages/ckeditor5-link/tests/manual/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit e9b938e

Please sign in to comment.