ModuleLoader.require([
"tinymce/InsertContent"
], function(InsertContent) {
module("tinymce.InsertContent", {
setupModule: function() {
QUnit.stop();
tinymce.init({
selector: "textarea",
add_unload_trigger: false,
disable_nodechange: true,
skin: false,
entities: 'raw',
indent: false,
init_instance_callback: function(ed) {
window.editor = ed;
QUnit.start();
}
});
}
});
function assertSelection(selector, offset) {
var node = editor.$(selector)[0];
var rng = editor.selection.getRng();
equal(rng.startContainer, node.firstChild);
equal(rng.startOffset, offset);
equal(rng.collapsed, true);
}
test('insertAtCaret - i inside text, converts to em', function() {
editor.setContent('
1234
');
editor.focus();
Utils.setSelection('p', 2);
InsertContent.insertAtCaret(editor, 'a');
equal(editor.getContent(), '12a34
');
});
test('insertAtCaret - ul at beginning of li', function() {
editor.setContent('');
editor.focus();
Utils.setSelection('li', 0);
InsertContent.insertAtCaret(editor, '');
equal(editor.getContent(), '');
assertSelection('li:nth-child(2)', 0);
});
test('insertAtCaret - ul with multiple items at beginning of li', function() {
editor.setContent('');
editor.focus();
Utils.setSelection('li', 0);
InsertContent.insertAtCaret(editor, '');
equal(editor.getContent(), '');
assertSelection('li:nth-child(3)', 0);
});
test('insertAtCaret - ul at end of li', function() {
editor.setContent('');
editor.focus();
Utils.setSelection('li', 2);
InsertContent.insertAtCaret(editor, '');
equal(editor.getContent(), '');
assertSelection('li:nth-child(2)', 1);
});
test('insertAtCaret - ul with multiple items at end of li', function() {
editor.setContent('');
editor.focus();
Utils.setSelection('li', 2);
InsertContent.insertAtCaret(editor, '');
equal(editor.getContent(), '');
assertSelection('li:nth-child(4)', 1);
});
test('insertAtCaret - ul with multiple items in middle of li', function() {
editor.setContent('');
editor.focus();
Utils.setSelection('li', 1);
InsertContent.insertAtCaret(editor, '');
equal(editor.getContent(), '');
assertSelection('li:nth-child(4)', 1);
});
test('insertAtCaret - ul in middle of li with formatting', function() {
editor.setContent('');
editor.focus();
Utils.setSelection('strong', 1);
InsertContent.insertAtCaret(editor, '');
equal(editor.getContent(), '');
assertSelection('li:nth-child(3) strong', 1);
});
test('insertAtCaret - ul at beginning of li with empty end li', function() {
editor.setContent('');
editor.focus();
Utils.setSelection('li', 0);
InsertContent.insertAtCaret(editor, '');
equal(editor.getContent(), '');
assertSelection('li:nth-child(2)', 0);
});
test('insertAtCaret - merge inline elements', function() {
editor.setContent('abc');
editor.focus();
Utils.setSelection('em', 1);
InsertContent.insertAtCaret(editor, {content: '123', merge: true});
equal(editor.getContent(), 'a123bc
');
});
});