fix: la commune n’est pas enregistrée dans la situation suite à la réponse
parent
45db67117e
commit
e5d026a878
|
@ -151,7 +151,7 @@ export default function RuleInput<Names extends string = DottedName>({
|
|||
<>
|
||||
<SelectCommune
|
||||
{...commonProps}
|
||||
onChange={(c) => commonProps.onChange({ batchUpdate: c })}
|
||||
onChange={(c) => commonProps.onChange(c)}
|
||||
value={value as Evaluation<string>}
|
||||
/>
|
||||
<Spacing md />
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import { pipe } from 'effect'
|
||||
import { isNumber, isString } from 'effect/Predicate'
|
||||
import * as R from 'effect/Record'
|
||||
import { DottedName } from 'modele-social'
|
||||
import { PublicodesExpression } from 'publicodes'
|
||||
|
||||
|
@ -19,8 +22,17 @@ export function updateSituation(
|
|||
|
||||
const objectifsExclusifs = config['objectifs exclusifs'] ?? []
|
||||
|
||||
const nouvellesValeurs =
|
||||
isString(value) || isNumber(value)
|
||||
? { [dottedName]: value }
|
||||
: pipe(
|
||||
value,
|
||||
R.mapKeys((suffixe) => `${dottedName} . ${suffixe}`),
|
||||
R.map((valeur) => (isString(valeur) ? `'${valeur}'` : valeur)) // 😭
|
||||
)
|
||||
|
||||
if (!objectifsExclusifs.includes(dottedName)) {
|
||||
return { ...currentSituation, [dottedName]: value }
|
||||
return { ...currentSituation, ...nouvellesValeurs }
|
||||
}
|
||||
|
||||
const objectifsToReset = objectifsExclusifs.filter(
|
||||
|
|
|
@ -73,9 +73,9 @@ export const prendLaProchaineQuestionMiddleware =
|
|||
if (!lastSituationsAvecContextes || situationAChangé) {
|
||||
lastSituationsAvecContextes = situationsAvecContextes
|
||||
|
||||
engines.forEach((engine, index) =>
|
||||
engines.forEach((engine, index) => {
|
||||
engine.setSituation(situationsAvecContextes[index])
|
||||
)
|
||||
})
|
||||
|
||||
lastSimulation = simulation
|
||||
lastConfig = config
|
||||
|
|
|
@ -174,6 +174,48 @@ describe('simulationReducer', () => {
|
|||
answeredQuestions: ['a', 'b', 'c'],
|
||||
})
|
||||
})
|
||||
it('enregistre la réponse dans la situation', () => {
|
||||
const state = {
|
||||
answeredQuestions: ['a', 'b'],
|
||||
config: {
|
||||
'objectifs exclusifs': [],
|
||||
},
|
||||
}
|
||||
|
||||
expect(
|
||||
simulationReducer(
|
||||
state as unknown as Simulation,
|
||||
enregistreLaRéponse('c' as DottedName, 42)
|
||||
)
|
||||
).toMatchObject({
|
||||
situation: {
|
||||
c: 42,
|
||||
},
|
||||
})
|
||||
})
|
||||
it('enregistre correctement les réponses multiples', () => {
|
||||
const state = {
|
||||
answeredQuestions: ['a', 'b'],
|
||||
config: {
|
||||
'objectifs exclusifs': [],
|
||||
},
|
||||
}
|
||||
|
||||
expect(
|
||||
simulationReducer(
|
||||
state as unknown as Simulation,
|
||||
enregistreLaRéponse('c' as DottedName, {
|
||||
sub1: 42,
|
||||
['sub2 . subC']: 'hello',
|
||||
})
|
||||
)
|
||||
).toMatchObject({
|
||||
situation: {
|
||||
'c . sub1': 42,
|
||||
'c . sub2 . subC': `'hello'`,
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('DELETE_FROM_SITUATION', () => {
|
||||
it('supprime la question des questions répondues si réponse effacée', () => {
|
||||
|
|
Loading…
Reference in New Issue