From 25c2e2376a1c4af4f98919aeefca2adb1ff4f863 Mon Sep 17 00:00:00 2001 From: ghettovoice Date: Thu, 30 Mar 2017 12:32:58 +0300 Subject: [PATCH] add more tests (#3) --- src/utils/plain-props.js | 8 ++++-- test/unit/specs/ol/coordinate.spec.js | 32 +++++++++++++++++++++++ test/unit/specs/utils/plain-props.spec.js | 22 ++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 test/unit/specs/ol/coordinate.spec.js create mode 100644 test/unit/specs/utils/plain-props.spec.js diff --git a/src/utils/plain-props.js b/src/utils/plain-props.js index 1c45eb9c..f1c12851 100644 --- a/src/utils/plain-props.js +++ b/src/utils/plain-props.js @@ -1,8 +1,12 @@ -import { isPlainObject, isObject, omitBy } from 'lodash/fp' +import { pickBy, isNumber, isString, isBoolean, isPlainObject } from 'lodash/fp' /** * @func * @param {Object} value * @param {Object} Returns object only with plain properties. */ -const plainProps = omitBy(x => isObject(x) && !isPlainObject(x)) +const plainProps = pickBy(x => isNumber(x) || + isString(x) || + Array.isArray(x) || + isBoolean(x) || + isPlainObject(x)) export default plainProps diff --git a/test/unit/specs/ol/coordinate.spec.js b/test/unit/specs/ol/coordinate.spec.js new file mode 100644 index 00000000..d6e83cd5 --- /dev/null +++ b/test/unit/specs/ol/coordinate.spec.js @@ -0,0 +1,32 @@ +import * as coordinateHelper from 'vl-ol/coordinate' + +describe('ol coordinate helper', () => { + const point3857 = [ 5565974.539663679, 7361866.113051185 ] + const point4326 = [ 50, 55 ] + const line3857 = [ [ 5565974.539663679, 7361866.113051185 ], [ -3896182.1777645755, -11068715.659379495 ] ] + const line4326 = [ [ 50, 55 ], [ -35, -70 ] ] + + describe('pointToLonLat', () => { + it('should transform point coordinate to EPSG:4326', () => { + expect(coordinateHelper.pointToLonLat(point3857, 'EPSG:3857')).to.be.deep.equal(point4326) + }) + }) + + describe('pointFromLonLat', () => { + it('should transform point coordinate from EPSG:4326', () => { + expect(coordinateHelper.pointFromLonLat(point4326, 'EPSG:3857')).to.be.deep.equal(point3857) + }) + }) + + describe('lineToLonLat', () => { + it('should transform line coordinate to EPSG:4326', () => { + expect(coordinateHelper.lineToLonLat(line3857, 'EPSG:3857')).to.be.deep.equal(line4326) + }) + }) + + describe('lineFromLonLat', () => { + it('should transform line coordinate from EPSG:4326', () => { + expect(coordinateHelper.lineFromLonLat(line4326, 'EPSG:3857')).to.be.deep.equal(line3857) + }) + }) +}) diff --git a/test/unit/specs/utils/plain-props.spec.js b/test/unit/specs/utils/plain-props.spec.js new file mode 100644 index 00000000..881cb98d --- /dev/null +++ b/test/unit/specs/utils/plain-props.spec.js @@ -0,0 +1,22 @@ +import plainProps from 'vl-utils/plain-props' + +describe('plain-props', () => { + it('should clean the object from non-plain values', () => { + const obj = { + num: 123, + str: 'qwe', + arr: [ 1, 2, 3 ], + func () {}, + inst: new Ctor() + } + const expected = { + num: 123, + str: 'qwe', + arr: [ 1, 2, 3 ] + } + + expect(plainProps(obj)).to.be.deep.equal(expected) + }) +}) + +function Ctor () {}