Renommage de evaluateVariable

pull/337/head
Mael 2018-09-07 17:30:50 +02:00
parent c33d2471ee
commit dcf5e86f97
3 changed files with 14 additions and 16 deletions

View File

@ -2,7 +2,7 @@ import React from 'react'
import { Node, Leaf } from './mecanismViews/common'
import { findRuleByDottedName, disambiguateRuleReference } from './rules'
import { evaluateNode, rewriteNode, makeJsx } from './evaluation'
import { evaluateVariable } from './variables'
import { getSituationValue } from './variables'
import { Trans } from 'react-i18next'
export let treatVariable = (rules, rule, filter) => parseResult => {
@ -20,10 +20,9 @@ export let treatVariable = (rules, rule, filter) => parseResult => {
variableHasCond =
variable['applicable si'] != null ||
variable['non applicable si'] != null,
situationValue = evaluateVariable(situation, dottedName, variable),
situationValue = getSituationValue(situation, dottedName, variable),
needsEvaluation =
situationValue == null && (variableHasCond || variableHasFormula),
// evaluateVariable renvoit la valeur déduite de la situation courante renseignée par l'utilisateur
explanation = needsEvaluation
? evaluateNode(cache, situation, parsedRules, variable)
: variable

View File

@ -23,10 +23,9 @@ let evaluateBottomUp = situationGate => startingFragments => {
}
let formatBooleanValue = { oui: true, non: false }
/* Evalue la valeur d'une variable
en utilisant la fonction situationGate qui donne accès à la situation courante*/
export let evaluateVariable = (situationGate, variableName, rule) => {
// test rec
export let getSituationValue = (situationGate, variableName, rule) => {
// get the current situation value
// it's the user input or test input, possibly with default values
let value = situationGate(variableName)
if (rule.API) return typeof value == 'string' ? JSON.parse(value) : value

View File

@ -1,13 +1,13 @@
import { expect } from 'chai'
import { evaluateBottomUp, evaluateVariable } from '../source/engine/variables'
import { evaluateBottomUp, getSituationValue } from '../source/engine/variables'
describe('evaluateVariable', function() {
describe('getSituationValue', function() {
it('should directly return the value of any rule that specifies a format (i.e currency, duration)', function() {
let rule = { format: 'euros' },
state = { salaire: '2300' },
situationGate = name => state[name]
expect(evaluateVariable(situationGate, 'salaire', rule)).to.equal('2300')
expect(getSituationValue(situationGate, 'salaire', rule)).to.equal('2300')
})
it("should interpret rules without a formula as boolean-valued, with 'oui' for true", function() {
@ -15,7 +15,7 @@ describe('evaluateVariable', function() {
state = { condition: 'oui' },
situationGate = name => state[name]
expect(evaluateVariable(situationGate, 'condition', rule)).to.be.true
expect(getSituationValue(situationGate, 'condition', rule)).to.be.true
})
it("should interpret rules without a formula as boolean-valued, with 'non' meaning false", function() {
@ -23,7 +23,7 @@ describe('evaluateVariable', function() {
state = { condition: 'non' },
situationGate = name => state[name]
expect(evaluateVariable(situationGate, 'condition', rule)).to.be.false
expect(getSituationValue(situationGate, 'condition', rule)).to.be.false
})
it("should interpret rules with 'one of these', with 'oui' for true", function() {
@ -31,7 +31,7 @@ describe('evaluateVariable', function() {
state = { condition: 'oui' },
situationGate = name => state[name]
expect(evaluateVariable(situationGate, 'condition', rule)).to.be.true
expect(getSituationValue(situationGate, 'condition', rule)).to.be.true
})
it('should walk up the namespace chain until it finds the tail as the value', function() {
@ -42,7 +42,7 @@ describe('evaluateVariable', function() {
situationGate = name => state[name]
expect(
evaluateVariable(
getSituationValue(
situationGate,
'contrat salarié . CDD . motif . classique . accroissement activité',
rule
@ -56,7 +56,7 @@ describe('evaluateVariable', function() {
situationGate = name => state[name]
expect(
evaluateVariable(
getSituationValue(
situationGate,
'contrat salarié . CDD . motif . classique . accroissement activité',
rule
@ -73,7 +73,7 @@ describe('evaluateVariable', function() {
state = { 'univers . ici': 'blanc' },
situationGate = name => state[name]
expect(evaluateVariable(situationGate, 'univers . ici . noir', rule)).to.be
expect(getSituationValue(situationGate, 'univers . ici . noir', rule)).to.be
.false
})
})