🐎 rends paresseuse l'évaluation du mécanisme "toutes ces conditions"

pull/1165/head
Johan Girod 2020-10-14 17:55:26 +02:00
parent 991fa0c40e
commit 2223bd2792
2 changed files with 22 additions and 10 deletions

View File

@ -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}$/)
})

View File

@ -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) => {