🐛 corrige l'ordre des questions en cas de réponse à une possibilité

pull/993/head
Johan Girod 2020-04-23 10:11:29 +02:00
parent 7ccc4ce4e3
commit 95e8d53103
4 changed files with 76 additions and 30 deletions

View File

@ -74,24 +74,6 @@ describe('Simulateurs', function() {
.should('be', '2000')
})
if (simulateur === 'salarié') {
it('should save the current simulation', function() {
cy.get(inputSelector)
.first()
.type('{selectall}2137')
cy.contains('Passer').click()
cy.contains('Passer').click()
cy.contains('Passer').click()
cy.wait(1600)
cy.visit('/simulateurs/salarié')
cy.contains('Retrouver ma simulation').click()
cy.get(inputSelector)
.first()
.invoke('val')
.should('match', /2[\s]137/)
})
}
if (simulateur === 'auto-entrepreneur') {
it('should allow to enter the date of creation', () => {
cy.get(inputSelector)
@ -118,3 +100,46 @@ describe('Simulateurs', function() {
})
)
})
describe.only('Simulateur salarié', () => {
if (!fr) {
return
}
before(() => cy.visit(`/simulateurs/salarié`))
it('should save the current simulation', function() {
cy.get(inputSelector)
.first()
.type('{selectall}2137')
cy.contains('Passer').click()
cy.contains('Passer').click()
cy.contains('Passer').click()
cy.wait(1600)
cy.visit('/simulateurs/salarié')
cy.contains('Retrouver ma simulation').click()
cy.get(inputSelector)
.first()
.invoke('val')
.should('match', /2[\s]137/)
})
it('should ask for CDD motif directly after CDD is selected', function() {
cy.get(inputSelector)
.eq(1)
.type('{selectall}3000')
cy.wait(1000)
cy.get('.step')
.find('input[value="\'CDD\'"]')
.click({ force: true })
cy.contains('Suivant').click()
cy.contains('Motifs classiques')
})
it.skip('should not crash when selecting localisation', function() {
cy.contains('Commune').click()
cy.contains("Saisissez le nom d'une commune").type('Steenvoorde')
cy.contains('Steenvoorde (Nord)').click()
cy.contains('Voir toutes les questions').click()
cy.contains('Steenvoorde')
})
})

View File

@ -60,7 +60,12 @@
}
.step.question input[type='radio'] {
display: none;
opacity: 0;
width: 0;
height: 0;
margin: 0;
position: absolute;
z-index: -1;
}
.step input[type='text'],

View File

@ -31,11 +31,12 @@ import {
objectifsSelector,
configSelector,
answeredQuestionsSelector,
currentQuestionSelector
currentQuestionSelector,
situationSelector
} from 'Selectors/simulationSelectors'
import { useMemo } from 'react'
import { DottedName } from 'Rules'
import { SimulationConfig } from 'Reducers/rootReducer'
import { Simulation, SimulationConfig } from 'Reducers/rootReducer'
type MissingVariables = Array<Partial<Record<DottedName, number>>>
export function getNextSteps(
@ -70,14 +71,14 @@ const similarity = (rule1: string = '', rule2: string = '') =>
export function getNextQuestions(
missingVariables: MissingVariables,
questionConfig: SimulationConfig['questions'] = {},
answeredQuestions = []
answeredQuestions = [],
situation: Simulation['situation'] = {}
): Array<DottedName> {
const {
'non prioritaires': notPriority = [],
uniquement: only = null,
'liste noire': blacklist = []
} = questionConfig
// console.log(missingVariables)
let nextSteps = difference(getNextSteps(missingVariables), answeredQuestions)
if (only) {
@ -89,16 +90,19 @@ export function getNextQuestions(
const lastStep = last(answeredQuestions)
// L'ajout de la réponse permet de traiter les questions dont la réponse est "une possibilité", exemple "contrat salarié . cdd"
// lastStepWithAnswer =
// lastStep && situation[lastStep]
// ? ([lastStep, situation[lastStep]].join(' . ') as DottedName)
// : lastStep
const lastStepWithAnswer =
lastStep && situation[lastStep]
? ([lastStep, situation[lastStep]]
.join(' . ')
.replace(/'/g, '')
.trim() as DottedName)
: lastStep
return sortBy(
question =>
notPriority.includes(question)
? notPriority.indexOf(question)
: similarity(question, lastStep),
: similarity(question, lastStepWithAnswer),
nextSteps
)
@ -109,6 +113,7 @@ export const useNextQuestions = function(): Array<DottedName> {
const answeredQuestions = useSelector(answeredQuestionsSelector)
const currentQuestion = useSelector(currentQuestionSelector)
const questionsConfig = useSelector(configSelector).questions ?? {}
const situation = useSelector(situationSelector)
const missingVariables = useEvaluation(objectifs, {
useDefaultValues: false
}).map(node => node.missingVariables ?? {})
@ -116,7 +121,8 @@ export const useNextQuestions = function(): Array<DottedName> {
return getNextQuestions(
missingVariables,
questionsConfig,
answeredQuestions
answeredQuestions,
situation
)
}, [missingVariables, questionsConfig, answeredQuestions])
if (currentQuestion && currentQuestion !== nextQuestions[0]) {

View File

@ -1818,7 +1818,7 @@ ajv@6.5.3:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"
ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.0, ajv@^6.5.5:
ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.0:
version "6.12.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.0.tgz#06d60b96d87b8454a5adaba86e7854da629db4b7"
integrity sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==
@ -1828,6 +1828,16 @@ ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.0, ajv@^6.5.5:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"
ajv@^6.5.5:
version "6.12.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd"
integrity sha512-k+V+hzjm5q/Mr8ef/1Y9goCmlsK4I6Sm74teeyGvFk1XrOsbsKLjEdrvny42CZ+a8sXbk8KWpY/bDwS+FLL2UQ==
dependencies:
fast-deep-equal "^3.1.1"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"
akh.codensity@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/akh.codensity/-/akh.codensity-0.0.1.tgz#869c28ec5611bd00aed0f52c8c7aa6410221f741"