From 0eda33f057489f0bed55cd5fcd312bcbef7d5f38 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 4 Oct 2016 11:28:47 -0700 Subject: [PATCH] Add tests for cropping native images --- spec/api-native-image-spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/api-native-image-spec.js b/spec/api-native-image-spec.js index b7131f53ef..4f30b7ac51 100644 --- a/spec/api-native-image-spec.js +++ b/spec/api-native-image-spec.js @@ -112,4 +112,23 @@ describe('nativeImage module', () => { assert(better.toPNG().length < best.toPNG().length) }) }) + + describe('crop(bounds)', () => { + it('returns an empty image when the bounds are invalid', () => { + const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png')) + assert(image.crop({width: 0, height: 0, x: 0, y: 0}).isEmpty()) + assert(image.crop({width: -1, height: 10, x: 0, y: 0}).isEmpty()) + assert(image.crop({width: 10, height: -35, x: 0, y: 0}).isEmpty()) + assert(image.crop({width: 100, height: 100, x: 1000, y: 1000}).isEmpty()) + }) + + it('returns a cropped image', () => { + const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png')) + const cropA = image.crop({width: 25, height: 64, x: 0, y: 0}) + const cropB = image.crop({width: 25, height: 64, x: 30, y: 40}) + assert.deepEqual(cropA.getSize(), {width: 25, height: 64}) + assert.deepEqual(cropB.getSize(), {width: 25, height: 64}) + assert(!cropA.toPNG().equals(cropB.toPNG())) + }) + }) })