Bläddra i källkod

Add manual test for server testing. Fix CORS issues.

Maciej Gołaszewski 6 år sedan
förälder
incheckning
eb5e62bebc

+ 8 - 7
packages/ckeditor5-mention/dev-server/index.js

@@ -11,14 +11,15 @@ const hostname = '127.0.0.1';
 const port = 3000;
 
 const server = http.createServer( function( req, res ) {
+	res.statusCode = 200;
+	res.setHeader( 'Content-Type', 'application/json' );
+
 	readEntries( getTimeout() ).then( entries => {
-		res.statusCode = 200;
-		res.setHeader( 'Content-Type', 'application/json' );
-		res.end( JSON.stringify( entries ) );
-	} );
+		res.setHeader( 'Access-Control-Allow-Origin', '*' );
+		res.setHeader( 'Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept' );
 
-	setTimeout( () => {
-	}, 600 );
+		res.end( JSON.stringify( entries ) + '\n' );
+	} );
 } );
 
 server.listen( port, hostname, () => {
@@ -29,7 +30,7 @@ function readEntries( timeOut ) {
 	return new Promise( resolve => {
 		setTimeout( () => {
 			resolve( [
-				{ id: 123, username: 'jodator', name: 'Maciej Gołaszewski' }
+				{ id: '@jodator', name: 'Maciej Gołaszewski', userId: 123 }
 			] );
 		}, timeOut );
 	} );

+ 13 - 0
packages/ckeditor5-mention/tests/manual/mention-asynchronous.html

@@ -0,0 +1,13 @@
+<head>
+	<meta http-equiv="Content-Security-Policy" content="default-src 'none'; connect-src 'self' http://localhost:3000 https://cksource.com http://*.cke-cs.com; script-src 'self' https://cksource.com; img-src * data:; style-src 'self' 'unsafe-inline'; frame-src *" />
+</head>
+
+<div id="editor">
+	<p>Hello <span class="mention" data-mention="@Ted">@Ted</span>.</p>
+	<p>Hello <span class="mention" data-mention="@Ted">@Ted</span><span class="mention" data-mention="@Ted">@Ted</span>.</p>
+
+	<figure class="image">
+		<img src="sample.jpg" />
+		<figcaption>CKEditor logo - caption</figcaption>
+	</figure>
+</div>

+ 54 - 0
packages/ckeditor5-mention/tests/manual/mention-asynchronous.js

@@ -0,0 +1,54 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/* global console, window, fetch */
+
+import global from '@ckeditor/ckeditor5-utils/src/dom/global';
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
+import Mention from '../../src/mention';
+import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
+import Font from '@ckeditor/ckeditor5-font/src/font';
+
+ClassicEditor
+	.create( global.document.querySelector( '#editor' ), {
+		plugins: [ ArticlePluginSet, Underline, Font, Mention ],
+		toolbar: [
+			'heading',
+			'|', 'bulletedList', 'numberedList', 'blockQuote',
+			'|', 'bold', 'italic', 'underline', 'link',
+			'|', 'fontFamily', 'fontSize', 'fontColor', 'fontBackgroundColor',
+			'|', 'insertTable',
+			'|', 'undo', 'redo'
+		],
+		image: {
+			toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
+		},
+		mention: {
+			feeds: [
+				{
+					marker: '@',
+					feed: getFeed
+				}
+			]
+		}
+	} )
+	.then( editor => {
+		window.editor = editor;
+	} )
+	.catch( err => {
+		console.error( err.stack );
+	} );
+
+function getFeed() {
+	const fetchOptions = {
+		method: 'get',
+		mode: 'cors'
+	};
+
+	return fetch( 'http://localhost:3000', fetchOptions )
+		.then( response => response.json() );
+}

+ 34 - 0
packages/ckeditor5-mention/tests/manual/mention-asynchronous.md

@@ -0,0 +1,34 @@
+## Mention
+
+
+### Configuration
+
+The feeds:
+
+1. Static list with `@` marker:
+
+    - Barney
+    - Lily
+    - Marshall
+    - Robin
+    - Ted
+
+2. Static list of 20 items (`#` marker)
+
+    - a01
+    - a02
+    - ...
+    - a20
+
+### Interaction
+
+You can interact with mention panel with keyboard:
+
+- Move arrows up/down to select an item.
+- Use <kbd>enter</kbd> or <kbd>tab</kbd> to insert a mention into the documentation. 
+- The <kbd>esc</kbd> should close the panel.
+
+Mention panel should be closed on:
+- Click outside the panel view.
+- Changing selection - like placing it in other part of text.
+