-module( 'jquery.textSelection' );
-
-test( '-- Initial check', function() {
- expect(1);
- ok( $.fn.textSelection, 'jQuery.fn.textSelection defined' );
-} );
+QUnit.module( 'jquery.textSelection', QUnit.newMwEnvironment() );
/**
* Test factory for $.fn.textSelection( 'encapsulateText' )
* end {int} ending char for selection
* params {object} add'l parameters for $().textSelection( 'encapsulateText' )
*/
-var encapsulateTest = function( options ) {
+function encapsulateTest( options ) {
var opt = $.extend({
description: '',
before: {},
selected: null
}, opt.after);
- test( opt.description, function() {
+ QUnit.test( opt.description, function ( assert ) {
var tests = 1;
- if (opt.after.selected !== null) {
+ if ( opt.after.selected !== null ) {
tests++;
}
- expect(tests);
+ QUnit.expect( tests );
- var $fixture = $( '<div id="qunit-fixture"></div>' );
var $textarea = $( '<textarea>' );
- $fixture.append($textarea);
- $( 'body' ).append($fixture);
+ $( '#qunit-fixture' ).append( $textarea );
//$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 text = $textarea.textSelection( 'getContents' ).replace( /\r\n/g, "\n" );
- equal( text, opt.after.text, 'Checking full text after encapsulation' );
+ assert.equal( text, opt.after.text, 'Checking full text after encapsulation' );
if (opt.after.selected !== null) {
var selected = $textarea.textSelection( 'getSelection' );
- equal( selected, opt.after.selected, 'Checking selected text after encapsulation.' );
+ assert.equal( selected, opt.after.selected, 'Checking selected text after encapsulation.' );
}
} );
-};
+}
var sig = {
'pre': "--~~~~"
'peri': 'Heading 2',
'post': ' ==',
'regex': /^(\s*)(={1,6})(.*?)\2(\s*)$/,
- 'regexReplace': "\$1==\$3==\$4",
+ 'regexReplace': "$1==$3==$4",
'ownline': true
}, ulist = {
'pre': "* ",
});
-var caretTest = function(options) {
- test(options.description, function() {
- expect(2);
+function caretTest( options ) {
+ QUnit.test( options.description, 2, function ( assert ) {
+ var $textarea = $( '<textarea>' ).text( options.text );
- var $fixture = $( '<div id="qunit-fixture"></div>' );
- var $textarea = $( '<textarea>' ).text(options.text);
+ $( '#qunit-fixture' ).append( $textarea );
- $fixture.append($textarea);
- $( 'body' ).append($fixture);
-
- if (options.mode == 'set') {
+ if ( options.mode === 'set' ) {
$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(', ') + ')' );
+ } else {
+ assert.equal( actual, expected, message );
+ }
+ }
+
var pos = $textarea.textSelection('getCaretPosition', {startAndEnd: true});
- equal(pos[0], options.start, 'Caret start should be where we set it.');
- equal(pos[1], options.end, 'Caret end should be where we set it.');
+ 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.');
});
}
var 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,
- end: 0,
+ 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({
description: 'set/getCaretPosition with forced empty selection',