Wordpress/tests/qunit/editor/plugins/autosave.html

105 lines
3.3 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<title>Unit tests for the Autosave 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>
</head>
<body>
<script>
var editor;
QUnit.config.reorder = false;
QUnit.config.autostart = false;
module("Autosave plugin", {
autostart: false
});
test("isEmpty true", function() {
ok(editor.plugins.autosave.isEmpty(''));
ok(editor.plugins.autosave.isEmpty(' '));
ok(editor.plugins.autosave.isEmpty('\t\t\t'));
ok(editor.plugins.autosave.isEmpty('<p id="x"></p>'));
ok(editor.plugins.autosave.isEmpty('<p></p>'));
ok(editor.plugins.autosave.isEmpty('<p> </p>'));
ok(editor.plugins.autosave.isEmpty('<p>\t</p>'));
ok(editor.plugins.autosave.isEmpty('<p><br></p>'));
ok(editor.plugins.autosave.isEmpty('<p><br /></p>'));
ok(editor.plugins.autosave.isEmpty('<p><br data-mce-bogus="true" /></p>'));
ok(editor.plugins.autosave.isEmpty('<p><br><br></p>'));
ok(editor.plugins.autosave.isEmpty('<p><br /><br /></p>'));
ok(editor.plugins.autosave.isEmpty('<p><br data-mce-bogus="true" /><br data-mce-bogus="true" /></p>'));
});
test("isEmpty false", function() {
ok(!editor.plugins.autosave.isEmpty('X'));
ok(!editor.plugins.autosave.isEmpty(' X'));
ok(!editor.plugins.autosave.isEmpty('\t\t\tX'));
ok(!editor.plugins.autosave.isEmpty('<p>X</p>'));
ok(!editor.plugins.autosave.isEmpty('<p> X</p>'));
ok(!editor.plugins.autosave.isEmpty('<p>\tX</p>'));
ok(!editor.plugins.autosave.isEmpty('<p><br>X</p>'));
ok(!editor.plugins.autosave.isEmpty('<p><br />X</p>'));
ok(!editor.plugins.autosave.isEmpty('<p><br data-mce-bogus="true" />X</p>'));
ok(!editor.plugins.autosave.isEmpty('<p><br><br>X</p>'));
ok(!editor.plugins.autosave.isEmpty('<p><br /><br />X</p>'));
ok(!editor.plugins.autosave.isEmpty('<p><br data-mce-bogus="true" /><br data-mce-bogus="true" />X</p>'));
ok(!editor.plugins.autosave.isEmpty('<h1></h1>'));
ok(!editor.plugins.autosave.isEmpty('<img src="x" />'));
});
test("hasDraft/storeDraft/restoreDraft", function() {
ok(!editor.plugins.autosave.hasDraft());
editor.setContent('X');
editor.undoManager.add();
editor.plugins.autosave.storeDraft();
ok(editor.plugins.autosave.hasDraft());
editor.setContent('Y');
editor.undoManager.add();
editor.plugins.autosave.restoreDraft();
equal(editor.getContent(), '<p>X</p>');
});
tinymce.init({
selector: "textarea",
add_unload_trigger: false,
plugins: 'autosave',
autosave_ask_before_unload: false,
init_instance_callback: function(ed) {
editor = ed;
editor.plugins.autosave.removeDraft();
QUnit.start();
}
});
</script>
<h1 id="qunit-header">Unit tests for the Table 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>
<div>
<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
</div>
</body>
</html>