* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / qunit / suites / resources / jquery / jquery.autoEllipsis.js
blob6be5212e1848c564c414c32cf9f223dcf1bda8ca
1 module( 'jquery.autoEllipsis.js' );
3 test( '-- Initial check', function(){
4         expect(1);
5         ok( jQuery.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' );
6 });
8 function createWrappedDiv( text ) {
9         var $wrapper = $( '<div />' ).css( 'width', '100px' );
10         var $div = $( '<div />' ).text( text );
11         $wrapper.append( $div );
12         return $wrapper;
15 function findDivergenceIndex( a, b ) {
16         var i = 0;
17         while ( i < a.length && i < b.length && a[i] == b[i] ) {
18                 i++;
19         }
20         return i;
23 test( 'Position right', function() {
24         expect(3);
26         // We need this thing to be visible, so append it to the DOM
27         var origText = 'This is a really long random string and there is no way it fits in 100 pixels.';
28         var $wrapper = createWrappedDiv( origText );
29         $( 'body' ).append( $wrapper );
30         $wrapper.autoEllipsis( { position: 'right' } );
32         // Verify that, and only one, span element was created
33         var $span = $wrapper.find( '> span' );
34         deepEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' );
36         // Check that the text fits by turning on word wrapping
37         $span.css( 'whiteSpace', 'nowrap' );
38         deepEqual( $span.width() <= $span.parent().width(), true, "Text fits (span's width is no larger than its parent's width)" );
40         // Add one character using scary black magic
41         var spanText = $span.text();
42         var d = findDivergenceIndex( origText, spanText );
43         spanText = spanText.substr( 0, d ) + origText[d] + '...';
45         // Put this text in the span and verify it doesn't fit
46         $span.text( spanText );
47         deepEqual( $span.width() > $span.parent().width(), true, 'Fit is maximal (adding one character makes it not fit any more)' );
49         // Clean up
50         $wrapper.remove();
51 });