ModuleLoader.require([
"tinymce/Env",
"tinymce/caret/CaretCandidate",
"tinymce/dom/DomQuery",
"tinymce/text/Zwsp"
], function(Env, CaretCandidate, $, Zwsp) {
module("tinymce.caret.CaretCandidate");
if (!Env.ceFalse) {
return;
}
function getRoot() {
return document.getElementById('view');
}
function setupHtml(html) {
getRoot().innerHTML = html;
}
test('isCaretCandidate', function() {
$.each("img input textarea hr table iframe video audio object".split(' '), function(index, name) {
equal(CaretCandidate.isCaretCandidate(document.createElement(name)), true);
});
equal(CaretCandidate.isCaretCandidate(document.createTextNode('text')), true);
equal(CaretCandidate.isCaretCandidate($('')[0]), true);
equal(CaretCandidate.isCaretCandidate($('
')[0]), true);
equal(CaretCandidate.isCaretCandidate($('')[0]), true);
equal(CaretCandidate.isCaretCandidate($('')[0]), false);
equal(CaretCandidate.isCaretCandidate($('')[0]), false);
equal(CaretCandidate.isCaretCandidate(document.createComment('text')), false);
equal(CaretCandidate.isCaretCandidate($('')[0]), false);
equal(CaretCandidate.isCaretCandidate(document.createTextNode(Zwsp.ZWSP)), false);
});
test('isInEditable', function() {
setupHtml('abcX');
equal(CaretCandidate.isInEditable($('span span', getRoot())[0].firstChild, getRoot()), false);
equal(CaretCandidate.isInEditable($('span span', getRoot())[0], getRoot()), true);
equal(CaretCandidate.isInEditable($('span', getRoot())[0], getRoot()), true);
equal(CaretCandidate.isInEditable(getRoot().firstChild, getRoot()), true);
});
test('isAtomic', function() {
$.each(["img", "input", "textarea", "hr"], function(index, name) {
equal(CaretCandidate.isAtomic(document.createElement(name)), true);
});
equal(CaretCandidate.isAtomic(document.createTextNode('text')), false);
equal(CaretCandidate.isAtomic($('')[0]), false);
equal(CaretCandidate.isAtomic($('X')[0]), true);
equal(CaretCandidate.isAtomic($('XYZ')[0]), false);
});
test('isEditableCaretCandidate', function() {
setupHtml('abcxxX');
equal(CaretCandidate.isEditableCaretCandidate(getRoot().firstChild, getRoot()), true);
equal(CaretCandidate.isEditableCaretCandidate($('b', getRoot())[0]), false);
equal(CaretCandidate.isEditableCaretCandidate($('span', getRoot())[0]), true);
equal(CaretCandidate.isEditableCaretCandidate($('span span', getRoot())[0]), false);
});
});