diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js
index 6a82194d7..d58d6f5b2 100644
--- a/source/engine/mecanisms.js
+++ b/source/engine/mecanisms.js
@@ -136,28 +136,28 @@ export let mecanismNumericalLogic = (recurse, k,v) => {
conditionNode = recurse(condition), // can be a 'comparison', a 'variable', TODO a 'negation'
consequenceNode = mecanismNumericalLogic(recurse, condition, consequence)
- let evaluate = (situationGate, parsedRules, node) => {
- let collectMissing = node => {
- let leftMissing = collectNodeMissing(node.explanation.condition),
- investigate = node.explanation.condition.nodeValue == true,
- rightMissing = investigate ? collectNodeMissing(node.explanation.consequence) : []
- return R.concat(leftMissing, rightMissing)
- }
-
- let explanation = R.evolve({
- condition: R.curry(evaluateNode)(situationGate, parsedRules),
- consequence: R.curry(evaluateNode)(situationGate, parsedRules)
- },node.explanation)
-
- return {
- ...node,
- collectMissing,
- explanation,
- nodeValue: explanation.consequence.nodeValue,
- condValue: explanation.condition.nodeValue
- }
+ let evaluate = (situationGate, parsedRules, node) => {
+ let collectMissing = node => {
+ let missingOnTheLeft = collectNodeMissing(node.explanation.condition),
+ investigate = node.explanation.condition.nodeValue !== false,
+ missingOnTheRight = investigate ? collectNodeMissing(node.explanation.consequence) : []
+ return R.concat(missingOnTheLeft, missingOnTheRight)
}
+ let explanation = R.evolve({
+ condition: R.curry(evaluateNode)(situationGate, parsedRules),
+ consequence: R.curry(evaluateNode)(situationGate, parsedRules)
+ },node.explanation)
+
+ return {
+ ...node,
+ collectMissing,
+ explanation,
+ nodeValue: explanation.consequence.nodeValue,
+ condValue: explanation.condition.nodeValue
+ }
+ }
+
let jsx = (nodeValue, {condition, consequence}) =>
{makeJsx(condition)}
diff --git a/test/generateQuestions.test.js b/test/generateQuestions.test.js
index 655c673de..bf1d0b4cd 100644
--- a/test/generateQuestions.test.js
+++ b/test/generateQuestions.test.js
@@ -109,6 +109,32 @@ describe('collectMissingVariables', function() {
expect(result).to.deep.equal({})
});
+ it('should report missing variables in consequence even if its condition is unresolved', function() {
+ let rawRules = [
+ { nom: "startHere", formule: { somme: ["logic"] }, espace: "top" },
+ { nom: "logic",
+ formule: {
+ "logique numérique": {
+ "10 > 11": "1000%",
+ "3 > dix": {
+ "douze": "560%",
+ "1 > 2": "75015%" }
+ }
+ },
+ espace: "top"
+ },
+ { nom: "douze", espace: "top" },
+ { nom: "dix", espace: "top" }
+ ],
+ rules = rawRules.map(enrichRule),
+ situation = analyseTopDown(rules, "startHere")(stateSelector),
+ result = collectMissingVariables()(stateSelector, situation);
+
+
+ expect(result).to.have.property('top . dix')
+ expect(result).to.have.property('top . douze')
+ });
+
it('should not report missing variables when a switch short-circuits', function() {
let rawRules = [
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
@@ -155,8 +181,8 @@ describe('buildNextSteps', function() {
expect(R.path(["question","props","label"])(result[1])).to.equal("Quel est le motif de recours au CDD ?")
expect(R.path(["question","props","label"])(result[2])).to.equal("Quel est le salaire brut ?")
expect(R.path(["question","props","label"])(result[3])).to.equal("Est-ce un contrat jeune vacances ?")
- expect(R.path(["question","props","label"])(result[4])).to.equal("Combien de jours de congés ne seront pas pris ?")
- expect(R.path(["question","props","label"])(result[5])).to.equal("Quelle est la durée du contrat ?")
+ expect(R.path(["question","props","label"])(result[4])).to.equal("Quelle est la durée du contrat ?")
+ expect(R.path(["question","props","label"])(result[5])).to.equal("Combien de jours de congés ne seront pas pris ?")
});
});