Explorar el Código

Tests: Initial test for setting editor data.

Marek Lewandowski hace 5 años
padre
commit
d4d1da18d7

+ 1 - 0
tests/manual/performance/_utils/large.txt

@@ -0,0 +1 @@
+<h1>large data placeholder</h1>

+ 1 - 0
tests/manual/performance/_utils/medium.txt

@@ -0,0 +1 @@
+<h1>Medium data placeholder</h1>

+ 3 - 0
tests/manual/performance/_utils/small.txt

@@ -0,0 +1,3 @@
+<h1>Hello world</h1>
+
+<p>This is rather short text with <em>very little</em> text <strong>formatting</strong>.</p>

+ 9 - 0
tests/manual/performance/setdata.html

@@ -0,0 +1,9 @@
+<div id="test-controls">
+	Set data with:
+	<button id="small-content" data-file-name="small" disabled>small</button>
+	<button id="medium-content" data-file-name="medium" disabled>medium</button>
+	<button id="large-content" data-file-name="large" disabled>large</button>
+	HTML payload.
+</div>
+
+<div id="editor"></div>

+ 76 - 0
tests/manual/performance/setdata.js

@@ -0,0 +1,76 @@
+/**
+ * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/* globals console, window, document */
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
+
+ClassicEditor
+	.create( document.querySelector( '#editor' ), {
+		plugins: [ ArticlePluginSet ],
+		toolbar: [
+			'heading',
+			'|',
+			'bold',
+			'italic',
+			'link',
+			'bulletedList',
+			'numberedList',
+			'|',
+			'outdent',
+			'indent',
+			'|',
+			'blockQuote',
+			'insertTable',
+			'mediaEmbed',
+			'undo',
+			'redo'
+		],
+		image: {
+			toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
+		},
+		table: {
+			contentToolbar: [
+				'tableColumn',
+				'tableRow',
+				'mergeTableCells'
+			]
+		}
+	} )
+	.then( editor => {
+		window.editor = editor;
+	} )
+	.catch( err => {
+		console.error( err.stack );
+	} );
+
+const buttons = document.querySelectorAll( '#test-controls button' );
+const fileNames = Array.from( buttons ).map( button => button.getAttribute( 'data-file-name' ) );
+
+preloadData( fileNames.map( name => `_utils/${ name }.txt` ) )
+	.then( fixtures => {
+		console.log( 'fixtures' );
+		console.log( fixtures );
+
+		for ( const button of buttons ) {
+			button.addEventListener( 'click', function() {
+				const content = fixtures[ this.getAttribute( 'data-file-name' ) ];
+
+				window.editor.setData( content );
+			} );
+			button.disabled = false;
+		}
+	} );
+
+function preloadData( urls ) {
+	// @todo: simplify it - inline literals instead of looping over arrays.
+	return Promise.all( urls.map( url => window.fetch( url ).then( resp => resp.text() ) ) )
+		.then( responses => {
+			return Object.fromEntries(
+				Array.from( responses.keys() ).map( index => [ fileNames[ index ], responses[ index ] ] )
+			);
+		} );
+}

+ 3 - 0
tests/manual/performance/setdata.md

@@ -0,0 +1,3 @@
+# Performance: `editor.setData()`
+
+1. Use any of "set data" buttons to perform a `editor.setData()` operation.