module("tinymce.plugins.SearchReplace", { setupModule: function() { QUnit.stop(); tinymce.init({ selector: "textarea", plugins: "searchreplace", elements: "elm1", add_unload_trigger: false, skin: false, indent: false, disable_nodechange: true, init_instance_callback : function(ed) { window.editor = ed; window.setTimeout(function() { QUnit.start(); }, 0); } }); } }); test('Find no match', function() { editor.getBody().innerHTML = 'a'; equal(0, editor.plugins.searchreplace.find('x')); }); test('Find single match', function() { editor.getBody().innerHTML = 'a'; equal(1, editor.plugins.searchreplace.find('a')); }); test('Find single match in multiple elements', function() { editor.getBody().innerHTML = 'text'; equal(1, editor.plugins.searchreplace.find('text')); }); test('Find single match, match case: true', function() { editor.getBody().innerHTML = 'a A'; equal(1, editor.plugins.searchreplace.find('A', true)); }); test('Find single match, whole words: true', function() { editor.getBody().innerHTML = 'a Ax'; equal(1, editor.plugins.searchreplace.find('a', false, true)); }); test('Find multiple matches', function() { editor.getBody().innerHTML = 'a b A'; equal(2, editor.plugins.searchreplace.find('a')); }); test('Find and replace single match', function() { editor.getBody().innerHTML = 'a'; editor.plugins.searchreplace.find('a'); ok(!editor.plugins.searchreplace.replace('x')); equal("

x

", editor.getContent()); }); test('Find and replace first in multiple matches', function() { editor.getBody().innerHTML = 'a b a'; editor.plugins.searchreplace.find('a'); ok(editor.plugins.searchreplace.replace('x')); equal("

x b a

", editor.getContent()); }); test('Find and replace all in multiple matches', function() { editor.getBody().innerHTML = 'a b a'; editor.plugins.searchreplace.find('a'); ok(!editor.plugins.searchreplace.replace('x', true, true)); equal("

x b x

", editor.getContent()); }); test('Find multiple matches, move to next and replace', function() { editor.getBody().innerHTML = 'a a'; equal(2, editor.plugins.searchreplace.find('a')); editor.plugins.searchreplace.next(); ok(!editor.plugins.searchreplace.replace('x')); equal("

a x

", editor.getContent()); }); test('Find multiple matches, move to next and replace backwards', function() { editor.getBody().innerHTML = 'a a'; equal(2, editor.plugins.searchreplace.find('a')); editor.plugins.searchreplace.next(); ok(editor.plugins.searchreplace.replace('x', false)); ok(!editor.plugins.searchreplace.replace('y', false)); equal("

y x

", editor.getContent()); }); test('Find multiple matches and unmark them', function() { editor.getBody().innerHTML = 'a b a'; equal(2, editor.plugins.searchreplace.find('a')); editor.plugins.searchreplace.done(); equal('a', editor.selection.getContent()); equal(0, editor.getBody().getElementsByTagName('span').length); }); test('Find multiple matches with pre blocks', function() { editor.getBody().innerHTML = 'abc
  abc  
abc'; equal(3, editor.plugins.searchreplace.find('b')); equal(Utils.normalizeHtml(editor.getBody().innerHTML), ( 'abc' + '
  abc  
' + 'abc' )); });