From: Brion Vibber Date: Sat, 23 Jul 2011 00:44:00 +0000 (+0000) Subject: Followup r86622: add initial QUnit test cases for jquery.textSelection module. X-Git-Tag: 1.31.0-rc.0~28675 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=e072a049037505e4fac65d0fe008a289c9c33bf2;p=lhc%2Fweb%2Fwiklou.git Followup r86622: add initial QUnit test cases for jquery.textSelection module. * tests .textSelection()'s encapsulateText method mostly (also uses setSelection, getContents, and getSelection) * examples from WikiEditor toolbar: sig, bold, h2 (ownline), ulist (ownline & splitlines) * confirms that splitlines works more or less as expected, at least for basic single-line, single split-line, and multi-line cases Doesn't test the WikiEditor iframe mode since that's in a separate extension; when it's possible to test those things too, that'll need to be run there. One of the h2 tests fails in IE6, returning selected text that's offset by one character from what's expected. I'm not sure whether it's actually selecting the wrong text or whether it's returning the wrong text -- needs further investigation. Also note that there's no setContents submethod in textSelection, despite there being some notes about one. --- diff --git a/tests/qunit/index.html b/tests/qunit/index.html index f0db23c295..a5819209c3 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -47,6 +47,7 @@ + @@ -73,6 +74,7 @@ + diff --git a/tests/qunit/suites/resources/jquery/jquery.textSelection.js b/tests/qunit/suites/resources/jquery/jquery.textSelection.js new file mode 100644 index 0000000000..d231af4937 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.textSelection.js @@ -0,0 +1,216 @@ +module( 'jquery.textSelection.js' ); + +test( '-- Initial check', function() { + expect(1); + ok( $.fn.textSelection, 'jQuery.fn.textSelection defined' ); +} ); + +/** + * Test factory for $.fn.textSelection('encapsulateText') + * + * @param options {object} associative array containing: + * description {string} + * input {string} + * output {string} + * start {int} starting char for selection + * end {int} ending char for selection + * params {object} add'l parameters for $().textSelection('encapsulateText') + */ +var encapsulateTest = function( options ) { + var opt = $.extend({ + description: '', + before: {}, + after: {}, + replace: {} + }, options); + + opt.before = $.extend({ + text: '', + start: 0, + end: 0 + }, opt.before); + opt.after = $.extend({ + text: '', + selected: null + }, opt.after); + + test( opt.description, function() { + var tests = 1; + if (opt.after.selected !== null) { + tests++; + } + expect(tests); + + var $fixture = $('
'); + var $textarea = $('