module("core.Editor"); //test('getContent--2个参数,第一个参数为参数为函数', function () { // var editor = te.obj[1]; // var div = te.dom[0]; // editor.render(div); // stop(); // setTimeout(function () { // editor.focus(); // editor.setContent("
dd
dd
测试样式,红色,字体: arial black
", autoHeightEnabled: false}); editor.ready(function () { equal(ua.formatColor(ua.getComputedStyle(editor.body.firstChild.firstChild).color), '#c00000', 'initialStyle中设置的class样式有效'); ok(/arial black/.test(ua.getComputedStyle(editor.body.firstChild.firstChild).fontFamily), 'initialStyle中设置的body样式有效'); setTimeout(function () { UE.delEditor('ue'); te.dom.push(document.getElementById('ue')); start(); }, 200); }); stop(); }); test("autoSyncData:true,textarea容器(由setcontent触发的)", function () { var div = document.body.appendChild(document.createElement('div')); div.innerHTML = ''; equal(document.getElementById('form').childNodes.length, 1, 'form里只有一个子节点'); var editor_a = UE.getEditor('myEditor', {autoHeightEnabled: false}); stop(); editor_a.ready(function () { equal(document.getElementById('form').childNodes.length, 2, 'form里有2个子节点'); editor_a.setContent('设置内容autoSyncData 1
设置内容autoSyncData 1
设置内容autoSyncData 2
设置内容autoSyncData 2
hello
'; editor_a.sync("form"); setTimeout(function () { var form = document.getElementById('form'); equal(form.lastChild.value, 'hello
', '同步内容正确'); div = form.parentNode; UE.delEditor('myEditor'); div.parentNode.removeChild(div); start(); }, 100); }); }); test("hide,show", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); editor.ready(function () { equal(editor.body.getElementsByTagName('span').length, 0, '初始没有书签'); editor.hide(); setTimeout(function () { equal($(editor.container).css('display'), 'none', '隐藏编辑器'); equal(editor.body.getElementsByTagName('span').length, 1, '插入书签'); ok(/_baidu_bookmark_start/.test(editor.body.getElementsByTagName('span')[0].id), '书签'); editor.show(); setTimeout(function () { equal($(te.dom[0]).css('display'), 'block', '显示编辑器'); var br = ua.browser.ie ? '' : 'tool
', '删除书签'); start(); }, 50); }, 50); }); stop(); }); test("_setDefaultContent--focus", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); editor.ready(function () { editor._setDefaultContent('hello'); editor.fireEvent('focus'); setTimeout(function () { var br = ua.browser.ie ? '' : '' + br + '
', 'focus'); start(); }, 50); }); stop(); }); test("_setDefaultContent--firstBeforeExecCommand", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); editor.ready(function () { editor._setDefaultContent('hello'); editor.fireEvent('firstBeforeExecCommand'); setTimeout(function () { var br = ua.browser.ie ? '' : '' + br + '
', 'firstBeforeExecCommand'); start(); }, 50); }); stop(); }); test("setDisabled,setEnabled", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); editor.ready(function () { editor.setContent('欢迎使用ueditor!
'); editor.focus(); setTimeout(function () { var startContainer = editor.selection.getRange().startContainer.outerHTML; var startOffset = editor.selection.getRange().startOffset; var collapse = editor.selection.getRange().collapsed; editor.setDisabled(); setTimeout(function () { equal(editor.body.contentEditable, 'false', 'setDisabled'); equal(editor.body.firstChild.firstChild.tagName.toLowerCase(), 'span', '插入书签'); equal($(editor.body.firstChild.firstChild).css('display'), 'none', '检查style'); equal($(editor.body.firstChild.firstChild).css('line-height'), '0px', '检查style'); ok(/_baidu_bookmark_start/.test(editor.body.firstChild.firstChild.id), '书签');///_baidu_bookmark_start/.test() editor.setEnabled(); setTimeout(function () { equal(editor.body.contentEditable, 'true', 'setEnabled'); equal(ua.getChildHTML(editor.body), '欢迎使用ueditor!
', '内容恢复'); if (!ua.browser.ie || ua.browser.ie < 9) {// ie9,10改range 之后,ie9,10这里的前后range不一致,focus时是text,setEnabled后是p equal(editor.selection.getRange().startContainer.outerHTML, startContainer, '检查range'); } equal(editor.selection.getRange().startOffset, startOffset, '检查range'); equal(editor.selection.getRange().collapsed, collapse, '检查range'); start(); }, 50); }, 50); }, 50); }); stop(); }); test("render-- element", function () { var editor = new baidu.editor.Editor({'UEDITOR_HOME_URL': '../../../', 'autoFloatEnabled': false}); var div = document.body.appendChild(document.createElement('div')); equal(div.innerHTML, "", "before render"); editor.render(div); equal(div.firstChild.tagName.toLocaleLowerCase(), 'iframe', 'check iframe'); ok(/ueditor_/.test(div.firstChild.id), 'check iframe id'); te.dom.push(div); }); test("render-- elementid", function () { var editor = te.obj[1]; var div = te.dom[0]; editor.render(div.id); equal(div.firstChild.tagName.toLocaleLowerCase(), 'iframe', 'check iframe'); ok(/ueditor_/.test(div.firstChild.id), 'check iframe id'); }); test("render-- options", function () { var options = {'initialContent': 'xxxxxx
xxx
' + space + '
', 'check initialContent'); te.dom.push(div); start(); }); }); test('destroy', function () { // var editor = new baidu.editor.Editor( {'autoFloatEnabled':false} ); var editor = new UE.ui.Editor({'autoFloatEnabled': false}); editor.key = 'ed'; var div = document.body.appendChild(document.createElement('div')); div.id = 'ed'; editor.render(div); editor.ready(function () { setTimeout(function () { editor.destroy(); equal(document.getElementById('ed').tagName.toLowerCase(), 'textarea', '容器被删掉了'); document.getElementById('ed') && te.dom.push(document.getElementById('ed')); start(); }, 200); }); stop(); }); //test( "setup--ready event", function() { // //todo //} ); // test("testBindshortcutKeys", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); expect(1); editor.ready(function () { editor.addshortcutkey({ "testBindshortcutKeys": "ctrl+67"//^C }); editor.commands["testbindshortcutkeys"] = { execCommand: function (cmdName) { ok(1, '') }, queryCommandState: function () { return 0; } } ua.keydown(editor.body, {keyCode: 67, ctrlKey: true}); setTimeout(function () { start(); }, 200); }); stop(); }); test("getContent--转换空格,nbsp与空格相间显示", function () { var editor = te.obj[1]; var div = te.dom[0]; editor.render(div); stop(); editor.ready(function () { setTimeout(function () { editor.focus(); var innerHTML = 'x x x x
', "转换空格,nbsp与空格相间显示,原nbsp不变"); setTimeout(function () { // UE.delEditor('test1'); start(); }, 100); }, 100); }); }); test('getContent--参数为函数', function () { var editor = te.obj[1]; var div = te.dom[0]; editor.render(div); stop(); editor.ready(function () { editor.focus(); editor.setContent("
dd
dd
dd
dd
你好
', "删除不可见字符" ); //} ); test("setContent", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); expect(2); editor.addListener("beforesetcontent", function () { ok(true, "beforesetcontent"); }); editor.addListener("aftersetcontent", function () { ok(true, "aftersetcontent"); }); var html = 'xxemxxem
xxem
hello1
hello2
"); setTimeout(function () { editor.focus(false); setTimeout(function () { var range = editor.selection.getRange(); equal(range.startOffset, 0, "focus(false)焦点在最前面"); equal(range.endOffset, 0, "focus(false)焦点在最前面"); if (ua.browser.gecko||ua.browser.webkit) { equal(range.startContainer, editor.body.firstChild, "focus(false)焦点在最前面"); equal(range.collapsed, true, "focus(false)焦点在最前面"); } else { equal(range.startContainer, editor.body.firstChild.firstChild, "focus(false)焦点在最前面"); equal(range.endContainer, editor.body.firstChild.firstChild, "focus(false)焦点在最前面"); } start(); }, 200); }, 100); }); }); test("focus(true)", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.setContent("hello1
hello2
"); setTimeout(function () { editor.focus(true); setTimeout(function () { if (ua.browser.gecko||ua.browser.webkit) { equal(editor.selection.getRange().startContainer, editor.body.lastChild, "focus( true)焦点在最后面"); equal(editor.selection.getRange().endContainer, editor.body.lastChild, "focus( true)焦点在最后面"); equal(editor.selection.getRange().startOffset, editor.body.lastChild.childNodes.length, "focus( true)焦点在最后面"); equal(editor.selection.getRange().endOffset, editor.body.lastChild.childNodes.length, "focus( true)焦点在最后面"); } else { equal(editor.selection.getRange().startContainer, editor.body.lastChild.lastChild, "focus( true)焦点在最后面"); equal(editor.selection.getRange().endContainer, editor.body.lastChild.lastChild, "focus( true)焦点在最后面"); equal(editor.selection.getRange().startOffset, editor.body.lastChild.lastChild.length, "focus( true)焦点在最后面"); equal(editor.selection.getRange().endOffset, editor.body.lastChild.lastChild.length, "focus( true)焦点在最后面"); } start(); }, 200); }, 100); }); }); test("isFocus()", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); setTimeout(function () { ok(editor.isFocus()); start(); }, 200); }); }); test("blur()", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); ok(editor.isFocus()); editor.blur(); ok(!editor.isFocus()); editor.blur();//多次使用不报错 ok(!editor.isFocus()); start(); }); }); test("_initEvents,_proxyDomEvent--click", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); expect(1); stop(); editor.addListener('click', function () { ok(true, 'click event dispatched'); start(); }); ua.click(editor.document); }); }); //test("_initEvents,_proxyDomEvent--focus", function() { // var editor = te.obj[1]; // // expect(1); stop(); // editor.addListener('focus', function() { // ok(true, 'focus event dispatched'); // start(); // }); // editor.setContent("hello1
hello2
"); // editor.focus(); //}); ////TODO //test( "_selectionChange--测试event是否被触发", function() { // var editor = te.obj[1]; // var div = te.dom[0]; // editor.render( div ); // editor.focus(); // expect( 2 ); // stop(); // editor.addListener( 'beforeselectionchange', function() { // ok( true, 'before selection change' ); // } ); // editor.addListener( 'selectionchange', function() { // ok( true, 'selection changed' ); // } ); // // ua.mousedown( editor.document, {clientX:0,clientY:0} ); // setTimeout( function() { // ua.mouseup( editor.document, {clientX:0,clientY:0} ); // }, 50 ); // // /*_selectionChange有一定的延时才会触发,所以需要等一会*/ // setTimeout( function() { // start(); // }, 200 ); //} ); //test("_selectionChange--fillData", function() { // var editor = te.obj[1]; // var div = te.dom[0]; // editor.focus(); // //TODO fillData干嘛用的 //}); /*按钮高亮、正常和灰色*/ test("queryCommandState", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); editor.setContent("xxxxxx
"); var p = editor.document.getElementsByTagName('p')[0]; var r = new baidu.editor.dom.Range(editor.document); r.setStart(p.firstChild, 0).setEnd(p.firstChild, 1).select(); equal(editor.queryCommandState('bold'), 1, '加粗状态为1'); r.setStart(p, 1).setEnd(p, 2).select(); setTimeout(function () { equal(editor.queryCommandState('bold'), 0, '加粗状态为0'); start(); }, 100); }); }); test("queryCommandValue", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); editor.setContent('xxx
'); var range = new baidu.editor.dom.Range(editor.document); var p = editor.document.getElementsByTagName("p")[0]; range.selectNode(p).select(); equal(editor.queryCommandValue('justify'), 'left', 'text align is left'); start(); }); }); test("execCommand", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); editor.setContent("xx
xxx
"); var doc = editor.document; var range = new baidu.editor.dom.Range(doc); var p = doc.getElementsByTagName('p')[1]; range.setStart(p, 0).setEnd(p, 1).select(); editor.execCommand('justify', 'right'); equal($(p).css('text-align'), 'right', 'execCommand align'); /*给span加style不会重复添加span*/ range.selectNode(p).select(); editor.execCommand("forecolor", "red"); /*span发生了变化,需要重新获取*/ var span = doc.getElementsByTagName('span')[0]; equal(span.style['color'], 'red', 'check execCommand color'); var div_new = document.createElement('div'); div_new.innerHTML = 'xx
xxx
'; var div1 = document.createElement('div'); div1.innerHTML = editor.body.innerHTML; ok(ua.haveSameAllChildAttribs(div_new, div1), 'check style'); start(); }); }); test("hasContents", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); editor.setContent(''); ok(!editor.hasContents(), "have't content"); editor.setContent("xxx"); ok(editor.hasContents(), "has contents"); editor.setContent('\t\n
" ); // ok( editor.hasContents(), "空格不过滤" ); //} ); /*参数是对原有认为是空的标签的一个扩展,即原来的dtd认为br为空,加上这个参数可以认为br存在时body也不是空*/ test("hasContents--有参数", function () { var editor = te.obj[1]; var container = te.dom[0]; $(container).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc'); editor.render(container); stop(); editor.ready(function () { editor.focus(); editor.setContent('你好
hell\no
hello