Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added editor initialization manual performance test #6124

Merged
merged 3 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/_utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @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 window */

/**
* Loads a predefined set of performance markup files.
*
* loadPerformanceData()
* .then( fixtures => {
* window.editor.setData( fixtures.small );
* } );
*
* @returns {Promise.<Object.<String, String>>}
*/
export function loadPerformanceData() {
return Promise.all( [ getFileContents( 'small' ), getFileContents( 'medium' ), getFileContents( 'large' ) ] )
.then( responses => {
return {
small: responses[ 0 ],
medium: responses[ 1 ],
large: responses[ 2 ]
};
} );

function getFileContents( fileName ) {
return window.fetch( `_utils/${ fileName }.txt` )
.then( resp => resp.text() );
}
}
19 changes: 19 additions & 0 deletions tests/manual/performance/editorinit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<style>
.editor {
display: none;
}
</style>

<div id="test-controls">
Initialize editor 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>

<hr>

<div id="editor_small" class="editor"></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <hr> would be nice here as in other manual tests (small issue but would be nice to have same visual pattern for those tests).

<div id="editor_medium" class="editor"></div>
<div id="editor_large" class="editor"></div>
69 changes: 69 additions & 0 deletions tests/manual/performance/editorinit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @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';
import { loadPerformanceData } from '../../_utils/utils';

loadPerformanceData()
.then( fixtures => {
const buttons = document.querySelectorAll( '#test-controls button' );

for ( const button of buttons ) {
const fixtureName = button.getAttribute( 'data-file-name' );
const content = fixtures[ fixtureName ];
const editorElement = document.querySelector( `#editor_${ fixtureName }` );

// Put the source content in editor-related elements ahead of time, so that potentially
// big `innerHTML` change does not affect the benchmark when pressing the button.
editorElement.innerHTML = content;

button.addEventListener( 'click', function() {
ClassicEditor
.create( editorElement, {
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 );
} );
} );

button.disabled = false;
}
} );

7 changes: 7 additions & 0 deletions tests/manual/performance/editorinit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Performance: editor initialization

1. Begin performance recording in devtools.
1. Use any button to initialize the editor with a given content.
1. Stop performance recording.

**Note:** You should initialize editor only once. To test it again / different scenario refresh the page to have clear reference.
19 changes: 2 additions & 17 deletions tests/manual/performance/setdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
import { loadPerformanceData } from '../../_utils/utils';

ClassicEditor
.create( document.querySelector( '#editor' ), {
Expand Down Expand Up @@ -37,7 +38,7 @@ ClassicEditor
console.error( err.stack );
} );

preloadData()
loadPerformanceData()
.then( fixtures => {
const buttons = document.querySelectorAll( '#test-controls button' );

Expand All @@ -50,19 +51,3 @@ preloadData()
button.disabled = false;
}
} );

function preloadData() {
return Promise.all( [ getFileContents( 'small' ), getFileContents( 'medium' ), getFileContents( 'large' ) ] )
.then( responses => {
return {
small: responses[ 0 ],
medium: responses[ 1 ],
large: responses[ 2 ]
};
} );

function getFileContents( fileName ) {
return window.fetch( `_utils/${ fileName }.txt` )
.then( resp => resp.text() );
}
}