Ajoute un test pour le bug de cotisations

pull/513/head
Johan Girod 2019-04-11 15:23:46 +02:00 committed by Mael
parent 70c9dc2899
commit 87837ee2a3
5 changed files with 115 additions and 58 deletions

View File

@ -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(
</Link>
</div>
)}
{//flatRule.question &&
// Fonctionnalité intéressante, à implémenter correctement
false && <UserInput {...{ flatRules, dottedName }} />}
<Algorithm
rule={displayedRule}
showValues={valuesToShow || currentExample}
@ -221,15 +225,3 @@ let NamespaceRulesList = compose(
</section>
)
})
const UserInput = reduxForm({
form: 'conversation',
destroyOnUnmount: false
})(
class UserInput extends Component {
render() {
let { flatRules, dottedName } = this.props
return getInputComponent(flatRules)(dottedName)
}
}
)

View File

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

View File

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

View File

@ -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 = []) =>

View File

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