Skip to content

Commit

Permalink
fix: la commune n’est pas enregistrée dans la situation suite à la ré…
Browse files Browse the repository at this point in the history
…ponse
  • Loading branch information
JalilArfaoui committed Sep 10, 2024
1 parent 45db671 commit e5d026a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion site/source/components/conversation/RuleInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 />
Expand Down
14 changes: 13 additions & 1 deletion site/source/domaine/updateSituation.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions site/source/store/reducers/simulation.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit e5d026a

Please sign in to comment.