http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88357

Revision: 88357
Author:   catrope
Date:     2011-05-17 22:19:27 +0000 (Tue, 17 May 2011)
Log Message:
-----------
Add simple test for jquery.autoEllipsis

Modified Paths:
--------------
    trunk/phase3/resources/test/index.html

Added Paths:
-----------
    trunk/phase3/resources/test/unit/jquery/jquery.autoEllipsis.js

Modified: trunk/phase3/resources/test/index.html
===================================================================
--- trunk/phase3/resources/test/index.html      2011-05-17 22:14:00 UTC (rev 
88356)
+++ trunk/phase3/resources/test/index.html      2011-05-17 22:19:27 UTC (rev 
88357)
@@ -13,6 +13,8 @@
        <script src="../mediawiki/mediawiki.js"></script>
        <script src="../mediawiki/mediawiki.user.js"></script>
 
+       <script src="../jquery/jquery.autoEllipsis.js"></script>
+       
        <script>
        mw.user.options.set({"skin": "vector"});
        </script>
@@ -43,6 +45,7 @@
        <script src="unit/jquery/jquery.mwPrototypes.js"></script>
        <script src="unit/mediawiki.util/mediawiki.util.js"></script>
        <script src="unit/jquery/jquery.colorUtil.js"></script>
+       <script src="unit/jquery/jquery.autoEllipsis.js"></script>
 
        <!-- TestSwarm -->
        <script src="testswarm.inject.js"></script>

Added: trunk/phase3/resources/test/unit/jquery/jquery.autoEllipsis.js
===================================================================
--- trunk/phase3/resources/test/unit/jquery/jquery.autoEllipsis.js              
                (rev 0)
+++ trunk/phase3/resources/test/unit/jquery/jquery.autoEllipsis.js      
2011-05-17 22:19:27 UTC (rev 88357)
@@ -0,0 +1,47 @@
+module( 'jquery.autoEllipsis.js' );
+
+test( '-- Initial check', function(){
+
+       ok( jQuery.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' );
+});
+
+function createWrappedDiv( text ) {
+       var $wrapper = $( '<div />' ).css( 'width', '100px' );
+       var $div = $( '<div />' ).text( text );
+       $wrapper.append( $div );
+       return $wrapper;
+}
+
+function findDivergenceIndex( a, b ) {
+       var i = 0;
+       while ( i < a.length && i < b.length && a[i] == b[i] ) {
+               i++;
+       }
+       return i;
+}
+
+test( 'Position right', function() {
+       // We need this thing to be visible, so append it to the DOM
+       var origText = 'This is a really long random string and there is no way 
it fits in 100 pixels.';
+       var $wrapper = createWrappedDiv( origText );
+       $( 'body' ).append( $wrapper );
+       // Autoellipse it
+       $wrapper.autoEllipsis( { position: 'right' } );
+       // Turn on word wrapping
+       var $span = $wrapper.find( 'span' );
+       $span.css( 'whiteSpace', 'nowrap' );
+       
+       // Check that the text fits
+       ok( $span.width() <= $span.parent().width(), "text fits (span's width 
is no larger than its parent's width)" );
+       
+       // Add one character using scary black magic
+       var spanText = $span.text();
+       var d = findDivergenceIndex( origText, spanText );
+       spanText = spanText.substr( 0, d ) + origText[d] + '...';
+       
+       // Put this text in the span and verify it doesn't fit
+       $span.text( spanText );
+       ok( $span.width() > $span.parent().width(), "fit is maximal (adding one 
character makes it not fit any more)" );
+       
+       $wrapper.remove();
+});


Property changes on: 
trunk/phase3/resources/test/unit/jquery/jquery.autoEllipsis.js
___________________________________________________________________
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to