From 1741509cf7ba5e922c22498176517ed181acd39a Mon Sep 17 00:00:00 2001 From: sarthak saxena Date: Thu, 1 Feb 2018 02:06:28 +0530 Subject: [PATCH] Add tests for basic image contrast + image contrast with tween + image contrast with crop --- test/node-runner.js | 1 + test/runner.html | 2 + test/unit/filters/Contrast-test.js | 102 +++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 test/unit/filters/Contrast-test.js diff --git a/test/node-runner.js b/test/node-runner.js index 27b8a880..ee09e8e5 100644 --- a/test/node-runner.js +++ b/test/node-runner.js @@ -107,6 +107,7 @@ require('./unit/filters/Noise-test.js'); require('./unit/filters/Threshold-test.js'); require('./unit/filters/Posterize-test.js'); require('./unit/filters/Sepia-test.js'); +require('./unit/filters/Contrast-test.js'); require('./unit/filters/Emboss-test.js'); require('./unit/filters/Solarize-test.js'); require('./unit/filters/Kaleidoscope-test.js'); diff --git a/test/runner.html b/test/runner.html index 94b37c46..2bbae76b 100644 --- a/test/runner.html +++ b/test/runner.html @@ -59,6 +59,7 @@ + @@ -164,6 +165,7 @@ + diff --git a/test/unit/filters/Contrast-test.js b/test/unit/filters/Contrast-test.js new file mode 100644 index 00000000..2c084170 --- /dev/null +++ b/test/unit/filters/Contrast-test.js @@ -0,0 +1,102 @@ +suite('Filter Contrast', function() { + // ====================================================== + test('basic', function(done) { + var stage = addStage(); + + var imageObj = new Image(); + imageObj.onload = function() { + var layer = new Konva.Layer(); + var darth = new Konva.Image({ + x: 10, + y: 10, + image: imageObj, + draggable: true + }); + + layer.add(darth); + stage.add(layer); + + darth.cache(); + darth.filters([Konva.Filters.Contrast]); + darth.contrast(40); + layer.draw(); + + assert.equal(darth.contrast(), 40); + + done(); + }; + imageObj.src = 'assets/darth-vader.jpg'; + }); + + // ====================================================== + test('tween', function(done) { + var stage = addStage(); + + var imageObj = new Image(); + imageObj.onload = function() { + var layer = new Konva.Layer(); + var darth = new Konva.Image({ + x: 10, + y: 10, + image: imageObj, + draggable: true + }); + + layer.add(darth); + stage.add(layer); + + darth.cache(); + darth.filters([Konva.Filters.Contrast]); + darth.contrast(40); + layer.draw(); + + var tween = new Konva.Tween({ + node: darth, + duration: 2.0, + contrast: 0, + easing: Konva.Easings.EaseInOut + }); + + darth.on('mouseover', function() { + tween.play(); + }); + + darth.on('mouseout', function() { + tween.reverse(); + }); + + done(); + }; + imageObj.src = 'assets/darth-vader.jpg'; + }); + + // ====================================================== + test('crop', function(done) { + var stage = addStage(); + + var imageObj = new Image(); + imageObj.onload = function() { + var layer = new Konva.Layer(); + var darth = new Konva.Image({ + x: 10, + y: 10, + image: imageObj, + crop: {x: 128, y: 48, width: 256, height: 128}, + draggable: true + }); + + layer.add(darth); + stage.add(layer); + + darth.cache(); + darth.filters([Konva.Filters.Contrast]); + darth.contrast(-40); + layer.draw(); + + assert.equal(darth.contrast(), -40); + + done(); + }; + imageObj.src = 'assets/darth-vader.jpg'; + }); +});