searchreplace.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. module('plugins.searchreplace');
  2. test('trace 3381:查找',function(){
  3. if(ua.browser.opera)
  4. return;
  5. var editor = te.obj[0];
  6. var range = te.obj[1];
  7. editor.setContent('<p>hello啊</p>');
  8. stop();
  9. setTimeout(function(){
  10. range.setStart(editor.body.firstChild,0).collapse(true).select();
  11. var num = editor.execCommand('searchreplace',{searchStr:'啊'});
  12. ua.manualDeleteFillData(editor.body);
  13. equal(editor.body.firstChild.innerHTML,'hello啊');
  14. equal(editor.selection.getRange().collapsed,false,'检查选区:不闭合为找到');
  15. start();
  16. },20);
  17. });
  18. //
  19. ///*trace 974,先替换再撤销再全部替换,则不会替换
  20. //* ie下会出现的bug*/
  21. test(' trace 3697全部替换',function(){
  22. //todo trace 3697
  23. if(ua.browser.opera)
  24. return;
  25. var editor = te.obj[0];
  26. var range = te.obj[1];
  27. editor.setContent('<p>欢迎回来</p>');
  28. range.setStart(editor.body.firstChild,0).collapse(true).select();
  29. editor.execCommand('searchreplace',{searchStr:'欢迎',replaceStr:'你好'});
  30. editor.undoManger.undo();
  31. editor.execCommand('searchreplace',{searchStr:'欢迎',replaceStr:'你好',all:true});
  32. ua.manualDeleteFillData(editor.body);
  33. equal(editor.body.firstChild.innerHTML,'你好回来');
  34. });
  35. ///*trace 917*/
  36. ///*trace 3288*/todo
  37. //test('替换内容包含查找内容,全部替换',function(){
  38. // if(ua.browser.opera)
  39. // return;
  40. // var editor = te.obj[0];
  41. // var range = te.obj[1];
  42. // editor.setContent('<p>hello回来</p>');
  43. // range.setStart(editor.body.firstChild,0).collapse(true).select();
  44. // /*searchreplace文件里是一个闭包,闭包中有一个全局变量currentRange,在上一次用例执行结束后仍然会保存这个值,导致下一次用例受影响*/
  45. // editor.execCommand('searchreplace',{searchStr:'hello',replaceStr:'hello啊',all:true});
  46. // ua.manualDeleteFillData(editor.body);
  47. // equal(editor.body.firstChild.innerHTML,'hello啊回来');
  48. //});
  49. /*trace 973*/
  50. test(' trace 3697替换内容包含查找内容',function(){
  51. if(ua.browser.opera)
  52. return;
  53. var editor = te.obj[0];
  54. var range = te.obj[1];
  55. editor.setContent('<p>欢迎回来</p>');
  56. range.setStart(editor.body.firstChild,0).collapse(1).select();
  57. editor.execCommand('searchreplace',{searchStr:'欢迎',replaceStr:'欢迎啊'});
  58. ua.manualDeleteFillData(editor.body);
  59. equal(editor.body.firstChild.innerHTML,'欢迎啊回来');
  60. editor.undoManger.undo();
  61. ua.manualDeleteFillData(editor.body);
  62. equal(editor.body.firstChild.innerHTML,'欢迎回来');
  63. });
  64. //
  65. ///*trace 1286*/todo
  66. //test('连续2次全部替换',function(){
  67. // if(ua.browser.opera)
  68. // return;
  69. // var editor = te.obj[0];
  70. // editor.setContent('<p>欢迎回来</p>');
  71. // editor.execCommand('searchreplace',{searchStr:'欢迎',replaceStr:'欢迎啊',all:true});
  72. // ua.manualDeleteFillData(editor.body);
  73. // equal(editor.body.firstChild.innerHTML,'欢迎啊回来');
  74. // editor.execCommand('searchreplace',{searchStr:'欢迎',replaceStr:'欢迎啊',all:true});
  75. // ua.manualDeleteFillData(editor.body);
  76. // equal(editor.body.firstChild.innerHTML,'欢迎啊啊回来');
  77. //});
  78. //
  79. test('替换内容为空',function(){
  80. if(ua.browser.opera)
  81. return;
  82. var editor = te.obj[0];
  83. editor.setContent('<p>欢迎回来</p>');
  84. stop();
  85. setTimeout(function(){
  86. editor.focus();
  87. editor.execCommand('searchreplace',{searchStr:'欢迎',replaceStr:''});
  88. ua.manualDeleteFillData(editor.body);
  89. equal(editor.body.firstChild.innerHTML,'回来');
  90. start();
  91. },50);
  92. });
  93. //
  94. test('全部替换内容为空',function(){
  95. if(ua.browser.opera)
  96. return;
  97. var editor = te.obj[0];
  98. editor.setContent('<p>欢迎回来 欢迎啊</p>');
  99. editor.execCommand('searchreplace',{searchStr:'欢迎',replaceStr:'',all:true});
  100. ua.manualDeleteFillData(editor.body);
  101. equal(editor.body.firstChild.innerHTML,'回来 啊');
  102. });
  103. //test('查找替换支持正则',function(){
  104. // if(ua.browser.opera)
  105. // return;
  106. // var editor = te.obj[0];
  107. // editor.setContent('<p>sd2323fasdfasd3434f</p>');
  108. // //因为是字符表示的正则要做转换
  109. // editor.execCommand('searchreplace',{searchStr:'/\\d+/',replaceStr:'',all:true});
  110. // ua.manualDeleteFillData(editor.body);
  111. // equal(editor.body.firstChild.innerHTML,'sdfasdfasdf');
  112. // editor.setContent('<p>sd2323fasdfasd3434f</p><p>首都发生地2323方</p>');
  113. // editor.execCommand('searchreplace',{searchStr:'/\\d+/',replaceStr:'',all:true});
  114. // ua.manualDeleteFillData(editor.body);
  115. // equal(editor.body.innerHTML.toLowerCase().replace(/>\s+</g,'><'),'<p>sdfasdfasdf</p><p>首都发生地方</p>');
  116. //});