r87900 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87899‎ | r87900 | r87901 >
Date:06:24, 12 May 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Add unit test for jquery.colorUtil module
Modified paths:
  • /trunk/phase3/resources/test/index.html (modified) (history)
  • /trunk/phase3/resources/test/unit/jquery (added) (history)
  • /trunk/phase3/resources/test/unit/jquery/jquery.colorUtil.js (added) (history)

Diff [purge]

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
169 + native
Index: trunk/phase3/resources/test/index.html
@@ -21,6 +21,8 @@
2222 <script src="../jquery/jquery.tablesorter.js"></script>
2323 <script src="../mediawiki.util/mediawiki.util.js"></script>
2424
 25+ <script src="../jquery/jquery.colorUtil.js"></script>
 26+
2527 <!-- QUnit dependancies and scripts -->
2628 <link rel="stylesheet" href="../jquery/jquery.qunit.css" />
2729 <script src="../jquery/jquery.qunit.js"></script>
@@ -31,6 +33,7 @@
3234 <!-- Your test suites go here -->
3335 <script src="unit/mediawiki/mediawiki.js"></script>
3436 <script src="unit/mediawiki.util/mediawiki.util.js"></script>
 37+ <script src="unit/jquery/jquery.colorUtil.js"></script>
3538
3639 <!-- TestSwarm -->
3740 <script src="http://toolserver.org/~krinkle/testswarm/js/inject.js"></script>

Comments

#Comment by Trevor Parscal (WMF) (talk | contribs)   09:16, 15 May 2011

Is this still needed since you switched to using visibility as a CSS check?

#Comment by Krinkle (talk | contribs)   09:44, 15 May 2011

This plugin wasn't written in this commit. colorUtil is used to convert colors and easily manipulate them.

I added it to the test suite to make sure it's working properly, just generally expanding our test suite.

I did use it to temporarily fix the color CSS check, which is removed now, but this plugin should still be part of the test suite on itself.

Status & tagging log