From 09926e567e513c9e7420be4f9c365c6c02bfc0b3 Mon Sep 17 00:00:00 2001 From: mama Date: Tue, 19 Sep 2017 17:23:45 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20d'un=20bug=20du=20m=C3=A9ca=20s?= =?UTF-8?q?=C3=A9lection=20et=20les=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/mecanisms.js | 2 +- source/webpack.test.config.js | 9 +++++++++ test/traverse.test.js | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index 89dc6f58d..92c0ed99d 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -627,7 +627,7 @@ export let mecanismSelection = (recurse,k,v) => { data = dataSource ? dataSource['data'] : null, dataKey = explanation.nodeValue, dataItems = (data && dataKey && dataSearchField) ? R.filter(item => item[dataSearchField] == dataKey, data) : null, - dataItemValues = dataItems ? R.values(dataItems) : null, + dataItemValues = (dataItems && !R.isEmpty(dataItems)) ? R.values(dataItems) : null, // TODO - over-specific! transform the JSON instead dataItemSubValues = dataItemValues && dataItemValues[0][dataTargetName] ? dataItemValues[0][dataTargetName]["taux"] : null, sortedSubValues = dataItemSubValues ? R.sortBy(pair => pair[0], R.toPairs(dataItemSubValues)) : null, diff --git a/source/webpack.test.config.js b/source/webpack.test.config.js index dcea44c25..a83837365 100644 --- a/source/webpack.test.config.js +++ b/source/webpack.test.config.js @@ -27,6 +27,15 @@ module.exports = { exclude: /node_modules/, loader: 'babel-loader' }, + { + test: /\.csv$/, + loader: 'csv-loader', + options: { + dynamicTyping: true, + header: true, + skipEmptyLines: true + } + }, { //slow : ~ 3 seconds test: /\.(jpe?g|png|gif|svg)$/i, loader: 'ignore-loader' diff --git a/test/traverse.test.js b/test/traverse.test.js index 38dbe1030..02ca48ead 100644 --- a/test/traverse.test.js +++ b/test/traverse.test.js @@ -258,4 +258,22 @@ describe('analyseSituation with mecanisms', function() { expect(analyseSituation(rules,"startHere")(stateSelector)).to.have.property('nodeValue',0.02) }); + it('should handle failed selections', function() { + let stateSelector = (name) => ({"top . code postal":"3"})[name] + let data = {taux_versement_transport: {xyz: {codePostal:1, aot: {taux: {"2019":"1.0"}}}, abc: {codePostal:2, smt: {taux: {"2019":"2.0"}}}}} + let rawRules = [ + { espace: "top", + nom: "startHere", + formule: {"sélection": { + données: "startHere", + cherche: "code postal", + dans: "codePostal", + renvoie: "smt" + }}, + données: 'taux_versement_transport'}, + {espace: "top", nom: "code postal", format: "nombre"}], + rules = rawRules.map(rule => enrichRule(rule,data)) + expect(analyseSituation(rules,"startHere")(stateSelector)).to.have.property('nodeValue', 0) + }); + });