This commit is contained in:
simon lehericey 2022-07-20 10:58:03 +02:00
parent c61e411328
commit d1e3a0d29f

View file

@ -274,30 +274,58 @@ describe 'The user' do
context 'with condition' do
include Logic
let(:procedure) { create(:procedure, :published, :for_individual, :with_yes_no, :with_type_de_champ) }
let(:revision) { procedure.published_revision }
let(:yes_no_type_de_champ) { revision.types_de_champ.first }
let(:type_de_champ) { revision.types_de_champ.last }
let(:condition) { ds_eq(champ_value(yes_no_type_de_champ.stable_id), constant(true)) }
let(:procedure) do
procedure = create(:procedure, :for_individual).tap do |p|
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')
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
log_in(user, procedure)
age, permis, tonnage = user.dossiers.first.champs.to_a
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')
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 'Accéder à votre dossier'
click_on 'Modifier mon dossier'
expect(page).to have_field(type_de_champ.libelle, with: '', visible: true)
choose('Non')
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')
# 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