🐛 simplifie le code pour plier/déplier pour corriger les doublons d'unfold
parent
ad291efa1d
commit
1aef35d7a4
|
@ -97,14 +97,14 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (state, action) =
|
|||
tracker.push(['trackEvent', 'unfold', action.step]);
|
||||
|
||||
let stepFinder = R.propEq('name', action.step),
|
||||
foldedSteps = R.reject(stepFinder)(state.foldedSteps).concat(state.unfoldedSteps),
|
||||
extraSteps = R.reject(stepFinder)(state.extraSteps)
|
||||
previous = R.head(state.unfoldedSteps),
|
||||
foldedSteps = R.reject(stepFinder)(R.concat(state.foldedSteps, previous ? [previous] : [])),
|
||||
unfolded = R.find(stepFinder)(R.concat(state.foldedSteps, state.extraSteps))
|
||||
|
||||
return {
|
||||
...newState,
|
||||
foldedSteps,
|
||||
extraSteps,
|
||||
unfoldedSteps: [R.find(stepFinder)(R.concat(state.foldedSteps,state.extraSteps))]
|
||||
unfoldedSteps: R.concat([unfolded], state.unfoldedSteps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,11 +40,13 @@ describe('fold', function() {
|
|||
|
||||
let rawRules = [
|
||||
// TODO - this won't work without the indirection, figure out why
|
||||
{nom: "startHere", formule: {somme: ["a","b"]}, espace: "top"},
|
||||
{nom: "startHere", formule: {somme: ["a","b","c"]}, espace: "top"},
|
||||
{nom: "a", espace: "top", formule: "aa"},
|
||||
{nom: "b", espace: "top", formule: "bb"},
|
||||
{nom: "c", espace: "top", formule: "cc"},
|
||||
{nom: "aa", question: "?", titre: "a", espace: "top"},
|
||||
{nom: "bb", question: "?", titre: "b", espace: "top"}],
|
||||
{nom: "bb", question: "?", titre: "b", espace: "top"},
|
||||
{nom: "cc", question: "?", titre: "c", espace: "top"}],
|
||||
rules = rawRules.map(enrichRule),
|
||||
reducer = reduceSteps(tracker, rules, stateSelector)
|
||||
|
||||
|
@ -59,11 +61,12 @@ describe('fold', function() {
|
|||
let result = step5
|
||||
|
||||
expect(result).to.have.property('unfoldedSteps')
|
||||
expect(result.unfoldedSteps).to.have.lengthOf(1)
|
||||
expect(result.unfoldedSteps).to.have.lengthOf(3)
|
||||
expect(result.unfoldedSteps[0]).to.have.deep.property("name","top . bb")
|
||||
expect(result).to.have.property('foldedSteps')
|
||||
expect(result.foldedSteps).to.have.lengthOf(1)
|
||||
expect(result.foldedSteps[0]).to.have.deep.property("name","top . aa")
|
||||
expect(result.foldedSteps).to.have.lengthOf(2)
|
||||
expect(result.foldedSteps[0]).to.have.deep.property("name","top . cc")
|
||||
expect(result.foldedSteps[1]).to.have.deep.property("name","top . aa")
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue