133 lines
4.2 KiB
HTML
133 lines
4.2 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Unit tests for searchreplace plugin</title>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||
|
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
|
||
|
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
|
||
|
<script src="../js/qunit/reporter.js"></script>
|
||
|
<script src="../js/utils.js"></script>
|
||
|
<script src="../js/tinymce_loader.js"></script>
|
||
|
<script>
|
||
|
var editor, rng;
|
||
|
|
||
|
QUnit.config.reorder = false;
|
||
|
QUnit.config.autostart = false;
|
||
|
|
||
|
module("tinymce.SearchReplace", {
|
||
|
autostart: false
|
||
|
});
|
||
|
|
||
|
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 = 't<b>e</b><em>xt</em>';
|
||
|
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("<p>x</p>", 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("<p>x b a</p>", 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("<p>x b x</p>", 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("<p>a x</p>", 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("<p>y x</p>", 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<pre> abc </pre>abc';
|
||
|
equal(3, editor.plugins.searchreplace.find('b'));
|
||
|
equal(normalizeHtml(editor.getBody().innerHTML), (
|
||
|
'a<span class="mce-match-marker mce-match-marker-selected" data-mce-bogus="1" data-mce-index="0">b</span>c' +
|
||
|
'<pre> a<span class="mce-match-marker" data-mce-bogus="1" data-mce-index="1">b</span>c </pre>' +
|
||
|
'a<span class="mce-match-marker" data-mce-bogus="1" data-mce-index="2">b</span>c'
|
||
|
));
|
||
|
});
|
||
|
|
||
|
tinymce.init({
|
||
|
mode: "exact",
|
||
|
plugins: "searchreplace",
|
||
|
elements: "elm1",
|
||
|
add_unload_trigger: false,
|
||
|
indent: false,
|
||
|
disable_nodechange: true,
|
||
|
init_instance_callback : function(ed) {
|
||
|
editor = ed;
|
||
|
window.setTimeout(function() {
|
||
|
QUnit.start();
|
||
|
}, 0);
|
||
|
}
|
||
|
});
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<h1 id="qunit-header">Unit tests for lists plugin</h1>
|
||
|
<h2 id="qunit-banner"></h2>
|
||
|
<div id="qunit-testrunner-toolbar"></div>
|
||
|
<h2 id="qunit-userAgent"></h2>
|
||
|
<ol id="qunit-tests"></ol>
|
||
|
<textarea id="elm1" name="elm1"></textarea>
|
||
|
<a href="javascript:;" onclick="alert(tinymce.get('elm1').getContent({format: 'raw'}));return false;">[Get raw]</a>
|
||
|
</body>
|
||
|
</html>
|