Added simple test

#79
This commit is contained in:
Gleb Pospelov 2015-07-30 04:08:33 +03:00
parent 36247c7bee
commit 268c6bef26
2 changed files with 80 additions and 0 deletions

View File

@ -49,6 +49,7 @@
<script src="../src/filters/Blur.js" data-cover></script>
<script src="../src/filters/Mask.js" data-cover></script>
<script src="../src/filters/RGB.js" data-cover></script>
<script src="../src/filters/RGBA.js" data-cover></script>
<script src="../src/filters/HSV.js" data-cover></script>
<script src="../src/filters/HSL.js" data-cover></script>
<script src="../src/filters/Emboss.js" data-cover></script>
@ -154,6 +155,7 @@
<script src="unit/filters/Blur-test.js"></script>
<script src="unit/filters/Brighten-test.js"></script>
<script src="unit/filters/RGB-test.js"></script>
<script src="unit/filters/RGBA-test.js"></script>
<script src="unit/filters/HSV-test.js"></script>
<script src="unit/filters/HSL-test.js"></script>
<script src="unit/filters/Invert-test.js"></script>

View File

@ -0,0 +1,78 @@
suite('RGBA', function() {
// ======================================================
test('colorize basic', function(done) {
var data = [
{
color: '#ff0000',
filter: [170, 170, 170, 0.5],
// Actually 212 but in tests rounding half up
result: [213, 85, 85, 255]
},
{
color: '#2a6511',
filter: [242, 193, 168, 0.33],
result: [108, 131, 67, 255]
},
{
color: '#e4d526',
filter: [175, 98, 37, 0.79],
result: [186, 122, 37, 255]
},
];
var stage = new Konva.Stage({
container: 'konva-container',
width: data.length,
height: 1
});
var layer = new Konva.Layer({
id: 'layer'
});
for (var i = 0; i < data.length; i += 1) {
var d = data[i];
var rect = new Konva.Rect({
x: i,
y: 0,
width: 1,
height: 1,
fill: d.color
});
rect.cache();
rect.red(d.filter[0]);
rect.green(d.filter[1]);
rect.blue(d.filter[2]);
rect.alpha(d.filter[3]);
rect.filters([Konva.Filters.RGBA]);
layer.add(rect);
}
stage.add(layer);
layer.batchDraw();
var context = layer.getCanvas().getContext();
var imageDataToArray = function (x) {
var imageData = context.getImageData(x, 0, 1, 1).data;
return [
imageData['0'], imageData['1'], imageData['2'], imageData['3']
];
};
var a0 = imageDataToArray(0);
var a1 = imageDataToArray(1);
var a2 = imageDataToArray(2);
assert.deepEqual(a0, data[0].result);
assert.deepEqual(a1, data[1].result);
assert.deepEqual(a2, data[2].result);
done();
});
});