Index: trunk/phase3/resources/test/unit/jquery/jquery.colorUtil.js |
— | — | @@ -0,0 +1,67 @@ |
| 2 | +module( 'jquery.colorUtil.js' ); |
| 3 | + |
| 4 | +test( '-- Initial check', function(){ |
| 5 | + |
| 6 | + ok( jQuery.colorUtil, 'jQuery.colorUtil defined' ); |
| 7 | +}); |
| 8 | + |
| 9 | +test( 'getRGB', function(){ |
| 10 | + |
| 11 | + equals( typeof jQuery.colorUtil.getRGB(), 'undefined', 'No arguments' ); |
| 12 | + equals( typeof jQuery.colorUtil.getRGB( '' ), 'undefined', 'Empty string' ); |
| 13 | + same( jQuery.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Array' ); |
| 14 | + same( jQuery.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple string' ); |
| 15 | + same( jQuery.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple string (whitespace)' ); |
| 16 | + same( jQuery.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse percentages string' ); |
| 17 | + same( jQuery.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse percentages string (whitespace)' ); |
| 18 | + same( jQuery.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' ); |
| 19 | + same( jQuery.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' ); |
| 20 | + same( jQuery.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' ); |
| 21 | + same( jQuery.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' ); |
| 22 | + same( jQuery.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' ); |
| 23 | + same( jQuery.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' ); |
| 24 | + same( jQuery.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' ); |
| 25 | + // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep track |
| 26 | + // would that ever chnge |
| 27 | + equals( typeof jQuery.colorUtil.getRGB( 'rgba(0,0,0,0)' ), 'undefined', 'Zero rgba without whitespace' ); |
| 28 | + |
| 29 | + same( jQuery.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' ); |
| 30 | + same( jQuery.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (transparent)' ); |
| 31 | + equals( typeof jQuery.colorUtil.getRGB( 'mediaWiki' ), 'undefined', 'Inexisting Color name' ); |
| 32 | + |
| 33 | +}); |
| 34 | + |
| 35 | +test( 'rgbToHsl', function(){ |
| 36 | + var hsl = jQuery.colorUtil.rgbToHsl( 144, 238, 144 ); |
| 37 | + var dualDecimals = function(a,b){ |
| 38 | + return Math.round(a*100)/100; |
| 39 | + }; |
| 40 | + |
| 41 | + ok( hsl, 'Basic return evaluation' ); |
| 42 | + same( dualDecimals(hsl[0]) , 0.33, 'rgb(144, 238, 144): H 0.33' ); |
| 43 | + same( dualDecimals(hsl[1]) , 0.73, 'rgb(144, 238, 144): S 0.73' ); |
| 44 | + same( dualDecimals(hsl[2]) , 0.75, 'rgb(144, 238, 144): L 0.75' ); |
| 45 | + |
| 46 | +}); |
| 47 | + |
| 48 | +test( 'hslToRgb', function(){ |
| 49 | + var rgb = jQuery.colorUtil.hslToRgb( 0.3, 0.7, 0.8 ); |
| 50 | + |
| 51 | + ok( rgb, 'Basic return evaluation' ); |
| 52 | + same( Math.round(rgb[0]) , 183, 'hsl(0.3, 0.7, 0.8): R 183' ); |
| 53 | + same( Math.round(rgb[1]) , 240, 'hsl(0.3, 0.7, 0.8): G 240' ); |
| 54 | + same( Math.round(rgb[2]) , 168, 'hsl(0.3, 0.7, 0.8): B 168' ); |
| 55 | + |
| 56 | +}); |
| 57 | + |
| 58 | +test( 'getColorBrightness', function(){ |
| 59 | + |
| 60 | + var a = jQuery.colorUtil.getColorBrightness( 'red', +0.1 ); |
| 61 | + |
| 62 | + equals( a, 'rgb(255,50,50)', 'Start with named color, brighten 10%' ); |
| 63 | + |
| 64 | + var b = jQuery.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 ); |
| 65 | + |
| 66 | + equals( b, 'rgb(118,29,29)', 'Start with rgb string, darken 10%' ); |
| 67 | + |
| 68 | +}); |
Property changes on: trunk/phase3/resources/test/unit/jquery/jquery.colorUtil.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 69 | + native |
Index: trunk/phase3/resources/test/index.html |
— | — | @@ -21,6 +21,8 @@ |
22 | 22 | <script src="../jquery/jquery.tablesorter.js"></script> |
23 | 23 | <script src="../mediawiki.util/mediawiki.util.js"></script> |
24 | 24 | |
| 25 | + <script src="../jquery/jquery.colorUtil.js"></script> |
| 26 | + |
25 | 27 | <!-- QUnit dependancies and scripts --> |
26 | 28 | <link rel="stylesheet" href="../jquery/jquery.qunit.css" /> |
27 | 29 | <script src="../jquery/jquery.qunit.js"></script> |
— | — | @@ -31,6 +33,7 @@ |
32 | 34 | <!-- Your test suites go here --> |
33 | 35 | <script src="unit/mediawiki/mediawiki.js"></script> |
34 | 36 | <script src="unit/mediawiki.util/mediawiki.util.js"></script> |
| 37 | + <script src="unit/jquery/jquery.colorUtil.js"></script> |
35 | 38 | |
36 | 39 | <!-- TestSwarm --> |
37 | 40 | <script src="http://toolserver.org/~krinkle/testswarm/js/inject.js"></script> |