Merge pull request #7589 from betagouv/fix_cascade_and_conditional
fix(conditionnel): la valeur d'un champ est nul si le champ est caché
This commit is contained in:
commit
18eb241e1a
3 changed files with 54 additions and 14 deletions
|
@ -22,14 +22,18 @@ class Logic::ChampValue < Logic::Term
|
||||||
end
|
end
|
||||||
|
|
||||||
def compute(champs)
|
def compute(champs)
|
||||||
|
targeted_champ = champ(champs)
|
||||||
|
|
||||||
|
return nil if !targeted_champ.visible?
|
||||||
|
|
||||||
case type_de_champ.type_champ
|
case type_de_champ.type_champ
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:yes_no),
|
when MANAGED_TYPE_DE_CHAMP.fetch(:yes_no),
|
||||||
MANAGED_TYPE_DE_CHAMP.fetch(:checkbox)
|
MANAGED_TYPE_DE_CHAMP.fetch(:checkbox)
|
||||||
champ(champs).true?
|
targeted_champ.true?
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
||||||
champ(champs).for_api
|
targeted_champ.for_api
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list)
|
||||||
champ(champs).value
|
targeted_champ.value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,14 @@ describe Logic::ChampValue do
|
||||||
|
|
||||||
it { is_expected.to be(false) }
|
it { is_expected.to be(false) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a value not visible' do
|
||||||
|
before do
|
||||||
|
expect(champ).to receive(:visible?).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to be nil }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'integer tdc' do
|
context 'integer tdc' do
|
||||||
|
|
|
@ -274,30 +274,58 @@ describe 'The user' do
|
||||||
context 'with condition' do
|
context 'with condition' do
|
||||||
include Logic
|
include Logic
|
||||||
|
|
||||||
let(:procedure) { create(:procedure, :published, :for_individual, :with_yes_no, :with_type_de_champ) }
|
let(:procedure) do
|
||||||
let(:revision) { procedure.published_revision }
|
procedure = create(:procedure, :for_individual).tap do |p|
|
||||||
let(:yes_no_type_de_champ) { revision.types_de_champ.first }
|
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'age')
|
||||||
let(:type_de_champ) { revision.types_de_champ.last }
|
p.draft_revision.add_type_de_champ(type_champ: :yes_no, libelle: 'permis de conduire')
|
||||||
let(:condition) { ds_eq(champ_value(yes_no_type_de_champ.stable_id), constant(true)) }
|
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'tonnage')
|
||||||
|
end
|
||||||
|
|
||||||
before { type_de_champ.update(condition: condition) }
|
age, permis, tonnage = 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)))
|
||||||
|
|
||||||
|
procedure.publish!
|
||||||
|
|
||||||
|
procedure
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'fill a dossier', js: true do
|
scenario 'fill a dossier', js: true do
|
||||||
log_in(user, procedure)
|
log_in(user, procedure)
|
||||||
|
|
||||||
|
age, permis, tonnage = user.dossiers.first.champs.to_a
|
||||||
|
|
||||||
fill_individual
|
fill_individual
|
||||||
|
|
||||||
expect(page).to have_field(type_de_champ.libelle, with: '', visible: false)
|
expect(page).to have_css('label', text: 'age', visible: true)
|
||||||
|
expect(page).to have_no_css('label', text: 'permis de conduire', visible: true)
|
||||||
|
expect(page).to have_no_css('label', text: 'tonnage', visible: true)
|
||||||
|
|
||||||
|
fill_in('age', with: '18')
|
||||||
|
expect(page).to have_css('label', text: 'permis de conduire', visible: true)
|
||||||
|
expect(page).to have_no_css('label', text: 'tonnage', visible: true)
|
||||||
|
|
||||||
choose('Oui')
|
choose('Oui')
|
||||||
expect(page).to have_field(type_de_champ.libelle, with: '', visible: true)
|
expect(page).to have_css('label', text: 'permis de conduire', visible: true)
|
||||||
|
expect(page).to have_css('label', text: 'tonnage', 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)
|
||||||
|
|
||||||
click_on 'Déposer le dossier'
|
click_on 'Déposer le dossier'
|
||||||
click_on 'Accéder à votre dossier'
|
click_on 'Accéder à votre dossier'
|
||||||
click_on 'Modifier mon dossier'
|
click_on 'Modifier mon dossier'
|
||||||
|
|
||||||
expect(page).to have_field(type_de_champ.libelle, with: '', visible: true)
|
expect(page).to have_css('label', text: 'age', visible: true)
|
||||||
choose('Non')
|
expect(page).to have_no_css('label', text: 'permis de conduire', visible: true)
|
||||||
expect(page).to have_field(type_de_champ.libelle, with: '', visible: false)
|
expect(page).to have_no_css('label', text: 'tonnage', visible: true)
|
||||||
|
|
||||||
|
fill_in('age', with: '18')
|
||||||
|
# the champ keeps their previous value so they are all displayed
|
||||||
|
expect(page).to have_css('label', text: 'permis de conduire', visible: true)
|
||||||
|
expect(page).to have_css('label', text: 'tonnage', visible: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue