mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
test : add unit test for ColorUtils
This commit is contained in:
parent
0e817a88a7
commit
ba491736c1
@ -117,10 +117,10 @@
|
||||
|
||||
ns.GifExportController.prototype.renderAsImageDataAnimatedGIF = function(zoom, fps, cb) {
|
||||
var currentColors = pskl.app.currentColorsService.computeCurrentColors();
|
||||
|
||||
|
||||
var preserveColors = currentColors.length < MAX_GIF_COLORS;
|
||||
var transparentColor = this.getTransparentColor(currentColors);
|
||||
|
||||
|
||||
var gif = new window.GIF({
|
||||
workers: 5,
|
||||
quality: 1,
|
||||
@ -155,17 +155,16 @@
|
||||
|
||||
ns.GifExportController.prototype.getTransparentColor = function(currentColors) {
|
||||
var transparentColor = pskl.utils.ColorUtils.getUnusedColor(currentColors);
|
||||
|
||||
if (!transparentColor) {
|
||||
console.error('Unable to find unused color to use as transparent color in the current sprite');
|
||||
transparentColor = MAGIC_PINK;
|
||||
} else {
|
||||
transparentColor = window.tinycolor(transparentColor).toHexString();
|
||||
}
|
||||
|
||||
return transparentColor;
|
||||
};
|
||||
|
||||
// FIXME : HORRIBLE COPY/PASTA
|
||||
|
||||
// FIXME : JD : HORRIBLE COPY/PASTA (JD later : where???)
|
||||
ns.GifExportController.prototype.updateStatus_ = function (imageUrl, error) {
|
||||
if (imageUrl) {
|
||||
var linkTpl = "<a class='image-link' href='{{link}}' target='_blank'>{{shortLink}}</a>";
|
||||
|
@ -3,25 +3,25 @@
|
||||
|
||||
ns.ColorUtils = {
|
||||
getUnusedColor : function (usedColors) {
|
||||
// start with white
|
||||
var color = {
|
||||
r : 255,
|
||||
g : 255,
|
||||
b : 255
|
||||
};
|
||||
|
||||
usedColors = usedColors || [];
|
||||
// create check map
|
||||
var colorMap = {};
|
||||
usedColors.forEach(function (color) {
|
||||
colorMap[color.toUpperCase()] = true;
|
||||
});
|
||||
|
||||
// start with white
|
||||
var color = {
|
||||
r : 255,
|
||||
g : 255,
|
||||
b : 255
|
||||
};
|
||||
var match = null;
|
||||
while (true) {
|
||||
var hex = tinycolor(color).toHexString().toUpperCase();
|
||||
|
||||
if (!colorMap[hex]) {
|
||||
match = color;
|
||||
match = hex;
|
||||
break;
|
||||
} else {
|
||||
// pick a non null component to decrease its value
|
||||
|
29
test/js/utils/ColorUtilsTest.js
Normal file
29
test/js/utils/ColorUtilsTest.js
Normal file
@ -0,0 +1,29 @@
|
||||
describe("Color utils", function() {
|
||||
|
||||
beforeEach(function() {});
|
||||
afterEach(function() {});
|
||||
|
||||
it("returns a color when provided with array of colors", function() {
|
||||
// when/then
|
||||
var unusedColor = pskl.utils.ColorUtils.getUnusedColor(['#ffffff', '#feffff', '#fdffff']);
|
||||
// verify
|
||||
expect(unusedColor).toBe('#FCFFFF');
|
||||
|
||||
// when/then
|
||||
unusedColor = pskl.utils.ColorUtils.getUnusedColor(['#fcffff', '#feffff', '#fdffff']);
|
||||
// verify
|
||||
expect(unusedColor).toBe('#FFFFFF');
|
||||
});
|
||||
|
||||
it("returns a color for an empty array", function() {
|
||||
// when/then
|
||||
var unusedColor = pskl.utils.ColorUtils.getUnusedColor([]);
|
||||
// verify
|
||||
expect(unusedColor).toBe('#FFFFFF');
|
||||
|
||||
// when/then
|
||||
unusedColor = pskl.utils.ColorUtils.getUnusedColor();
|
||||
// verify
|
||||
expect(unusedColor).toBe('#FFFFFF');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user