2019-06-05 16:11:29 +00:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { enrichRule, rulesFr as rules } from 'Engine/rules'
|
|
|
|
import { assocPath, merge } from 'ramda'
|
|
|
|
import reducers from 'Reducers/rootReducer'
|
|
|
|
import salariéConfig from '../source/components/simulationConfigs/salarié.yaml'
|
|
|
|
import {
|
|
|
|
currentQuestionSelector,
|
|
|
|
nextStepsSelector
|
|
|
|
} from '../source/selectors/analyseSelectors'
|
2018-06-18 10:12:08 +00:00
|
|
|
let baseState = {
|
|
|
|
conversationSteps: { foldedSteps: [] },
|
2019-09-17 18:10:27 +00:00
|
|
|
simulation: { situation: {} }
|
2018-06-18 10:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('conversation', function() {
|
|
|
|
it('should start with the first missing variable', function() {
|
|
|
|
let rawRules = [
|
|
|
|
// TODO - this won't work without the indirection, figure out why
|
2019-10-11 15:01:11 +00:00
|
|
|
{ nom: 'top . startHere', formule: { somme: ['a', 'b'] } },
|
|
|
|
{ nom: 'top . a', formule: 'aa' },
|
|
|
|
{ nom: 'top . b', formule: 'bb' },
|
|
|
|
{ nom: 'top . aa', question: '?', titre: 'a' },
|
|
|
|
{ nom: 'top . bb', question: '?', titre: 'b' }
|
2018-06-18 10:12:08 +00:00
|
|
|
],
|
|
|
|
rules = rawRules.map(enrichRule),
|
|
|
|
state = merge(baseState, {
|
2019-06-05 16:11:29 +00:00
|
|
|
simulation: { config: { objectifs: ['startHere'] } }
|
2018-06-18 10:12:08 +00:00
|
|
|
}),
|
|
|
|
currentQuestion = currentQuestionSelector(state, { rules })
|
|
|
|
|
|
|
|
expect(currentQuestion).to.equal('top . aa')
|
|
|
|
})
|
|
|
|
it('should deal with double unfold', function() {
|
|
|
|
let rawRules = [
|
|
|
|
// TODO - this won't work without the indirection, figure out why
|
|
|
|
{
|
2019-10-11 15:01:11 +00:00
|
|
|
nom: 'top . startHere',
|
|
|
|
formule: { somme: ['a', 'b', 'c'] }
|
2018-06-18 10:12:08 +00:00
|
|
|
},
|
2019-10-11 15:01:11 +00:00
|
|
|
{ nom: 'top . a', formule: 'aa' },
|
|
|
|
{ nom: 'top . b', formule: 'bb' },
|
|
|
|
{ nom: 'top . c', formule: 'cc' },
|
|
|
|
{ nom: 'top . aa', question: '?', titre: 'a' },
|
|
|
|
{ nom: 'top . bb', question: '?', titre: 'b' },
|
|
|
|
{ nom: 'top . cc', question: '?', titre: 'c' }
|
2018-06-18 10:12:08 +00:00
|
|
|
],
|
|
|
|
rules = rawRules.map(enrichRule)
|
|
|
|
|
|
|
|
let step1 = merge(baseState, {
|
2019-09-17 18:10:27 +00:00
|
|
|
rules,
|
2019-06-05 16:11:29 +00:00
|
|
|
simulation: { config: { objectifs: ['startHere'] } }
|
2018-06-18 10:12:08 +00:00
|
|
|
})
|
|
|
|
let step2 = reducers(
|
2019-09-17 18:10:27 +00:00
|
|
|
assocPath(['simulation', 'situation'], { 'top . aa': '1' }, step1),
|
2018-06-18 10:12:08 +00:00
|
|
|
{
|
|
|
|
type: 'STEP_ACTION',
|
|
|
|
name: 'fold',
|
|
|
|
step: 'top . aa'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
let step3 = reducers(
|
|
|
|
assocPath(
|
2019-09-17 18:10:27 +00:00
|
|
|
['simulation', 'situation'],
|
|
|
|
{ 'top . aa': '1', 'top . bb': '1' },
|
2018-06-18 10:12:08 +00:00
|
|
|
step2
|
|
|
|
),
|
|
|
|
{
|
|
|
|
type: 'STEP_ACTION',
|
|
|
|
name: 'fold',
|
|
|
|
step: 'top . bb'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
let step4 = reducers(step3, {
|
|
|
|
type: 'STEP_ACTION',
|
|
|
|
name: 'unfold',
|
|
|
|
step: 'top . aa'
|
|
|
|
})
|
|
|
|
let lastStep = reducers(step4, {
|
|
|
|
type: 'STEP_ACTION',
|
|
|
|
name: 'unfold',
|
|
|
|
step: 'top . bb'
|
|
|
|
})
|
|
|
|
|
2019-09-17 18:10:27 +00:00
|
|
|
expect(currentQuestionSelector(lastStep)).to.equal('top . bb')
|
2018-06-18 10:12:08 +00:00
|
|
|
expect(lastStep.conversationSteps).to.have.property('foldedSteps')
|
2019-06-05 16:11:29 +00:00
|
|
|
expect(lastStep.conversationSteps.foldedSteps).to.have.lengthOf(0)
|
2018-06-18 10:12:08 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should first ask for questions without defaults, then those with defaults', function() {
|
2019-02-01 12:31:57 +00:00
|
|
|
let rawRules = [
|
2019-06-05 16:11:29 +00:00
|
|
|
{ nom: 'net', formule: 'brut - cotisation' },
|
|
|
|
{
|
|
|
|
nom: 'brut',
|
|
|
|
question: 'Quel est le salaire brut ?',
|
2019-07-05 13:00:24 +00:00
|
|
|
unité: '€'
|
2019-06-05 16:11:29 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
nom: 'cotisation',
|
|
|
|
formule: {
|
|
|
|
multiplication: {
|
|
|
|
assiette: 'brut',
|
|
|
|
variations: [
|
|
|
|
{
|
|
|
|
si: 'cadre',
|
|
|
|
alors: {
|
|
|
|
taux: '77%'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sinon: {
|
|
|
|
taux: '80%'
|
|
|
|
}
|
2019-02-01 12:31:57 +00:00
|
|
|
}
|
2019-06-05 16:11:29 +00:00
|
|
|
]
|
|
|
|
}
|
2019-02-01 12:31:57 +00:00
|
|
|
}
|
2019-06-05 16:11:29 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
nom: 'cadre',
|
|
|
|
question: 'Est-ce un cadre ?',
|
|
|
|
'par défaut': 'non'
|
2019-02-01 12:31:57 +00:00
|
|
|
}
|
2019-06-05 16:11:29 +00:00
|
|
|
],
|
2019-02-01 12:31:57 +00:00
|
|
|
rules = rawRules.map(enrichRule)
|
2018-06-18 10:12:08 +00:00
|
|
|
|
|
|
|
let step1 = merge(baseState, {
|
2019-09-17 18:10:27 +00:00
|
|
|
rules,
|
2019-06-05 16:11:29 +00:00
|
|
|
simulation: { config: { objectifs: ['net'] } }
|
2018-06-18 10:12:08 +00:00
|
|
|
})
|
2019-09-17 18:10:27 +00:00
|
|
|
expect(currentQuestionSelector(step1)).to.equal('brut')
|
2018-06-18 10:12:08 +00:00
|
|
|
|
|
|
|
let step2 = reducers(
|
2019-09-17 18:10:27 +00:00
|
|
|
assocPath(['simulation', 'situation', 'brut'], '2300', step1),
|
2018-06-18 10:12:08 +00:00
|
|
|
{
|
|
|
|
type: 'STEP_ACTION',
|
|
|
|
name: 'fold',
|
|
|
|
step: 'brut'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(step2.conversationSteps).to.have.property('foldedSteps')
|
|
|
|
expect(step2.conversationSteps.foldedSteps).to.have.lengthOf(1)
|
|
|
|
expect(step2.conversationSteps.foldedSteps[0]).to.equal('brut')
|
|
|
|
expect(currentQuestionSelector(step2, { rules })).to.equal('cadre')
|
|
|
|
})
|
|
|
|
})
|
2018-06-19 08:30:43 +00:00
|
|
|
describe('real conversation', function() {
|
|
|
|
it('should not have more than X questions', function() {
|
|
|
|
let state = merge(baseState, {
|
2019-06-05 16:11:29 +00:00
|
|
|
simulation: { config: salariéConfig }
|
2018-06-19 08:30:43 +00:00
|
|
|
}),
|
|
|
|
nextSteps = nextStepsSelector(state, { rules })
|
|
|
|
|
|
|
|
expect(nextSteps.length).to.be.below(30) // If this breaks, that's good news
|
|
|
|
expect(nextSteps.length).to.be.above(10)
|
|
|
|
})
|
|
|
|
})
|