diff --git a/test/loader.js b/test/loader.js index 14cd175..5fa9de7 100644 --- a/test/loader.js +++ b/test/loader.js @@ -87,7 +87,7 @@ define(function () { 'inputs/wysihtml5/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.min'], init: function(require) { loadCss(require.toUrl("./bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.css")); - loadCss(require.toUrl("./bootstrap-wysihtml5-0.0.2/wysiwyg-color.css")); + //loadCss(require.toUrl("./bootstrap-wysihtml5-0.0.2/wysiwyg-color.css")); } }, diff --git a/test/main.js b/test/main.js index ffe7492..ee32ab3 100644 --- a/test/main.js +++ b/test/main.js @@ -27,15 +27,15 @@ require(["loader", jqurl], function(loader) { }); function addTests(config) { - var date; + var custom; switch(params.f) { case 'bootstrap': - date = ['test/unit/datefield', 'test/unit/date']; + custom = ['test/unit/datefield', 'test/unit/date', 'test/unit/wysihtml5']; break; default: - date = ['test/unit/dateuifield', 'test/unit/dateui']; + custom = ['test/unit/dateuifield', 'test/unit/dateui']; } var tests = [ @@ -46,7 +46,7 @@ require(["loader", jqurl], function(loader) { 'test/unit/select', 'test/unit/checklist' ]; - tests = tests.concat(date); + tests = tests.concat(custom); tests.push('test/unit/api'); for(var i=0; i<tests.length-1; i++) { diff --git a/test/unit/wysihtml5.js b/test/unit/wysihtml5.js new file mode 100644 index 0000000..0ef343d --- /dev/null +++ b/test/unit/wysihtml5.js @@ -0,0 +1,54 @@ +$(function () { + + module("wysihtml5", { + setup: function(){ + fx = $('#async-fixture'); + $.support.transition = false; + } + }); + + asyncTest("should load correct value and save new entered value", function () { + var v1 = '<h1>qq</h1><br>qwerty', + v2 = '11<h2>werqwr</h2>4353', + e = $('<a href="#" data-pk="1" data-url="post.php">'+v1+'</a>').appendTo(fx).editable({ + type: 'wysihtml5', + success: function(response, newvalue) { + // construction: replace(/\s*\n(?!\r)/g, "") required to clear newlines added in ie8 + equal(newvalue.toLowerCase().replace(/\s*\n(?!\r)/g, ""), v2, 'value in success ok'); + } + }); + + e.click(); + + setTimeout(function() { + + var p = tip(e); + ok(p.is(':visible'), 'container visible'); + ok(p.find('textarea').is(':hidden'), 'textarea hidden'); + ok(p.find('iframe').length, 'iframe shown'); + ok(p.find('.wysihtml5-toolbar').length, 'toolbar shown'); + + equal(p.find('textarea').val().toLowerCase(), v1.toLowerCase(), 'textrea val correct'); + + var iframe = document.querySelectorAll('.wysihtml5-sandbox'), + $c = $(iframe[0]).contents().find('body'); + + equal($c.html().toLowerCase(), v1.toLowerCase(), 'content correct'); + + //set new value, should wait async while it render to iframe + $c.html(v2); + setTimeout(function() { + p.find('form').submit(); + setTimeout(function() { + ok(!p.is(':visible'), 'popover closed'); + equal(e.data('editable').value.toLowerCase().replace(/\s*\n(?!\r)/g, ""), v2, 'new text saved to value'); + equal(e.html().toLowerCase().replace(/\s*\n(?!\r)/g, ""), v2.toLowerCase(), 'new text shown'); + e.remove(); + start(); + }, timeout); + }, 800); + }, 800); + + }); + +}); \ No newline at end of file