Skip to content

Commit

Permalink
add more tests (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Mar 30, 2017
1 parent 7ce1543 commit 25c2e23
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/plain-props.js
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions test/unit/specs/ol/coordinate.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
22 changes: 22 additions & 0 deletions test/unit/specs/utils/plain-props.spec.js
Original file line number Diff line number Diff line change
@@ -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 () {}

0 comments on commit 25c2e23

Please sign in to comment.