Merge pull request #7599 from betagouv/conditional_handle_incorrect_input
fix(conditional): ne prend pas en compte les champs invalides
This commit is contained in:
commit
051e912a91
3 changed files with 17 additions and 3 deletions
|
@ -25,6 +25,7 @@ class Logic::ChampValue < Logic::Term
|
|||
targeted_champ = champ(champs)
|
||||
|
||||
return nil if !targeted_champ.visible?
|
||||
return nil if targeted_champ.blank?
|
||||
|
||||
case type_de_champ.type_champ
|
||||
when MANAGED_TYPE_DE_CHAMP.fetch(:yes_no),
|
||||
|
|
|
@ -33,6 +33,12 @@ describe Logic::ChampValue do
|
|||
|
||||
it { expect(champ_value(champ.stable_id).type).to eq(:number) }
|
||||
it { is_expected.to eq(42) }
|
||||
|
||||
context 'with a blank value' do
|
||||
let(:champ) { create(:champ_integer_number, value: '') }
|
||||
|
||||
it { is_expected.to be nil }
|
||||
end
|
||||
end
|
||||
|
||||
context 'decimal tdc' do
|
||||
|
|
|
@ -279,12 +279,14 @@ describe 'The user' do
|
|||
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'age')
|
||||
p.draft_revision.add_type_de_champ(type_champ: :yes_no, libelle: 'permis de conduire')
|
||||
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'tonnage')
|
||||
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'parking')
|
||||
end
|
||||
|
||||
age, permis, tonnage = procedure.draft_revision.types_de_champ.all
|
||||
age, permis, tonnage, parking = procedure.draft_revision.types_de_champ.all
|
||||
|
||||
permis.update(condition: greater_than_eq(champ_value(age.stable_id), constant(18)))
|
||||
tonnage.update(condition: ds_eq(champ_value(permis.stable_id), constant(true)))
|
||||
parking.update(condition: less_than_eq(champ_value(tonnage.stable_id), constant(20)))
|
||||
|
||||
procedure.publish!
|
||||
|
||||
|
@ -294,8 +296,6 @@ describe 'The user' do
|
|||
scenario 'fill a dossier', js: true do
|
||||
log_in(user, procedure)
|
||||
|
||||
age, permis, tonnage = user.dossiers.first.champs.to_a
|
||||
|
||||
fill_individual
|
||||
|
||||
expect(page).to have_css('label', text: 'age', visible: true)
|
||||
|
@ -310,6 +310,13 @@ describe 'The user' do
|
|||
expect(page).to have_css('label', text: 'permis de conduire', visible: true)
|
||||
expect(page).to have_css('label', text: 'tonnage', visible: true)
|
||||
|
||||
fill_in('tonnage', with: '1')
|
||||
expect(page).to have_css('label', text: 'parking', visible: true)
|
||||
|
||||
# try to fill with invalid data
|
||||
fill_in('tonnage', with: 'a')
|
||||
expect(page).to have_no_css('label', text: 'parking', visible: true)
|
||||
|
||||
fill_in('age', with: '2')
|
||||
expect(page).to have_no_css('label', text: 'permis de conduire', visible: true)
|
||||
expect(page).to have_no_css('label', text: 'tonnage', visible: true)
|
||||
|
|
Loading…
Reference in a new issue