fix(admin/conditional): don't break when target champ is empty but a value is still referenced

This commit is contained in:
Colin Darie 2023-02-06 15:52:21 +01:00 committed by mfo
parent f4055474ce
commit 51338eebb1
2 changed files with 11 additions and 0 deletions

View file

@ -31,6 +31,7 @@ class TypesDeChampEditor::ConditionsErrorsComponent < ApplicationComponent
def humanize(error)
case error
in { type: :not_available }
in { type: :incompatible, stable_id: nil }
t('not_available', scope: '.errors')
in { type: :unmanaged, stable_id: stable_id }
targeted_champ = @upper_tdcs.find { |tdc| tdc.stable_id == stable_id }

View file

@ -71,5 +71,15 @@ describe TypesDeChampEditor::ConditionsErrorsComponent, type: :component do
it { expect(page).to have_content("« another choice » ne fait pas partie de « #{tdc.libelle} ».") }
end
context 'when target became unavailable but a right still references the value' do
# Cf https://demarches-simplifiees.sentry.io/issues/3625488398/events/53164e105bc94d55a004d69f96d58fb2/?project=1429550
# However maybe we should not have empty at left with still a constant at right
let(:tdc) { create(:type_de_champ_integer_number) }
let(:upper_tdcs) { [tdc] }
let(:conditions) { [ds_eq(empty, constant('a text'))] }
it { expect(page).to have_content("Un champ cible n'est plus disponible") }
end
end
end