Skip to content

Commit

Permalink
ci: UT
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Nov 27, 2016
1 parent 8bee3ad commit 8be05e9
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"lint": "eslint src --fix",
"test": "mocha --compilers js:babel-register --require babel-polyfill",
"test": "mocha --recursive --compilers js:babel-register --require babel-polyfill",
"test-cov": "istanbul cover _mocha -- --compilers js:babel-register --require babel-polyfill",
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --compilers js:babel-register --require babel-polyfill -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"start": "node --debug --harmony ./dist/server/index.js",
Expand Down
8 changes: 4 additions & 4 deletions src/cli/cms/editor/handlebars/sourceAttr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function isSelected(currentValue, values) {
export function isSelected(currentValue, values) {
var isEqual = false
if(typeof currentValue === 'object' && Object.prototype.toString.call(currentValue) === '[object Object]') {
Array.prototype.forEach.call(values, (value) => {
Expand Down Expand Up @@ -46,7 +46,7 @@ export default function sourceAttr(obj, params) {
* @param {string} path the path to object (dot notation)
* @return {[type]} the object containing the path object or undefined
*/
function get(obj, path) {
export function get(obj, path) {
return path.split('.').reduce(function(prev, curr) {
return prev ? prev[curr] : undefined
}, obj || self)
Expand All @@ -59,7 +59,7 @@ function get(obj, path) {
* @param {string} str the string
* @return {string} the string with values
*/
function prepareDisplay(obj, str) {
export function prepareDisplay(obj, str) {
var keys = getKeys(str)
Array.prototype.forEach.call(keys, (key) => {
var val = get(obj, key)
Expand All @@ -75,7 +75,7 @@ function prepareDisplay(obj, str) {
* @param {string} str the string containing variables
* @return {Array} the array of variables
*/
function getKeys(str){
export function getKeys(str){
var regex = /\{\{(.*?)\}\}/g
var variables = []
var match
Expand Down
81 changes: 81 additions & 0 deletions test/cms/editor/handlebars/sourceAttr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
var chai = require('chai');
var path = require('path');
var fse = require('fs-extra');

var sourceAttr = require('../../../../src/cli/cms/editor/handlebars/sourceAttr')

describe('cmsEditor.handlebars.sourceAttr', function() {
before( function() {
this.fixture = {
gmapsElement: fse.readJsonSync(path.join(__dirname, '../../../fixtures/editor/gmaps-element.json'), 'utf8')
}
});

it('sourceAttr', function() {
var obj = this.fixture.gmapsElement
var params = {
display:'{{formatted_address}}',
value: 'State of Pará, Brazil'
}
var json = sourceAttr.default(obj, params)
chai.expect(json.selected).to.equal('selected')
chai.expect(json.val).to.equal('State of Pará, Brazil')
});

it('get path', function() {
var obj = this.fixture.gmapsElement
var path = 'geometry.location.lat'
var str = sourceAttr.get(obj, path)
chai.expect(str).to.equal(-1.9981271)
});

it('get unknown path', function() {
var obj = this.fixture.gmapsElement
var path = 'errored.path'
var str = sourceAttr.get(obj, path)
chai.expect(str).to.be.undefined;
});

it('prepareDisplay value', function() {
var obj = this.fixture.gmapsElement
var str = 'formatted_address'
str = sourceAttr.prepareDisplay(obj, str)
chai.expect(str).to.equal('State of Pará, Brazil')
});

it('prepareDisplay variable', function() {
var obj = this.fixture.gmapsElement
var str = '{{formatted_address}}'
str = sourceAttr.prepareDisplay(obj, str)
chai.expect(str).to.equal('State of Pará, Brazil')
});

it('prepareDisplay 2 variables', function() {
var obj = this.fixture.gmapsElement
var str = '{{formatted_address}} - {{geometry.location.lat}}'
str = sourceAttr.prepareDisplay(obj, str)
chai.expect(str).to.equal('State of Pará, Brazil - -1.9981271')
});

it('prepareDisplay unknown', function() {
var obj = this.fixture.gmapsElement
var str = 'unknownkey'
str = sourceAttr.prepareDisplay(obj, str)
chai.expect(str).to.equal(str)
});

it('getKeys key', function() {
var ar = sourceAttr.getKeys('key')
chai.expect(ar.length).to.equal(1)
});

it('getKeys {{key}}', function() {
var ar = sourceAttr.getKeys('{{key}}')
chai.expect(ar.length).to.equal(1)
});

it('getKeys {{key}}-nokey-{{key2}}', function() {
var ar = sourceAttr.getKeys('{{key}}-nokey-{{key2}}')
chai.expect(ar.length).to.equal(2)
});
});
53 changes: 53 additions & 0 deletions test/fixtures/editor/gmaps-element.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"address_components": [
{
"long_name": "State of Pará",
"short_name": "PA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Brazil",
"short_name": "BR",
"types": [
"country",
"political"
]
}
],
"formatted_address": "State of Pará, Brazil",
"geometry": {
"bounds": {
"northeast": {
"lat": 2.5910246,
"lng": -46.0643195
},
"southwest": {
"lat": -9.8411565,
"lng": -58.89827700000001
}
},
"location": {
"lat": -1.9981271,
"lng": -54.9306152
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 2.5910246,
"lng": -46.0643195
},
"southwest": {
"lat": -9.8411565,
"lng": -58.89827700000001
}
}
},
"place_id": "ChIJlwksrJn5iJIRCvNV5z7IXjE",
"types": [
"administrative_area_level_1",
"political"
]
}
3 changes: 2 additions & 1 deletion test/fixtures/node_modules/test/process/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion test/fixtures/scripts/test-script/process/test.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
console.log('test')
//console.log('test')
var i = 0
9 changes: 0 additions & 9 deletions test/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@ describe('Process', function() {
}.bind(this))
});

/**
* abeExtend.plugins.instance.getProcess
*
*/
it('abeExtend.plugins.instance.getProcess()', function() {
var file = abeExtend.plugins.instance.getProcess('test')
chai.expect(file).to.not.be.null;
});


/**
* abeExtend.process
*
*/
it('abeExtend.process', function() {
var res = abeExtend.process('test', [])
// chai.assert.equal(res, 'test', 'Hook test failed !')
Expand Down

0 comments on commit 8be05e9

Please sign in to comment.