module("plugins.basestyle"); test('sub--table', function () { var editor = te.obj[0]; setTimeout(function () { editor.setContent('
hello1 | hello2 |
hello3 | hello4 |
你好
'); var body = editor.body; stop(); setTimeout(function () { range.setStart(body.firstChild.firstChild, 1).collapse(1).select(true); editor.execCommand('superscript'); equal(ua.getChildHTML(body.firstChild), '你好', '查看执行上标后的结果'); range = editor.selection.getRange(); range.insertNode(editor.document.createTextNode('hello')); equal(ua.getChildHTML(body.firstChild), '你hello好', '上标标签中插入文本'); start(); }, 100) }); test('不闭合插入上下标', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('hello1hello2baidu_linkhello3'); var body = editor.document.body; stop(); setTimeout(function () { range.setStart(body.firstChild.firstChild, 0).setEnd(body.firstChild.lastChild, 3).select(); editor.execCommand('superscript'); ua.manualDeleteFillData(body); ua.checkSameHtml(editor.getContent(), 'hello1hello2baidu_linkhello3
', '普通文本添加上标'); start(); }, 100); }); /*trace 870*/ //无法模拟光标自动移到的场景,因此模拟输入文本通过插入文本节点实现的方法,在插入文本后光标仍然在原来的位置 // 我们不确定光标实际在哪 test('trace 870:加粗文本前面去加粗', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; editor.setContent('hello2hello
hellohello2
this is a dog
'); stop(); setTimeout(function () { range.selectNode(body.firstChild).select(); editor.execCommand('bold'); range.setStart(body.firstChild.firstChild.firstChild, 2).collapse(true).select(); equal(editor.queryCommandState('bold'), 1, '闭合选择,加粗高亮'); ua.manualDeleteFillData(editor.body); range.setStart(body.firstChild.firstChild.firstChild, 0).setEnd(body.firstChild.firstChild.lastChild, 4).select(); equal(editor.queryCommandState('bold'), 1, '不闭合选择,加粗高亮'); start(); }, 100) }); /*trace 580*/ test('bold-连续加粗2次', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; editor.setContent('this is a dog
'); var text = body.firstChild.firstChild; range.setStart(text, 0).setEnd(text, 3).select(); editor.execCommand('bold'); /*第一次加粗*/ equal(editor.queryCommandState('bold'), 1, '加粗按钮高亮'); text = body.firstChild.lastChild; range.setStart(text, 1).setEnd(text, 3).select(); /*不闭合选区文本*/ equal(editor.queryCommandState('bold'), 0, '不闭合选择,加粗不高亮'); ua.manualDeleteFillData(editor.body); editor.execCommand('bold'); /*第二次加粗*/ equal(editor.queryCommandState('bold'), 1, '加粗高亮'); }); /*trace 1983*/ test('bold-2个单词,中间有空格第一个单词加粗,第二个单词加粗再去加粗', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; body.innerHTML = 'hello world
'; //用setContent复现不了这个问题 var text = body.firstChild.firstChild; range.setStart(text, 0).setEnd(text, 5).select(); editor.execCommand('bold'); text = body.firstChild.lastChild; range.setStart(text, 1).setEnd(text, 6).select(); editor.execCommand('bold'); editor.execCommand('bold'); ok(body.firstChild.childNodes.length == 3 && body.firstChild.childNodes[1].length == 1, '空格保留'); }); test('测试 userAction.manualdeleteFilldata', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; editor.setContent(''); var fillData = editor.document.createTextNode(domUtils.fillChar); // 在ie 6,7下,使用appendChild时,需要body先加载,必须将上句document前加editor,否则出错 body.appendChild(fillData); var space = ua.browser.ie ? ' ' : '' + space + '
', '清除不可见字符前不相等'); ua.manualDeleteFillData(body); equal(body.innerHTML.toLowerCase(), '' + space + '
', '清除不可见字符后相等'); }); test('trace 1884:单击B再单击I ', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; editor.setContent(''); range.setStart(body.firstChild, 0).collapse(1).select(); editor.execCommand('bold'); equal(editor.queryCommandState('bold'), 1, 'b高亮'); editor.execCommand('italic'); equal(editor.queryCommandState('italic'), 1, 'b高亮'); }); test('单击B再在其他地方单击I,空的strong标签被删除 ', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; editor.setContent('hello
'); range.setStart(body.firstChild, 0).collapse(1).select(); editor.execCommand('bold'); equal(editor.queryCommandState('bold'), 1, 'b高亮'); range.setStart(body.firstChild, 1).collapse(1).select(); editor.execCommand('italic'); equal(editor.queryCommandState('italic'), 1, 'b高亮'); ua.manualDeleteFillData(body); if (!ua.browser.ie) { //ie下有问题不能修,屏蔽ie equal(body.innerHTML.toLowerCase(), 'hello
', '空strong标签被删除') } }); test('ctrl+i', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; editor.setContent('没有加粗的文本
'); range.selectNode(body.firstChild).select(); var p = body.firstChild; setTimeout(function () { ua.keydown(editor.body, {'keyCode': 73, 'ctrlKey': true}); editor.focus(); setTimeout(function () { equal(ua.getChildHTML(p), '没有加粗的文本'); start(); }, 150); }, 100); stop(); }); test('ctrl+u', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; editor.setContent('没有加粗的文本
'); setTimeout(function () { range.selectNode(body.firstChild).select(); setTimeout(function () { var html = '没有加粗的文本'; ua.checkHTMLSameStyle(html, editor.document, body.firstChild, '文本被添加了下划线'); equal(editor.body.firstChild.firstChild.style.textDecoration, 'underline'); start(); }, 150); ua.keydown(editor.body, {'keyCode': 85, 'ctrlKey': true}); }, 150); stop(); }); test('ctrl+b', function () { var editor = te.obj[0]; var body = editor.body; var range = te.obj[1]; editor.setContent('没有加粗的文本
'); range.selectNode(body.firstChild).select(); setTimeout(function () { ua.keydown(editor.body, {'keyCode': 66, 'ctrlKey': true}); setTimeout(function () { equal(ua.getChildHTML(body.firstChild), '没有加粗的文本'); start(); }, 150); }, 150); stop(); }); /*trace 3240*/ test('表格中文本加粗', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent(''); range.setStart(editor.body.firstChild, 0).collapse(true).select(); editor.execCommand('inserttable'); ua.manualDeleteFillData(editor.body); setTimeout(function () { var tds = editor.body.getElementsByTagName('td'); tds[0].innerHTML = 'asd'; tds[10].innerHTML = 'asd'; var trs = editor.body.firstChild.getElementsByTagName('tr'); var ut = editor.getUETable(editor.body.firstChild); var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[2].cells[0]); ut.setSelected(cellsRange); range.setStart(trs[0].cells[0], 0).collapse(true).select(); editor.execCommand('bold'); ua.manualDeleteFillData(editor.body); equal(editor.queryCommandState('bold'), 1, 'b高亮'); equal(trs[0].cells[0].firstChild.tagName.toLowerCase(), 'strong', '[0][0]单元格中文本标签'); if (!ua.browser.ie) equal(trs[1].cells[0].firstChild.tagName.toLowerCase(), 'br', '[1][0]单元格中文本标签'); equal(trs[2].cells[0].firstChild.tagName.toLowerCase(), 'strong', '[2][0]单元格中文本标签'); start(); }, 50); stop(); });