2017-07-01 09:17:54 +00:00
|
|
|
import R from 'ramda'
|
|
|
|
import {expect} from 'chai'
|
2017-07-11 14:39:05 +00:00
|
|
|
import {rules as realRules, enrichRule} from '../source/engine/rules'
|
2017-07-09 22:14:22 +00:00
|
|
|
import {analyseSituation, analyseTopDown} from '../source/engine/traverse'
|
2017-07-07 08:35:40 +00:00
|
|
|
import {buildNextSteps, collectMissingVariables, getObjectives} from '../source/engine/generateQuestions'
|
2017-07-01 09:17:54 +00:00
|
|
|
|
2017-07-11 14:00:10 +00:00
|
|
|
let stateSelector = (name) => null
|
2017-07-01 09:17:54 +00:00
|
|
|
|
2017-07-09 22:14:22 +00:00
|
|
|
describe('getObjectives', function() {
|
2017-07-07 08:35:40 +00:00
|
|
|
|
|
|
|
it('should derive objectives from the root rule', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
|
|
|
{nom: "deux", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"},
|
|
|
|
{nom: "evt", espace: "sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"},
|
|
|
|
{nom: "ko", espace: "sum . evt"}],
|
|
|
|
rules = rawRules.map(enrichRule),
|
2017-07-09 22:14:22 +00:00
|
|
|
{root, parsedRules} = analyseTopDown(rules,"startHere")(stateSelector),
|
2017-07-11 14:00:10 +00:00
|
|
|
result = getObjectives(stateSelector, root, parsedRules)
|
2017-07-07 08:35:40 +00:00
|
|
|
|
|
|
|
expect(result).to.have.lengthOf(1)
|
|
|
|
expect(result[0]).to.have.property('name','deux')
|
|
|
|
});
|
|
|
|
|
2017-07-09 22:14:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('collectMissingVariables', function() {
|
|
|
|
|
2017-07-07 08:35:40 +00:00
|
|
|
it('should identify missing variables', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
|
|
|
{nom: "deux", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"},
|
|
|
|
{nom: "evt", espace: "sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"},
|
|
|
|
{nom: "ko", espace: "sum . evt"}],
|
|
|
|
rules = rawRules.map(enrichRule),
|
2017-07-09 22:14:22 +00:00
|
|
|
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
2017-07-11 14:00:10 +00:00
|
|
|
result = collectMissingVariables()(stateSelector,situation)
|
2017-07-07 08:35:40 +00:00
|
|
|
|
|
|
|
expect(result).to.have.property('sum . evt . ko')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should identify missing variables mentioned in expressions', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
|
|
|
{nom: "deux", formule: 2, "non applicable si" : "evt . nyet > evt . nope", espace: "sum"},
|
|
|
|
{nom: "nope", espace: "sum . evt"},
|
|
|
|
{nom: "nyet", espace: "sum . evt"}],
|
|
|
|
rules = rawRules.map(enrichRule),
|
2017-07-09 22:14:22 +00:00
|
|
|
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
2017-07-11 14:00:10 +00:00
|
|
|
result = collectMissingVariables()(stateSelector,situation)
|
2017-07-07 08:35:40 +00:00
|
|
|
|
|
|
|
expect(result).to.have.property('sum . evt . nyet')
|
|
|
|
expect(result).to.have.property('sum . evt . nope')
|
|
|
|
});
|
|
|
|
|
2017-07-28 08:22:22 +00:00
|
|
|
it('should ignore missing variables in the formula if not applicable', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
|
|
|
{nom: "deux", formule: "trois", "non applicable si" : "3 > 2", espace: "sum"},
|
|
|
|
{nom: "trois", espace: "sum"}],
|
|
|
|
rules = rawRules.map(enrichRule),
|
2017-07-28 08:55:19 +00:00
|
|
|
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables()(stateSelector,situation)
|
|
|
|
|
|
|
|
expect(result).to.be.empty
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not report missing variables when "one of these" short-circuits', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: {somme: [2, "deux"]}, espace: "sum"},
|
|
|
|
{nom: "deux", formule: "trois", "non applicable si" : {"une de ces conditions": ["3 > 2", "trois"]}, espace: "sum"},
|
|
|
|
{nom: "trois", espace: "sum"}],
|
|
|
|
rules = rawRules.map(enrichRule),
|
2017-07-28 09:42:57 +00:00
|
|
|
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables()(stateSelector,situation)
|
|
|
|
|
|
|
|
expect(result).to.be.empty
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should report missing variables in switch statements', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
|
|
|
|
{ nom: "logic", formule: {"logique numérique": {
|
|
|
|
"11 > dix":"1000%",
|
|
|
|
"3 > dix":"1100%",
|
|
|
|
"1 > dix":"1200%"
|
|
|
|
}}, espace: "top"},
|
|
|
|
{nom: "dix", espace: "top"}],
|
|
|
|
rules = rawRules.map(enrichRule),
|
|
|
|
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables()(stateSelector,situation)
|
|
|
|
|
|
|
|
expect(result).to.have.property('top . dix')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not report missing variables in switch for consequences of false conditions', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
|
|
|
|
{ nom: "logic", formule: {"logique numérique": {
|
|
|
|
"11 > 10":"1000%",
|
|
|
|
"3 > 1":"1100%",
|
|
|
|
"1 > 2":"dix"
|
|
|
|
}}, espace: "top"},
|
|
|
|
{nom: "dix", espace: "top"}],
|
|
|
|
rules = rawRules.map(enrichRule),
|
|
|
|
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables()(stateSelector,situation)
|
|
|
|
|
|
|
|
expect(result).to.be.empty
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not report missing variables when a switch short-circuits', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{ nom: "startHere", formule: {somme: ["logic"]}, espace: "top"},
|
|
|
|
{ nom: "logic", formule: {"logique numérique": {
|
|
|
|
"11 > 10":"1000%",
|
|
|
|
"3 > dix":"1100%",
|
|
|
|
"1 > dix":"1200%"
|
|
|
|
}}, espace: "top"},
|
|
|
|
{nom: "dix", espace: "top"}],
|
|
|
|
rules = rawRules.map(enrichRule),
|
2017-07-28 08:22:22 +00:00
|
|
|
situation = analyseTopDown(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables()(stateSelector,situation)
|
|
|
|
|
|
|
|
expect(result).to.be.empty
|
|
|
|
});
|
|
|
|
|
2017-07-07 08:35:40 +00:00
|
|
|
});
|
|
|
|
|
2017-07-01 09:17:54 +00:00
|
|
|
describe('buildNextSteps', function() {
|
|
|
|
|
|
|
|
it('should generate questions', 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),
|
2017-07-11 14:00:10 +00:00
|
|
|
situation = analyseTopDown(rules,"sum")(stateSelector),
|
|
|
|
result = buildNextSteps(stateSelector, rules, situation)
|
2017-07-01 09:17:54 +00:00
|
|
|
|
|
|
|
expect(result).to.have.lengthOf(1)
|
|
|
|
expect(R.path(["question","props","label"])(result[0])).to.equal("?")
|
|
|
|
});
|
|
|
|
|
2017-07-11 14:39:05 +00:00
|
|
|
it('should generate questions from the real rules', function() {
|
|
|
|
let rules = realRules.map(enrichRule),
|
|
|
|
situation = analyseTopDown(rules,"surcoût CDD")(stateSelector),
|
|
|
|
objectives = getObjectives(stateSelector, situation.root, situation.parsedRules),
|
|
|
|
result = buildNextSteps(stateSelector, rules, situation)
|
|
|
|
|
|
|
|
expect(objectives).to.have.lengthOf(4)
|
2017-07-12 22:01:44 +00:00
|
|
|
expect(result).to.have.lengthOf(6)
|
2017-07-11 15:43:54 +00:00
|
|
|
expect(R.path(["question","props","label"])(result[0])).to.equal("Pensez-vous être confronté à l'un de ces événements au cours du contrat ?")
|
|
|
|
expect(R.path(["question","props","label"])(result[1])).to.equal("Quel est le motif de recours au CDD ?")
|
|
|
|
expect(R.path(["question","props","label"])(result[2])).to.equal("Quel est le salaire brut ?")
|
|
|
|
expect(R.path(["question","props","label"])(result[3])).to.equal("Est-ce un contrat jeune vacances ?")
|
2017-07-12 22:01:44 +00:00
|
|
|
expect(R.path(["question","props","label"])(result[4])).to.equal("Combien de jours de congés ne seront pas pris ?")
|
|
|
|
expect(R.path(["question","props","label"])(result[5])).to.equal("Quelle est la durée du contrat ?")
|
2017-07-11 14:39:05 +00:00
|
|
|
});
|
|
|
|
|
2017-07-01 09:17:54 +00:00
|
|
|
});
|