Merge "Define 'MW_UPDATER' when running update.php"
[mediawiki.git] / tests / qunit / suites / resources / jquery / jquery.colorUtil.test.js
blob39ae363c61baf84e8387206444c3fe0ec20382b0
1 ( function ( $ ) {
2         QUnit.module( 'jquery.colorUtil', QUnit.newMwEnvironment() );
4         QUnit.test( 'getRGB', 18, function ( assert ) {
5                 assert.strictEqual( $.colorUtil.getRGB(), undefined, 'No arguments' );
6                 assert.strictEqual( $.colorUtil.getRGB( '' ), undefined, 'Empty string' );
7                 assert.deepEqual( $.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Parse array of rgb values' );
8                 assert.deepEqual( $.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple rgb string' );
9                 assert.deepEqual( $.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple rgb string with spaces' );
10                 assert.deepEqual( $.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse rgb string with percentages' );
11                 assert.deepEqual( $.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse rgb string with percentages and spaces' );
12                 assert.deepEqual( $.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' );
13                 assert.deepEqual( $.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' );
14                 assert.deepEqual( $.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' );
15                 assert.deepEqual( $.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' );
16                 assert.deepEqual( $.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' );
17                 assert.deepEqual( $.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' );
18                 assert.deepEqual( $.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' );
20                 // Perhaps this is a bug in colorUtil, but it is the current behavior so, let's keep
21                 // track of it, so we will know in case it would ever change.
22                 assert.strictEqual( $.colorUtil.getRGB( 'rgba(0,0,0,0)' ), undefined, 'Zero rgba without whitespace' );
24                 assert.deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
25                 assert.deepEqual( $.colorUtil.getRGB( 'transparent' ), [255, 255, 255], 'Color names (transparent)' );
26                 assert.strictEqual( $.colorUtil.getRGB( 'mediaWiki' ), undefined, 'Inexisting color name' );
27         } );
29         QUnit.test( 'rgbToHsl', 1, function ( assert ) {
30                 var hsl, ret;
32                 // Cross-browser differences in decimals...
33                 // Round to two decimals so they can be more reliably checked.
34                 function dualDecimals( a ) {
35                         return Math.round( a * 100 ) / 100;
36                 }
38                 // Re-create the rgbToHsl return array items, limited to two decimals.
39                 hsl = $.colorUtil.rgbToHsl( 144, 238, 144 );
40                 ret = [ dualDecimals( hsl[0] ), dualDecimals( hsl[1] ), dualDecimals( hsl[2] ) ];
42                 assert.deepEqual( ret, [0.33, 0.73, 0.75], 'rgb(144, 238, 144): hsl(0.33, 0.73, 0.75)' );
43         } );
45         QUnit.test( 'hslToRgb', 1, function ( assert ) {
46                 var rgb, ret;
47                 rgb = $.colorUtil.hslToRgb( 0.3, 0.7, 0.8 );
49                 // Re-create the hslToRgb return array items, rounded to whole numbers.
50                 ret = [ Math.round( rgb[0] ), Math.round( rgb[1] ), Math.round( rgb[2] ) ];
52                 assert.deepEqual( ret, [183, 240, 168], 'hsl(0.3, 0.7, 0.8): rgb(183, 240, 168)' );
53         } );
55         QUnit.test( 'getColorBrightness', 2, function ( assert ) {
56                 var a, b;
57                 a = $.colorUtil.getColorBrightness( 'red', +0.1 );
58                 assert.equal( a, 'rgb(255,50,50)', 'Start with named color "red", brighten 10%' );
60                 b = $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
61                 assert.equal( b, 'rgb(118,29,29)', 'Start with rgb string "rgb(200,50,50)", darken 20%' );
62         } );
63 }( jQuery ) );