Make a nice assert function for properly testing locale specific colors.

Jonathan Frederic 12 years ago committed by Jonathan Frederic
parent 7dfa8fbe79
commit 359d7342d2

@ -61,10 +61,8 @@ casper.notebook_test(function () {
colors[1] = window.getComputedStyle(svg2).fill;
return colors;
});
this.test.assert(['#ff0000', 'rgb(255, 0, 0)'].indexOf(colors && colors[0]) > -1, 'display_svg() First svg should be red');
this.test.assert(['#000000', 'rgb(0, 0, 0)'].indexOf(colors && colors[1]) > -1, 'display_svg() Second svg should be black');
this.assert_colors_equal('#ff0000', colors && colors[0], 'display_svg() First svg should be red');
this.assert_colors_equal('#000000', colors && colors[1], 'display_svg() Second svg should be black');
});
// now ensure that we can pass the same metadata dict to plain old display()
@ -91,8 +89,7 @@ casper.notebook_test(function () {
colors[1] = window.getComputedStyle(svg2).fill;
return colors;
});
this.test.assert(['#ff0000', 'rgb(255, 0, 0)'].indexOf(colors && colors[0]) > -1, 'display() First svg should be red');
this.test.assert(['#000000', 'rgb(0, 0, 0)'].indexOf(colors && colors[1]) > -1, 'display() Second svg should be black');
this.assert_colors_equal('#ff0000', colors && colors[0], 'display() First svg should be red');
this.assert_colors_equal('#000000', colors && colors[1], 'display() Second svg should be black');
});
});

@ -417,6 +417,34 @@ casper.cell_has_class = function(index, classes) {
}, {i : index, c: classes});
};
casper.assert_colors_equal = function (hex_color, local_color, msg) {
// Tests to see if two colors are equal.
//
// Parameters
// hex_color: string
// Hexadecimal color code, with or without preceeding hash character.
// local_color: string
// Local color representation. Can either be hexadecimal (default for
// phantom) or rgb (default for slimer).
// Remove parentheses, hashes, semi-colons, and space characters.
hex_color = hex_color.replace(/[\(\); #]/, '');
local_color = local_color.replace(/[\(\); #]/, '');
// If the local color is rgb, clean it up and replace
if (local_color.substr(0,3).toLowerCase() == 'rgb') {
components = local_color.substr(3).split(',');
local_color = '';
for (var i = 0; i < components.length; i++) {
var part = parseInt(components[i]).toString(16);
while (part.length < 2) part = '0' + part;
local_color += part;
}
}
this.test.assertEquals(hex_color.toUpperCase(), local_color.toUpperCase(), msg);
};
casper.notebook_test = function(test) {
// Wrap a notebook test to reduce boilerplate.
//

Loading…
Cancel
Save