Merge "* oracle DB schema update to current (changes relevant to 1.19 will be backpor...
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.autoEllipsis.test.js
1 ( function ( mw, $ ) {
2
3 QUnit.module( 'jquery.autoEllipsis', QUnit.newMwEnvironment() );
4
5 function createWrappedDiv( text, width ) {
6 var $wrapper = $( '<div>' ).css( 'width', width );
7 var $div = $( '<div>' ).text( text );
8 $wrapper.append( $div );
9 return $wrapper;
10 }
11
12 function findDivergenceIndex( a, b ) {
13 var i = 0;
14 while ( i < a.length && i < b.length && a[i] === b[i] ) {
15 i++;
16 }
17 return i;
18 }
19
20 QUnit.test( 'Position right', 4, function ( assert ) {
21 // We need this thing to be visible, so append it to the DOM
22 var origText = 'This is a really long random string and there is no way it fits in 100 pixels.';
23 var $wrapper = createWrappedDiv( origText, '100px' );
24 $( '#qunit-fixture' ).append( $wrapper );
25 $wrapper.autoEllipsis( { position: 'right' } );
26
27 // Verify that, and only one, span element was created
28 var $span = $wrapper.find( '> span' );
29 assert.strictEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' );
30
31 // Check that the text fits by turning on word wrapping
32 $span.css( 'whiteSpace', 'nowrap' );
33 assert.ltOrEq( $span.width(), $span.parent().width(), "Text fits (making the span 'white-space:nowrap' does not make it wider than its parent)" );
34
35 // Add two characters using scary black magic
36 var spanText = $span.text();
37 var d = findDivergenceIndex( origText, spanText );
38 var spanTextNew = spanText.substr( 0, d ) + origText[d] + origText[d] + '...';
39
40 assert.gt( spanTextNew.length, spanText.length, 'Verify that the new span-length is indeed greater' );
41
42 // Put this text in the span and verify it doesn't fit
43 $span.text( spanTextNew );
44 // In IE6 width works like min-width, allow IE6's width to be "equal to"
45 if ( $.browser.msie && Number( $.browser.version ) === 6 ) {
46 assert.gtOrEq( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more) - IE6: Maybe equal to as well due to width behaving like min-width in IE6' );
47 } else {
48 assert.gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more)' );
49 }
50 });
51
52 }( mediaWiki, jQuery ) );