convertcase.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. module("plugins.convertcase");
  2. test('闭合选择', function () {
  3. stop();
  4. setTimeout(function () {
  5. var editor = te.obj[0];
  6. var range = te.obj[1];
  7. var body = editor.body;
  8. editor.setContent('<p>hello</p>');
  9. setTimeout(function () {
  10. range.setStart(body.firstChild, 1).collapse(true).select();
  11. editor.execCommand("touppercase");
  12. equal(editor.getContent(), "<p>hello</p>", "闭合选择--up");
  13. start();
  14. }, 50);
  15. }, 100);
  16. });
  17. test('非闭合选择----字符串全选', function () {
  18. var editor = te.obj[0];
  19. var range = te.obj[1];
  20. var body = editor.body;
  21. editor.setContent('<p>hello1</p><p>hello2</p>');
  22. setTimeout(function () {
  23. range.setStart(body.firstChild, 0).setEnd(body.lastChild, 1).select();
  24. editor.execCommand("touppercase");
  25. equal(editor.getContent(), "<p>HELLO1</p><p>HELLO2</p>", "非闭合--字符串全选--up");
  26. editor.execCommand("touppercase");
  27. equal(editor.getContent(), "<p>HELLO1</p><p>HELLO2</p>", "非闭合--两次up");
  28. editor.execCommand("tolowercase");
  29. equal(editor.getContent(), "<p>hello1</p><p>hello2</p>", "非闭合--字符串全选--low");
  30. editor.execCommand("tolowercase");
  31. equal(editor.getContent(), "<p>hello1</p><p>hello2</p>", "非闭合---两次low");
  32. start();
  33. }, 50);
  34. stop();
  35. });
  36. test('非闭合选择----子字符串', function () {
  37. var editor = te.obj[0];
  38. var range = te.obj[1];
  39. var body = editor.body;
  40. editor.setContent('<p>hello1</p><p>hello2</p>');
  41. setTimeout(function () {
  42. range.setStart(body.firstChild.firstChild, 2).setEnd(body.lastChild.firstChild, 2).select();
  43. editor.execCommand("touppercase");
  44. equal(editor.getContent(), "<p>heLLO1</p><p>HEllo2</p>", "非闭合--子字符串--up");
  45. editor.execCommand("tolowercase");
  46. equal(editor.getContent(), "<p>hello1</p><p>hello2</p>", "非闭合--子字符串--low");
  47. start();
  48. }, 50);
  49. stop();
  50. });
  51. test('非闭合选择----字符串包括大写跟小写', function () {
  52. var editor = te.obj[0];
  53. var range = te.obj[1];
  54. var body = editor.body;
  55. var text = "<p>HEllo1</p><p>heLLo2</p>";
  56. editor.setContent(text);
  57. setTimeout(function () {
  58. range.setStart(body.firstChild.firstChild, 0).setEnd(body.lastChild.firstChild, 6).select();
  59. editor.execCommand("touppercase");
  60. equal(editor.getContent(), "<p>HELLO1</p><p>HELLO2</p>", "非闭合--包含大小写--up");
  61. editor.setContent(text);
  62. setTimeout(function () {
  63. range.setStart(body.firstChild.firstChild, 0).setEnd(body.lastChild.firstChild, 6).select();
  64. editor.execCommand("tolowercase");
  65. equal(editor.getContent(), "<p>hello1</p><p>hello2</p>", "非闭合--包含大小写--low");
  66. start();
  67. }, 50);
  68. }, 50);
  69. stop();
  70. });
  71. test('非闭合选择----字符串包括换行跟空格', function () {
  72. if (ua.browser.ie == 9)return;//TODO 1.2.6
  73. if (ua.browser.ie == 8)return;//TODO 1.2.6 PUBLICGE-3402
  74. var editor = te.obj[0];
  75. var range = te.obj[1];
  76. var body = editor.body;
  77. editor.setContent('<p>HEllo1<br/> heLLO2</p>');
  78. setTimeout(function () {
  79. range.setStart(body.firstChild.firstChild, 0).setEnd(body.firstChild.lastChild, 6).select();
  80. editor.execCommand("touppercase");
  81. equal(editor.getContent(), "<p>HELLO1<br/> HELLO2</p>", "非闭合--包含大小写--up");
  82. editor.execCommand("tolowercase");
  83. equal(editor.getContent(), "<p>hello1<br/> hello2</p>", "非闭合--包含大小写--low");
  84. start();
  85. }, 50);
  86. stop();
  87. });
  88. test('标签table', function () {
  89. //单个单元格,多个单元格,两个表格
  90. var editor = te.obj[0];
  91. var range = te.obj[1];
  92. var body = editor.body;
  93. var text = "<table><tr><td>hello1</td><td>hello2</td></tr><tr><td>hello3</td><td>hello4</td></tr></table>";
  94. editor.setContent(text);
  95. stop();
  96. setTimeout(function () {
  97. var tds = body.firstChild.getElementsByTagName('td');
  98. range.selectNode(tds[1]).select();
  99. editor.execCommand("touppercase");
  100. equal(tds[1].innerHTML, "HELLO2", "table--up");
  101. editor.execCommand("tolowercase");
  102. equal(tds[1].innerHTML, "hello2", "table--low");
  103. range.setStart(tds[1], 0).setEnd(tds[2], 1).select();
  104. editor.execCommand("touppercase");
  105. equal(tds[1].innerHTML, "HELLO2", "table--单元格2--up");
  106. equal(tds[2].innerHTML, "HELLO3", "table--单元格3--up");
  107. editor.execCommand("tolowercase");
  108. equal(tds[1].innerHTML, "hello2", "table--单元格2--low");
  109. equal(tds[2].innerHTML, "hello3", "table--单元格3--low");
  110. range.setStart(tds[0], 0).setEnd(tds[3], 1).select();
  111. editor.execCommand("touppercase");
  112. equal(tds[0].innerHTML, "HELLO1", "table--单元格1--up");
  113. equal(tds[1].innerHTML, "HELLO2", "table--单元格2--up");
  114. equal(tds[2].innerHTML, "HELLO3", "table--单元格3--up");
  115. equal(tds[3].innerHTML, "HELLO4", "table--单元格4--up");
  116. editor.execCommand("tolowercase");
  117. equal(tds[0].innerHTML, "hello1", "table--单元格1--low");
  118. equal(tds[1].innerHTML, "hello2", "table--单元格2--low");
  119. equal(tds[2].innerHTML, "hello3", "table--单元格3--low");
  120. equal(tds[3].innerHTML, "hello4", "table--单元格4--low");
  121. start();
  122. }, 50);
  123. });
  124. test('标签h1', function () {
  125. var editor = te.obj[0];
  126. var range = te.obj[1];
  127. var body = editor.body;
  128. editor.setContent('<h1>hello1</h1><h1>hello2</h1>');
  129. range.setStart(body.firstChild.firstChild, 2).setEnd(body.lastChild.firstChild, 2).select();
  130. editor.execCommand("touppercase");
  131. equal(editor.getContent(), "<h1>heLLO1</h1><h1>HEllo2</h1>", "h1--up");
  132. editor.execCommand("tolowercase");
  133. equal(editor.getContent(), "<h1>hello1</h1><h1>hello2</h1>", "h1--low");
  134. });
  135. test('h1&table', function () {
  136. var editor = te.obj[0];
  137. var range = te.obj[1];
  138. var body = editor.body;
  139. var text = "<h1>hello</h1><table><tbody><tr><td>hello1</td><td>hello2</td></tr><tr><td>hello3</td><td>hello4</td></tr></tbody></table>";
  140. editor.setContent(text);
  141. stop();
  142. setTimeout(function () {
  143. range.setStart(body.firstChild.firstChild, 0).setEnd(body.lastChild.firstChild.lastChild.lastChild.firstChild, 6).select();
  144. var tds = body.lastChild.getElementsByTagName('td');
  145. editor.execCommand("touppercase");
  146. ok(body.firstChild.tagName == "h1" || body.firstChild.tagName == "H1", "h1标签");
  147. equal(body.firstChild.innerHTML, "HELLO", "h1--up");
  148. equal(tds[0].innerHTML, "HELLO1", "table--单元格1--up");
  149. equal(tds[1].innerHTML, "HELLO2", "table--单元格2--up");
  150. equal(tds[2].innerHTML, "HELLO3", "table--单元格3--up");
  151. equal(tds[3].innerHTML, "HELLO4", "table--单元格4--up");
  152. editor.execCommand("tolowercase");
  153. ok(body.firstChild.tagName == "h1" || body.firstChild.tagName == "H1", "h1标签");
  154. equal(body.firstChild.innerHTML, "hello", "h1--low");
  155. equal(tds[0].innerHTML, "hello1", "table--单元格1--low");
  156. equal(tds[1].innerHTML, "hello2", "table--单元格2--low");
  157. equal(tds[2].innerHTML, "hello3", "table--单元格3--low");
  158. equal(tds[3].innerHTML, "hello4", "table--单元格4--low");
  159. start();
  160. }, 50);
  161. });
  162. test('三个组合', function () {
  163. var editor = te.obj[0];
  164. var range = te.obj[1];
  165. var body = editor.body;
  166. var text = "<p>hello</p><table><tbody><tr><td>hello1</td><td>hello2</td></tr><tr><td>hello3</td><td>hello4</td></tr></tbody></table><h1>hello</h1>";
  167. editor.setContent(text);
  168. var tds = body.firstChild.nextSibling.getElementsByTagName('td');
  169. range.setStart(body.firstChild.firstChild, 2).setEnd(body.lastChild.firstChild, 2).select();
  170. editor.execCommand("touppercase");
  171. ok(body.firstChild.tagName == "p" || body.firstChild.tagName == "P", "p标签");
  172. equal(body.firstChild.innerHTML, "heLLO", "p--up");
  173. equal(tds[0].innerHTML, "HELLO1", "table--单元格1--up");
  174. equal(tds[1].innerHTML, "HELLO2", "table--单元格2--up");
  175. equal(tds[2].innerHTML, "HELLO3", "table--单元格3--up");
  176. equal(tds[3].innerHTML, "HELLO4", "table--单元格4--up");
  177. ok(body.lastChild.tagName == "h1" || body.lastChild.tagName == "H1", "h1标签");
  178. equal(body.lastChild.innerHTML, "HEllo", "h1--up");
  179. editor.execCommand("tolowercase");
  180. ok(body.firstChild.tagName == "p" || body.firstChild.tagName == "P", "p标签");
  181. equal(body.firstChild.innerHTML, "hello", "p--low");
  182. equal(tds[0].innerHTML, "hello1", "table--单元格1--low");
  183. equal(tds[1].innerHTML, "hello2", "table--单元格2--low");
  184. equal(tds[2].innerHTML, "hello3", "table--单元格3--low");
  185. equal(tds[3].innerHTML, "hello4", "table--单元格4--low");
  186. ok(body.lastChild.tagName == "h1" || body.lastChild.tagName == "H1", "h1标签");
  187. equal(body.lastChild.innerHTML, "hello", "h1--low");
  188. });