Introduit des tests pour reduceSteps

pull/104/head
Laurent Bossavit 2017-10-14 16:50:20 +02:00 committed by mama
parent 61e11a648b
commit 6ba339cef1
2 changed files with 40 additions and 7 deletions

View File

@ -23,10 +23,7 @@ let assume = (evaluator, assumptions) => state => name => {
return userInput != null ? userInput : assumptions[name]
}
export let reduceSteps = (state, action) => {
let flatRules = rules
export let reduceSteps = (flatRules, answerSource) => (state, action) => {
if (![START_CONVERSATION, STEP_ACTION].includes(action.type))
return state
@ -38,7 +35,7 @@ export let reduceSteps = (state, action) => {
hardAssumptions = R.pathOr({},['simulateur','hypothèses'],sim),
// Soft assumptions are revealed after the simulation ends, and can be changed
softAssumptions = R.pathOr({},['simulateur','par défaut'],sim),
intermediateSituation = assume(fromConversation, hardAssumptions),
intermediateSituation = assume(answerSource, hardAssumptions),
completeSituation = assume(intermediateSituation,softAssumptions)
let situationGate = completeSituation(state),
@ -52,10 +49,12 @@ export let reduceSteps = (state, action) => {
}
if (action.type == START_CONVERSATION) {
let unfoldedSteps = buildNextSteps(situationGate, flatRules, newState.analysedSituation)
return {
...newState,
foldedSteps: [],
unfoldedSteps: buildNextSteps(situationGate, flatRules, newState.analysedSituation)
unfoldedSteps
}
}
if (action.type == STEP_ACTION && action.name == 'fold') {
@ -148,5 +147,5 @@ export default reduceReducers(
}),
// cross-cutting concerns because here `state` is the whole state tree
reduceSteps
reduceSteps(rules, fromConversation)
)

34
test/reducers.test.js Normal file
View File

@ -0,0 +1,34 @@
import {expect} from 'chai'
import {rules as realRules, enrichRule} from '../source/engine/rules'
import {analyseSituation, analyseTopDown} from '../source/engine/traverse'
import {buildNextSteps, collectMissingVariables, getObjectives} from '../source/engine/generateQuestions'
import {reduceSteps} from '../source/reducers'
let stateSelector = state => name => null
describe('fold', function() {
it('should start conversation with only unfolded questions', function() {
let rawRules = [
// TODO - this won't work without the indirection, figure out why
{nom: "startHere", formule: {somme: ["a","b"]}, espace: "top"},
{nom: "a", espace: "top", formule: "aa"},
{nom: "b", espace: "top", formule: "bb"},
{nom: "aa", question: "?", titre: "a", espace: "top"},
{nom: "bb", question: "?", titre: "b", espace: "top"}],
rules = rawRules.map(enrichRule),
reducer = reduceSteps(rules, stateSelector),
action = {type:'START_CONVERSATION', rootVariable: 'startHere'},
// situation = analyseTopDown(rules,"startHere")(stateSelector({})),
// objectives = getObjectives(stateSelector({}), situation.root, situation.parsedRules),
// missing = collectMissingVariables()(stateSelector({}),situation),
result = reducer({},action)
expect(result).to.have.property('unfoldedSteps')
expect(result.unfoldedSteps).to.have.lengthOf(2)
expect(result.unfoldedSteps[0]).to.have.deep.property("name","top . aa")
expect(result.unfoldedSteps[1]).to.have.deep.property("name","top . bb")
});
});