⚙️ Basculer sur la nouvelle implémentation de findVariantsAndRecords

pull/18/head
Laurent Bossavit 2017-07-03 14:30:03 +02:00
parent dd779be0a0
commit f36cceaf2c
4 changed files with 6 additions and 37 deletions

View File

@ -109,12 +109,9 @@ export let buildNextSteps = (allRules, analysedSituation) => {
D'autres variables pourront être regroupées aussi, car elles partagent un parent, mais sans fusionner leurs questions dans l'interface. Ce sont des **groupes de type _record_ **
*/
// Ramda has trouble automatically currying this construction
let findVAR = (memo,name) => findVariantsAndRecords(allRules, memo, name, null)
return R.pipe(
R.keys,
R.reduce(findVAR, {variantGroups: {}, recordGroups: {}}),
R.curry(findVariantsAndRecords)(allRules),
// on va maintenant construire la liste des composants React qui afficheront les questions à l'utilisateur pour que l'on obtienne les variables manquantes
R.evolve({
variantGroups: generateGridQuestions(allRules, missingVariables),

View File

@ -152,7 +152,7 @@ export let collectMissingVariables = (groupMethod='groupByMissingVariable') => a
let isVariant = R.path(['formule', 'une possibilité'])
export let findVariantsAndRecords2 = (allRules, names) => {
export let findVariantsAndRecords = (allRules, names) => {
let tag = name => {
let parent = parentName(name),
gramps = parentName(parent),
@ -171,7 +171,7 @@ export let findVariantsAndRecords2 = (allRules, names) => {
return R.pipe(classify,groupByType,stripTypes,mergeLists)(names)
}
export let findVariantsAndRecords =
export let findVariantsAndRecords2 =
(allRules, {variantGroups, recordGroups}, dottedName, childDottedName) => {
let child = findRuleByDottedName(allRules, dottedName),
parentDottedName = parentName(dottedName),
@ -180,7 +180,7 @@ export let findVariantsAndRecords =
let grandParentDottedName = parentName(parentDottedName),
grandParent = findRuleByDottedName(allRules, grandParentDottedName)
if (isVariant(grandParent))
return findVariantsAndRecords(allRules, {variantGroups, recordGroups}, parentDottedName, childDottedName || dottedName)
return findVariantsAndRecords2(allRules, {variantGroups, recordGroups}, parentDottedName, childDottedName || dottedName)
else
return {
variantGroups: R.mergeWith(R.concat, variantGroups, {[parentDottedName]: [childDottedName || dottedName]}),

View File

@ -22,9 +22,4 @@ describe('buildNextSteps', function() {
expect(R.path(["question","props","label"])(result[0])).to.equal("?")
});
it('should generate questions from the real rule set', function() {
let situation = analyseSituation(rules,"surcoût CDD")(stateSelector),
result = buildNextSteps(rules, situation)
});
});

View File

@ -64,7 +64,7 @@ describe('findVariantsAndRecords', function() {
{nom: "cinq", espace: "top", question:"?"}],
rules = rawRules.map(enrichRule),
situation = analyseSituation(rules,"startHere")(stateSelector),
result = findVariantsAndRecords2(rules, ['top . cinq'])
result = findVariantsAndRecords(rules, ['top . cinq'])
expect(result).to.have.deep.property('recordGroups', {top: ['top . cinq']})
});
@ -77,32 +77,9 @@ describe('findVariantsAndRecords', function() {
{nom: "ko", espace: "top . sum . evt"}],
rules = rawRules.map(enrichRule),
situation = analyseSituation(rules,"sum")(stateSelector),
result = findVariantsAndRecords2(rules, ['top . sum . evt . ko'])
result = findVariantsAndRecords(rules, ['top . sum . evt . ko'])
expect(result).to.have.deep.property('variantGroups', {"top . sum . evt": ['top . sum . evt . ko']})
});
it('should find variants', function() {
let rawRules = [
{nom: "sum", formule: {somme: [2, "deux"]}, espace: "top"},
{nom: "deux", formule: 2, "non applicable si" : "top . sum . evt . ko", espace: "top"},
{nom: "evt", espace: "top . sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"},
{nom: "ko", espace: "top . sum . evt"}],
rules = rawRules.map(enrichRule),
situation = analyseSituation(rules,"sum")(stateSelector),
result = findVariantsAndRecords2(rules, ['top . sum . evt . ko'])
expect(result['variantGroups']).to.deep.equal({"top . sum . evt": ['top . sum . evt . ko']})
});
it('should provide equivalent function to findVAR with findVariants', function() {
let situation = analyseSituation(rules,"surcoût CDD")(stateSelector),
findVAR = (memo,name) => findVariantsAndRecords(rules, memo, name, null),
missing = collectMissingVariables()(situation),
newResult = R.pipe(R.keys,R.reduce(findVAR, {variantGroups: {}, recordGroups: {}}))(missing),
oldResult = findVariantsAndRecords2(rules, R.keys(missing))
expect(newResult).to.deep.equal(oldResult)
});
});