Skip to content

Commit

Permalink
Add custom detach editor test for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
sculpt0r authored and f1ames committed Apr 23, 2021
1 parent ee13308 commit 806e0f0
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/core/creators/manual/detachedcustomcallbackmobile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div id="message"></div>
<button id="startButton">Try to create editor</button>
<button id="attachButton">Invoke config callback to finish editor creation</button>
<div>
<div id="editor">
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>

<script>
if ( !bender.tools.env.mobile ) {
bender.ignore();
}

var editor = document.getElementById( 'editor' ),
attachButton = CKEDITOR.document.getById( 'attachButton' ),
startButton = CKEDITOR.document.getById( 'startButton' ),
messageElement = CKEDITOR.document.getById( 'message' ),
editorParent = editor.parentNode,
editorCreationCallback;

editorParent.removeChild( editor );

startButton.on( 'click', function() {
CKEDITOR.replace( editor, {
delayIfDetached: true,
delayIfDetached_callback: registerCallback,
on: {
instanceReady: function() {
messageElement.setHtml( 'Editor is ready!' );
}
}
} );

messageElement.setHtml( 'Creation attempt finished. Callback is ready to use.' );
} );

attachButton.on( 'click', function() {
editorParent.appendChild( editor );

messageElement.setHtml( 'Editor attached to DOM' );

editorCreationCallback();
} );

function registerCallback( editorCreationFunc ) {
editorCreationCallback = editorCreationFunc;
}
</script>
16 changes: 16 additions & 0 deletions tests/core/creators/manual/detachedcustomcallbackmobile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@bender-tags: 4.17.0, feature, 4461
@bender-ui: collapsed
@bender-ckeditor-plugins: toolbar, wysiwygarea, sourcearea, undo, clipboard, basicstyles, elementspath

1. Click `Try to create editor` button.
2. Click the second button to attach editor to DOM element and invoke config callback to finish editor creation.

**Expected**
* Editor is created.
* Editor contains initial data.
* Editor data is editable.

**Unexpected**
* Editor isn't created.
* Editor data is empty.
* Editor data is not editable.
56 changes: 56 additions & 0 deletions tests/core/creators/manual/detachedcustomintervalmobile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<div id="message"></div>
<button id="startButton">Start Test</button>
<span id="testTimer"></span>

<div>
<div id="editor">
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>

<script>
if ( !bender.tools.env.mobile ) {
bender.ignore();
}

var editorElement = document.getElementById( 'editor' ),
startButton = CKEDITOR.document.getById( 'startButton' ),
timerElement = CKEDITOR.document.getById( 'testTimer' ),
messageElement = CKEDITOR.document.getById( 'message' ),
editorParent = editorElement.parentNode,
waitTime = 3000,
timerInterval = 50,
timerIntervalToken;

startButton.on( 'click', function ( evt ) {
evt && evt.removeListener();

timerIntervalToken = setInterval( function() {
waitTime -= timerInterval;
if ( waitTime <= 0 ) {
messageElement.setHtml( 'Editor is going to be created...' );

waitTime = 0;
clearInterval( timerIntervalToken );
}

timerElement.setText( waitTime + 'ms');
}, timerInterval );

editorParent.removeChild( editorElement );

CKEDITOR.tools.setTimeout( function() {
editorParent.appendChild( editorElement );
}, 50 );

CKEDITOR.replace( editorElement, {
delayIfDetached: true,
delayIfDetached_interval: waitTime,
on: {
instanceReady: function() {
messageElement.setHtml( 'Editor is ready!' );
}
}
} );
} );
</script>
16 changes: 16 additions & 0 deletions tests/core/creators/manual/detachedcustomintervalmobile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@bender-tags: 4.17.0, feature, 4461
@bender-ui: collapsed
@bender-ckeditor-plugins: toolbar, wysiwygarea, sourcearea, undo, clipboard, basicstyles, elementspath

1. Click the button to start the test.
2. Wait three seconds for editor creation.

**Expected**
* Editor is created.
* Editor contains initial data.
* Editor data is editable.

**Unexpected**
* Editor isn't created.
* Editor data is empty.
* Editor data is not editable.

0 comments on commit 806e0f0

Please sign in to comment.