From 58e935e79117a32ca40553ad9dcdc669a082aaf2 Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Tue, 19 Sep 2017 00:08:39 +0200 Subject: [PATCH] =?UTF-8?q?:bug:=20Corrige=20les=20variables=20manquantes?= =?UTF-8?q?=20pour=20les=20s=C3=A9lections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/traverse.js | 6 ++++-- test/generateQuestions.test.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/engine/traverse.js b/source/engine/traverse.js index 047b45b58..ec595e73a 100644 --- a/source/engine/traverse.js +++ b/source/engine/traverse.js @@ -337,10 +337,11 @@ let mecanismSelection = (recurse,k,v) => { let explanation = recurse(v['cherche']) let evaluate = (situationGate, parsedRules, node) => { - let collectMissing = node => node.explanation.nodeValue ? [] : collectNodeMissing(node.explanation), + let collectMissing = node => collectNodeMissing(node.explanation), + explanation = evaluateNode(situationGate, parsedRules, node.explanation), dataSource = findRuleByName(parsedRules, dataSourceName), - dataKey = evaluateNode(situationGate, parsedRules, explanation).nodeValue, 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, // TODO - over-specific! transform the JSON instead @@ -363,6 +364,7 @@ let mecanismSelection = (recurse,k,v) => { return { evaluate, + explanation, jsx } } diff --git a/test/generateQuestions.test.js b/test/generateQuestions.test.js index 851cb586e..a3e1b0a98 100644 --- a/test/generateQuestions.test.js +++ b/test/generateQuestions.test.js @@ -265,16 +265,16 @@ describe('buildNextSteps', function() { }); it('should generate questions from the real rules, experimental version', function() { - let stateSelector = (name) => ({"contrat salarié . type de contrat":"CDI"})[name] + let stateSelector = (name) => ({"contrat salarié . type de contrat":"CDI","entreprise . effectif":"50"})[name] let rules = realRules.map(enrichRule), situation = analyseTopDown(rules,"Salaire")(stateSelector), objectives = getObjectives(stateSelector, situation.root, situation.parsedRules), + missing = collectMissingVariables()(stateSelector,situation), result = buildNextSteps(stateSelector, rules, situation) expect(R.path(["question","props","label"])(result[0])).to.equal("Quel est le salaire brut ?") expect(R.path(["question","props","label"])(result[1])).to.equal("Le salarié a-t-il le statut cadre ?") - expect(R.path(["question","props","label"])(result[2])).to.equal("Quel est l'effectif de l'entreprise ?") }); });