From 2166968c412d6f4dbbbcedefd1510d13b2667308 Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Sat, 14 Oct 2017 22:11:56 +0200 Subject: [PATCH] =?UTF-8?q?:x:=20Mettre=20en=20=C3=A9vidence=20le=20bug=20?= =?UTF-8?q?du=20double=20unfold?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/reducers.test.js | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/test/reducers.test.js b/test/reducers.test.js index 0a55c5560..85d012ae9 100644 --- a/test/reducers.test.js +++ b/test/reducers.test.js @@ -1,3 +1,5 @@ +import R from 'ramda' + import {expect} from 'chai' import {rules as realRules, enrichRule} from '../source/engine/rules' import {analyseSituation, analyseTopDown} from '../source/engine/traverse' @@ -6,19 +8,20 @@ import {buildNextSteps, collectMissingVariables, getObjectives} from '../source/ import {reduceSteps} from '../source/reducers' let stateSelector = state => name => null +let tracker = {push: array => 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 + // 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), + reducer = reduceSteps(tracker, rules, stateSelector), action = {type:'START_CONVERSATION', rootVariable: 'startHere'}, // situation = analyseTopDown(rules,"startHere")(stateSelector({})), // objectives = getObjectives(stateSelector({}), situation.root, situation.parsedRules), @@ -31,4 +34,36 @@ describe('fold', function() { expect(result.unfoldedSteps[1]).to.have.deep.property("name","top . bb") }); + it('should deal with double unfold', function() { + let fakeState = {} + let stateSelector = state => name => fakeState[name] + + 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(tracker, rules, stateSelector) + + var step1 = reducer({},{type:'START_CONVERSATION', rootVariable: 'startHere'}) + fakeState['top . aa'] = 1 + var step2 = reducer(step1,{type:'STEP_ACTION', name: 'fold', step: 'top . aa'}) + fakeState['top . bb'] = 1 + var step3 = reducer(step2,{type:'STEP_ACTION', name: 'fold', step: 'top . bb'}) + var step4 = reducer(step3,{type:'STEP_ACTION', name: 'unfold', step: 'top . aa'}) + var step5 = reducer(step4,{type:'STEP_ACTION', name: 'unfold', step: 'top . bb'}) + + let result = step5 + + expect(result).to.have.property('unfoldedSteps') + expect(result.unfoldedSteps).to.have.lengthOf(1) + expect(result.unfoldedSteps[0]).to.have.deep.property("name","top . bb") + expect(result).to.have.property('foldedSteps') + expect(result.unfoldedSteps).to.have.lengthOf(1) + expect(result.unfoldedSteps[0]).to.have.deep.property("name","top . aa") + }); + });