diff --git a/source/components/rule/Rule.js b/source/components/rule/Rule.js index 57f15574c..1b3f8454b 100644 --- a/source/components/rule/Rule.js +++ b/source/components/rule/Rule.js @@ -1,28 +1,35 @@ -import { T } from 'Components'; -import withColours from 'Components/utils/withColours'; -import withLanguage from 'Components/utils/withLanguage'; -import withSitePaths from 'Components/utils/withSitePaths'; -import { getInputComponent } from 'Engine/generateQuestions'; -import knownMecanisms from 'Engine/known-mecanisms.yaml'; -import { createMarkdownDiv } from 'Engine/marked'; -import { encodeRuleName, findRuleByDottedName, findRuleByNamespace } from 'Engine/rules'; -import { compose, isEmpty, isNil } from 'ramda'; -import React, { Component, Suspense } from 'react'; -import emoji from 'react-easy-emoji'; -import { Helmet } from 'react-helmet'; -import { Trans, withTranslation } from 'react-i18next'; -import { connect } from 'react-redux'; -import { Link } from 'react-router-dom'; -import { reduxForm } from 'redux-form'; -import { exampleAnalysisSelector, flatRulesSelector, noUserInputSelector, ruleAnalysisSelector } from 'Selectors/analyseSelectors'; -import Animate from 'Ui/animate'; -import Montant from 'Ui/Montant'; -import { AttachDictionary } from '../AttachDictionary'; -import Algorithm from './Algorithm'; -import Examples from './Examples'; -import RuleHeader from './Header'; -import References from './References'; -import './Rule.css'; +import { T } from 'Components' +import withColours from 'Components/utils/withColours' +import withLanguage from 'Components/utils/withLanguage' +import withSitePaths from 'Components/utils/withSitePaths' +import knownMecanisms from 'Engine/known-mecanisms.yaml' +import { createMarkdownDiv } from 'Engine/marked' +import { + encodeRuleName, + findRuleByDottedName, + findRuleByNamespace +} from 'Engine/rules' +import { compose, isEmpty, isNil } from 'ramda' +import React, { Component, Suspense } from 'react' +import emoji from 'react-easy-emoji' +import { Helmet } from 'react-helmet' +import { Trans, withTranslation } from 'react-i18next' +import { connect } from 'react-redux' +import { Link } from 'react-router-dom' +import { + exampleAnalysisSelector, + flatRulesSelector, + noUserInputSelector, + ruleAnalysisSelector +} from 'Selectors/analyseSelectors' +import Animate from 'Ui/animate' +import Montant from 'Ui/Montant' +import { AttachDictionary } from '../AttachDictionary' +import Algorithm from './Algorithm' +import Examples from './Examples' +import RuleHeader from './Header' +import References from './References' +import './Rule.css' let LazySource = React.lazy(() => import('./RuleSource')) @@ -132,9 +139,6 @@ export default compose( )} - {//flatRule.question && - // Fonctionnalité intéressante, à implémenter correctement - false && } ) }) - -const UserInput = reduxForm({ - form: 'conversation', - destroyOnUnmount: false -})( - class UserInput extends Component { - render() { - let { flatRules, dottedName } = this.props - return getInputComponent(flatRules)(dottedName) - } - } -) diff --git a/source/engine/evaluation.js b/source/engine/evaluation.js index fb9be18a6..e27bb97f6 100644 --- a/source/engine/evaluation.js +++ b/source/engine/evaluation.js @@ -1,17 +1,17 @@ import { add, - map, - pluck, any, equals, - reduce, - mergeWith, - fromPairs, - keys, - values, evolve, filter, - is + fromPairs, + is, + keys, + map, + mergeWith, + pluck, + reduce, + values } from 'ramda' export let makeJsx = node => diff --git a/source/engine/rules.js b/source/engine/rules.js index 381c278d4..93e529f56 100644 --- a/source/engine/rules.js +++ b/source/engine/rules.js @@ -1,12 +1,39 @@ // Séparation artificielle, temporaire, entre ces deux types de règles -import formValueTypes from 'Components/conversation/formValueTypes'; -import { assoc, chain, dropLast, find, fromPairs, has, identity, is, isNil, join, last, map, mapObjIndexed, path, pipe, propEq, props, range, reduce, reduced, reject, split, take, toPairs, trim, when } from 'ramda'; -import rawRules from 'Règles/base.yaml'; -import translations from 'Règles/externalized.yaml'; +import formValueTypes from 'Components/conversation/formValueTypes' +import { + assoc, + chain, + dropLast, + find, + fromPairs, + has, + identity, + is, + isNil, + join, + last, + map, + mapObjIndexed, + path, + pipe, + propEq, + props, + range, + reduce, + reduced, + reject, + split, + take, + toPairs, + trim, + when +} from 'ramda' +import rawRules from 'Règles/base.yaml' +import translations from 'Règles/externalized.yaml' // TODO - should be in UI, not engine -import { capitalise0 } from '../utils'; -import marked from './marked'; -import possibleVariableTypes from './possibleVariableTypes.yaml'; +import { capitalise0 } from '../utils' +import marked from './marked' +import possibleVariableTypes from './possibleVariableTypes.yaml' // console.log('rawRules', rawRules.map(({espace, nom}) => espace + nom)) /*********************************** @@ -224,7 +251,7 @@ export let translateAll = (translations, flatRules) => { 'sous-question', 'résumé', 'suggestions', - 'contrôles', + 'contrôles' ] return map(translateRule('en', translations, targets), flatRules) diff --git a/source/engine/variables.js b/source/engine/variables.js index 1fa5b93cd..a1b8148db 100644 --- a/source/engine/variables.js +++ b/source/engine/variables.js @@ -1,5 +1,5 @@ -import { isEmpty, dropLast, last } from 'ramda' -import { splitName, joinName } from './rules' +import { dropLast, isEmpty, last } from 'ramda' +import { joinName, splitName } from './rules' let evaluateBottomUp = situationGate => startingFragments => { let rec = (parentFragments, childFragments = []) => diff --git a/test/bug-cotisations.test.js b/test/bug-cotisations.test.js new file mode 100644 index 000000000..3c6d13275 --- /dev/null +++ b/test/bug-cotisations.test.js @@ -0,0 +1,38 @@ +import { expect } from 'chai' +import { enrichRule } from 'Engine/rules' +import { rules as realRules } from '../source/engine/rules' +import { analyse, analyseMany, parseAll } from '../source/engine/traverse' + +describe('bug-analyse-many', function() { + it.only('should compute the same contributions if asked with analyseMany or analyse', function() { + const situationSelector = dottedName => + ({ + 'contrat salarié . salaire . net après impôt': 10000, + 'auto entrepreneur': 'non', + 'contrat salarié': 'oui', + 'contrat salarié . assimilé salarié': 'oui', + 'contrat salarié . ATMP . taux réduit': 'oui', + 'contrat salarié . CDD': 'non', + 'contrat salarié . indemnité kilométrique vélo . indemnité vélo active': + 'non', + 'contrat salarié . avantages en nature . montant': 0, + 'contrat salarié . temps partiel': 'non', + 'établissement . localisation': {}, + 'contrat salarié . complémentaire santé . part employeur': 50, + 'contrat salarié . complémentaire santé . forfait . en france': 50, + 'entreprise . effectif': 1, + 'entreprise . association non lucrative': 'non' + }[dottedName]) + const rules = parseAll(realRules.map(enrichRule)) + const targets = [ + "entreprise . chiffre d'affaires", + 'contrat salarié . cotisations' + ] + const analyseManyValue = analyseMany(rules, targets)(situationSelector) + .targets[1] + const analyseValue = analyse(rules, 'contrat salarié . cotisations')( + situationSelector + ).targets[0] + expect(analyseManyValue.nodeValue).to.equal(analyseValue.nodeValue) + }) +})