1 module( 'jquery.colorUtil.js' );
3 test( '-- Initial check', function(){
5 ok( jQuery
.colorUtil
, 'jQuery.colorUtil defined' );
8 test( 'getRGB', function(){
10 equal( typeof jQuery
.colorUtil
.getRGB(), 'undefined', 'No arguments' );
11 equal( typeof jQuery
.colorUtil
.getRGB( '' ), 'undefined', 'Empty string' );
12 deepEqual( jQuery
.colorUtil
.getRGB( [0, 100, 255] ), [0, 100, 255], 'Array' );
13 deepEqual( jQuery
.colorUtil
.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple string' );
14 deepEqual( jQuery
.colorUtil
.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple string (whitespace)' );
15 deepEqual( jQuery
.colorUtil
.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse percentages string' );
16 deepEqual( jQuery
.colorUtil
.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse percentages string (whitespace)' );
17 deepEqual( jQuery
.colorUtil
.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' );
18 deepEqual( jQuery
.colorUtil
.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' );
19 deepEqual( jQuery
.colorUtil
.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' );
20 deepEqual( jQuery
.colorUtil
.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' );
21 deepEqual( jQuery
.colorUtil
.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' );
22 deepEqual( jQuery
.colorUtil
.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' );
23 deepEqual( jQuery
.colorUtil
.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' );
24 // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep track
25 // would that ever change
26 equal( typeof jQuery
.colorUtil
.getRGB( 'rgba(0,0,0,0)' ), 'undefined', 'Zero rgba without whitespace' );
28 deepEqual( jQuery
.colorUtil
.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
29 deepEqual( jQuery
.colorUtil
.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (transparent)' );
30 equal( typeof jQuery
.colorUtil
.getRGB( 'mediaWiki' ), 'undefined', 'Inexisting color name' );
34 test( 'rgbToHsl', function(){
35 var hsl
= jQuery
.colorUtil
.rgbToHsl( 144, 238, 144 );
36 var dualDecimals = function(a
,b
){
37 return Math
.round(a
*100)/100;
40 ok( hsl
, 'Basic return evaluation' );
41 deepEqual( dualDecimals(hsl
[0]) , 0.33, 'rgb(144, 238, 144): H 0.33' );
42 deepEqual( dualDecimals(hsl
[1]) , 0.73, 'rgb(144, 238, 144): S 0.73' );
43 deepEqual( dualDecimals(hsl
[2]) , 0.75, 'rgb(144, 238, 144): L 0.75' );
47 test( 'hslToRgb', function(){
48 var rgb
= jQuery
.colorUtil
.hslToRgb( 0.3, 0.7, 0.8 );
50 ok( rgb
, 'Basic return evaluation' );
51 deepEqual( Math
.round(rgb
[0]) , 183, 'hsl(0.3, 0.7, 0.8): R 183' );
52 deepEqual( Math
.round(rgb
[1]) , 240, 'hsl(0.3, 0.7, 0.8): G 240' );
53 deepEqual( Math
.round(rgb
[2]) , 168, 'hsl(0.3, 0.7, 0.8): B 168' );
57 test( 'getColorBrightness', function(){
59 var a
= jQuery
.colorUtil
.getColorBrightness( 'red', +0.1 );
61 equal( a
, 'rgb(255,50,50)', 'Start with named color, brighten 10%' );
63 var b
= jQuery
.colorUtil
.getColorBrightness( 'rgb(200,50,50)', -0.2 );
65 equal( b
, 'rgb(118,29,29)', 'Start with rgb string, darken 10%' );