X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fqunit%2Fsuites%2Fresources%2Fjquery%2Fjquery.textSelection.test.js;h=5fe239448f005916904636a604c50247a0047e73;hb=bad8847147778997818a2cbdd8c1ea0d5fe7ac65;hp=1795b95a6b30c558750a85f49d314e75c72a5224;hpb=b3e457400b48d58725a6a49eb0678743ee646f81;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js index 1795b95a6b..5fe239448f 100644 --- a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js @@ -14,22 +14,22 @@ * params {object} add'l parameters for $().textSelection( 'encapsulateText' ) */ function encapsulateTest( options ) { - var opt = $.extend({ + var opt = $.extend( { description: '', before: {}, after: {}, replace: {} - }, options); + }, options ); - opt.before = $.extend({ + opt.before = $.extend( { text: '', start: 0, end: 0 - }, opt.before); - opt.after = $.extend({ + }, opt.before ); + opt.after = $.extend( { text: '', selected: null - }, opt.after); + }, opt.after ); QUnit.test( opt.description, function ( assert ) { /*jshint onevar: false */ @@ -46,15 +46,8 @@ //$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm... $textarea.val( opt.before.text ); // won't work with the WikiEditor iframe? - var start = opt.before.start, + var start = opt.before.start, end = opt.before.end; - if ( window.opera ) { - // Compensate for Opera's craziness converting \n to \r\n and counting that as two chars - var newLinesBefore = opt.before.text.substring( 0, start ).split( '\n' ).length - 1, - newLinesInside = opt.before.text.substring( start, end ).split( '\n' ).length - 1; - start += newLinesBefore; - end += newLinesBefore + newLinesInside; - } var options = $.extend( {}, opt.replace ); // Clone opt.replace options.selectionStart = start; @@ -98,7 +91,7 @@ splitlines: true }; - encapsulateTest({ + encapsulateTest( { description: 'Adding sig to end of text', before: { text: 'Wikilove dude! ', @@ -110,9 +103,9 @@ selected: '' }, replace: sig - }); + } ); - encapsulateTest({ + encapsulateTest( { description: 'Adding bold to empty', before: { text: '', @@ -124,9 +117,9 @@ selected: 'Bold text' // selected because it's the default }, replace: bold - }); + } ); - encapsulateTest({ + encapsulateTest( { description: 'Adding bold to existing text', before: { text: 'Now is the time for all good men to come to the aid of their country', @@ -138,12 +131,12 @@ selected: '' // empty because it's not the default' }, replace: bold - }); + } ); - encapsulateTest({ + encapsulateTest( { description: 'ownline option: adding new h2', before: { - text:'Before\nAfter', + text: 'Before\nAfter', start: 7, end: 7 }, @@ -152,12 +145,12 @@ selected: 'Heading 2' }, replace: h2 - }); + } ); - encapsulateTest({ + encapsulateTest( { description: 'ownline option: turn a whole line into new h2', before: { - text:'Before\nMy heading\nAfter', + text: 'Before\nMy heading\nAfter', start: 7, end: 17 }, @@ -166,13 +159,13 @@ selected: '' }, replace: h2 - }); + } ); - encapsulateTest({ + encapsulateTest( { description: 'ownline option: turn a partial line into new h2', before: { - text:'BeforeMy headingAfter', + text: 'BeforeMy headingAfter', start: 6, end: 16 }, @@ -181,10 +174,10 @@ selected: '' }, replace: h2 - }); + } ); - encapsulateTest({ + encapsulateTest( { description: 'splitlines option: no selection, insert new list item', before: { text: 'Before\nAfter', @@ -195,9 +188,9 @@ text: 'Before\n* Bulleted list item\nAfter' }, replace: ulist - }); + } ); - encapsulateTest({ + encapsulateTest( { description: 'splitlines option: single partial line selection, insert new list item', before: { text: 'BeforeMy List ItemAfter', @@ -208,9 +201,9 @@ text: 'Before\n* My List Item\nAfter' }, replace: ulist - }); + } ); - encapsulateTest({ + encapsulateTest( { description: 'splitlines option: multiple lines', before: { text: 'Before\nFirst\nSecond\nThird\nAfter', @@ -221,7 +214,7 @@ text: 'Before\n* First\n* Second\n* Third\nAfter' }, replace: ulist - }); + } ); function caretTest( options ) { @@ -231,52 +224,52 @@ $( '#qunit-fixture' ).append( $textarea ); if ( options.mode === 'set' ) { - $textarea.textSelection('setSelection', { + $textarea.textSelection( 'setSelection', { start: options.start, end: options.end - }); + } ); } function among( actual, expected, message ) { if ( $.isArray( expected ) ) { - assert.ok( $.inArray( actual, expected ) !== -1 , message + ' (got ' + actual + '; expected one of ' + expected.join(', ') + ')' ); + assert.ok( $.inArray( actual, expected ) !== -1, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' ); } else { assert.equal( actual, expected, message ); } } - pos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true }); - among(pos[0], options.start, 'Caret start should be where we set it.'); - among(pos[1], options.end, 'Caret end should be where we set it.'); - }); + pos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true } ); + among( pos[0], options.start, 'Caret start should be where we set it.' ); + among( pos[1], options.end, 'Caret end should be where we set it.' ); + } ); } caretSample = 'Some big text that we like to work with. Nothing fancy... you know what I mean?'; /* - // @broken: Disabled per bug 34820 - caretTest({ - description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8', - text: caretSample, - start: [0, caretSample.length], // Opera and Firefox (prior to FF 6.0) default caret to the end of the box (caretSample.length) - end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both. - mode: 'get' - }); - */ + // @broken: Disabled per bug 34820 + caretTest({ + description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8', + text: caretSample, + start: [0, caretSample.length], // Opera and Firefox (prior to FF 6.0) default caret to the end of the box (caretSample.length) + end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both. + mode: 'get' + }); + */ - caretTest({ + caretTest( { description: 'set/getCaretPosition with forced empty selection', text: caretSample, start: 7, end: 7, mode: 'set' - }); + } ); - caretTest({ + caretTest( { description: 'set/getCaretPosition with small selection', text: caretSample, start: 6, end: 11, mode: 'set' - }); + } ); }( jQuery ) );