2017-03-07 13:57:09 +03:00
|
|
|
import Ember from 'ember';
|
2017-03-14 14:59:34 +03:00
|
|
|
import $ from 'jquery';
|
2017-03-07 13:57:09 +03:00
|
|
|
// polls the editor until it's started.
|
|
|
|
export function editorRendered() {
|
|
|
|
return Ember.Test.promise(function (resolve) { // eslint-disable-line
|
|
|
|
function checkEditor() {
|
|
|
|
if (window.editor) {
|
|
|
|
return resolve();
|
|
|
|
} else {
|
|
|
|
window.requestAnimationFrame(checkEditor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkEditor();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-22 02:42:14 +03:00
|
|
|
// polls the title until it's started.
|
|
|
|
export function titleRendered() {
|
|
|
|
return Ember.Test.promise(function (resolve) { // eslint-disable-line
|
|
|
|
function checkTitle() {
|
|
|
|
let title = $('#gh-editor-title div');
|
|
|
|
if (title[0]) {
|
|
|
|
return resolve();
|
|
|
|
} else {
|
|
|
|
window.requestAnimationFrame(checkTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkTitle();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-07 13:57:09 +03:00
|
|
|
// simulates text inputs into the editor, unfortunately the helper Ember helper functions
|
|
|
|
// don't work on content editable so we have to manipuate the text input event manager
|
|
|
|
// in mobiledoc-kit directly. This is a private API.
|
|
|
|
export function inputText(editor, text) {
|
|
|
|
editor._eventManager._textInputHandler.handle(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
// inputs text and waits for the editor to modify the dom with the desired result or timesout.
|
|
|
|
export function testInput(input, output, expect) {
|
|
|
|
window.editor.element.focus(); // for some reason the editor doesn't work until it's focused when run in ghost-admin.
|
|
|
|
return Ember.Test.promise(function (resolve, reject) { // eslint-disable-line
|
|
|
|
let lastRender = '';
|
|
|
|
let isRejected = false;
|
|
|
|
let rejectTimeout = window.setTimeout(() => {
|
|
|
|
expect(lastRender).to.equal(output); // we know this is false but include it for the output.
|
|
|
|
reject(lastRender);
|
|
|
|
isRejected = true;
|
|
|
|
}, 500);
|
|
|
|
window.editor.didRender(() => {
|
|
|
|
lastRender = window.editor.element.innerHTML;
|
|
|
|
if (window.editor.element.innerHTML === output && !isRejected) {
|
|
|
|
window.clearTimeout(rejectTimeout);
|
|
|
|
expect(lastRender).to.equal(output); // we know this is true but include it for the output.
|
|
|
|
return resolve(lastRender);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
inputText(window.editor, input);
|
|
|
|
});
|
2017-03-14 14:59:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export function waitForRender(selector) {
|
|
|
|
let isRejected = false;
|
|
|
|
return Ember.Test.promise(function (resolve, reject) { // eslint-disable-line
|
|
|
|
let rejectTimeout = window.setTimeout(() => {
|
|
|
|
reject('element didn\'t render');
|
|
|
|
isRejected = true;
|
|
|
|
}, 1500);
|
|
|
|
|
|
|
|
function checkIsRendered() {
|
|
|
|
if ($(selector)[0] && !isRejected) {
|
|
|
|
window.clearTimeout(rejectTimeout);
|
|
|
|
return resolve();
|
|
|
|
} else {
|
|
|
|
window.requestAnimationFrame(checkIsRendered);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkIsRendered();
|
|
|
|
});
|
2017-03-22 02:42:14 +03:00
|
|
|
}
|