From 2223bd27923dfec93bf3ec8766746498576d553a Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Wed, 14 Oct 2020 17:55:26 +0200 Subject: [PATCH] =?UTF-8?q?:racehorse:=20rends=20paresseuse=20l'=C3=A9valu?= =?UTF-8?q?ation=20du=20m=C3=A9canisme=20"toutes=20ces=20conditions"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/mon-entreprise/simulateurs.js | 4 +-- .../source/mecanisms/condition-allof.tsx | 28 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs.js index e2c322570..325e631f3 100644 --- a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs.js +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs.js @@ -28,13 +28,13 @@ describe('Simulateurs', function() { cy.get(chargeInputSelector).type(1000) } cy.get(inputSelector).each((testedInput, i) => { - cy.wrap(testedInput).type('{selectall}60003') + cy.wrap(testedInput).type('{selectall}60100') cy.wait(1500) cy.contains('Cotisations') cy.get(inputSelector).each(($input, j) => { const val = $input.val().replace(/[\s,.]/g, '') if (i != j) { - expect(val).not.to.be.eq('60003') + expect(val).not.to.be.eq('60100') } expect(val).to.match(/[1-9][\d]{3,6}$/) }) diff --git a/publicodes/source/mecanisms/condition-allof.tsx b/publicodes/source/mecanisms/condition-allof.tsx index ec13b6640..15c37ad22 100644 --- a/publicodes/source/mecanisms/condition-allof.tsx +++ b/publicodes/source/mecanisms/condition-allof.tsx @@ -4,16 +4,28 @@ import { Mecanism } from '../components/mecanisms/common' import { evaluateNode, makeJsx, mergeAllMissing } from '../evaluation' const evaluate = (cache, situation, parsedRules, node) => { - const evaluateOne = child => - evaluateNode(cache, situation, parsedRules, child) - const explanation = map(evaluateOne, node.explanation) - const anyFalse = explanation.find(e => e.nodeValue === false) // court-circuit - const { nodeValue, missingVariables } = anyFalse ?? { - nodeValue: explanation.some(e => e.nodeValue === null) ? null : true, + const [nodeValue, explanation] = node.explanation.reduce( + ([nodeValue, explanation], node) => { + if (nodeValue === false) { + return [nodeValue, [...explanation, node]] + } + const evaluatedNode = evaluateNode(cache, situation, parsedRules, node) + return [ + nodeValue === false || nodeValue === null + ? nodeValue + : evaluatedNode.nodeValue, + [...explanation, evaluatedNode] + ] + }, + [true, []] + ) + + return { + ...node, + nodeValue, + explanation, missingVariables: mergeAllMissing(explanation) } - - return { ...node, nodeValue, explanation, missingVariables } } export const mecanismAllOf = (recurse, v) => {