From 25b72636584b3c46951710a91f49a8fd8a266691 Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Fri, 8 Sep 2017 12:28:35 +0200 Subject: [PATCH] =?UTF-8?q?:bug:=20Corrige=20les=20variables=20manquantes?= =?UTF-8?q?=20pour=20'une=20possibilit=C3=A9'=20lorsqu'on=20a=20donn=C3=A9?= =?UTF-8?q?=20une=20r=C3=A9ponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/traverse.js | 7 +++++-- test/generateQuestions.test.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/source/engine/traverse.js b/source/engine/traverse.js index d162054c5..fc71e87db 100644 --- a/source/engine/traverse.js +++ b/source/engine/traverse.js @@ -91,9 +91,12 @@ let fillVariableNode = (rules, rule) => (parseResult) => { ? null // pas moyen de calculer car il n'y a pas de formule, elle restera donc nulle : parsedRule.nodeValue, // la valeur du calcul fait foi explanation = parsedRule, - missingVariables = variableIsCalculable ? [] : (nodeValue == null ? [dottedName] : []) + missingVariables = variableIsCalculable ? [] : [dottedName] - let collectMissing = node => variableIsCalculable ? collectNodeMissing(parsedRule) : node.missingVariables + let collectMissing = node => + nodeValue != null ? // notamment si situationValue != null + [] : + variableIsCalculable ? collectNodeMissing(parsedRule) : node.missingVariables let result = cached ? cached : { ...rewriteNode(node,nodeValue,explanation,collectMissing), diff --git a/test/generateQuestions.test.js b/test/generateQuestions.test.js index 7bfb8c6f6..7c1b55f48 100644 --- a/test/generateQuestions.test.js +++ b/test/generateQuestions.test.js @@ -93,6 +93,19 @@ describe('collectMissingVariables', function() { expect(result).to.deep.equal({}) }); + it('should not report missing variables when "une possibilité" was answered', function() { + let mySelector = (name) => ({"top . trois":"ko"})[name] + + let rawRules = [ + {nom: "startHere", formule: "trois", espace: "top"}, + {nom: "trois", formule: {"une possibilité":["ko"]}, espace: "top"}], + rules = rawRules.map(enrichRule), + situation = analyseTopDown(rules,"startHere")(mySelector), + result = collectMissingVariables()(mySelector,situation) + + expect(result).to.deep.equal({}) + }); + it('should report missing variables in switch statements', function() { let rawRules = [ { nom: "startHere", formule: {"aiguillage numérique": {