demarches-normaliennes/spec/system/users/linked_dropdown_spec.rb
2023-12-12 22:35:11 +00:00

91 lines
3 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

describe 'linked dropdown lists' do
let(:password) { SECURE_PASSWORD }
let!(:user) { create(:user, password: password) }
let(:options) do
[
'--Primary 1--',
'Secondary 1.1',
'Secondary 1.2',
'--Primary 2--',
'Secondary 2.1',
'Secondary 2.2',
'Secondary 2.3'
]
end
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :linked_drop_down_list, libelle: 'linked dropdown', options: options, mandatory: mandatory }]) }
let(:user_dossier) { user.dossiers.first }
context 'not mandatory' do
let(:mandatory) { false }
scenario 'change primary value, secondary options are updated', js: true do
log_in(user.email, password, procedure)
fill_individual
expect(page).to have_select("linked dropdown", options: ['', 'Primary 1', 'Primary 2'])
# Select a primary value
select('Primary 2', from: 'linked dropdown')
# Secondary menu reflects chosen primary value
expect(page).to have_select("Valeur secondaire dépendant de la première", options: ['', 'Secondary 2.1', 'Secondary 2.2', 'Secondary 2.3'])
# Select another primary value
select('Primary 1', from: 'linked dropdown')
# Secondary menu gets updated
expect(page).to have_select("Valeur secondaire dépendant de la première", options: ['', 'Secondary 1.1', 'Secondary 1.2'])
end
end
context 'mandatory' do
let(:mandatory) { true }
scenario 'change primary value, secondary options are updated', js: true do
log_in(user.email, password, procedure)
fill_individual
expect(page).to have_select("linked dropdown", options: ['', 'Primary 1', 'Primary 2'])
# Select a primary value
select('Primary 2', from: 'linked dropdown')
# Secondary menu reflects chosen primary value
expect(page).to have_select("Valeur secondaire dépendant de la première", options: ['', 'Secondary 2.1', 'Secondary 2.2', 'Secondary 2.3'])
# Select another primary value
select('Primary 1', from: 'linked dropdown')
# Secondary menu gets updated
expect(page).to have_select("Valeur secondaire dépendant de la première", options: ['', 'Secondary 1.1', 'Secondary 1.2'])
end
end
private
def log_in(email, password, procedure)
visit "/commencer/#{procedure.path}"
click_on 'Jai déjà un compte'
expect(page).to have_current_path(new_user_session_path)
sign_in_with(email, password)
expect(page).to have_current_path(commencer_path(path: procedure.path))
click_on 'Commencer la démarche'
expect(page).to have_content("Votre identité")
expect(page).to have_current_path(identite_dossier_path(user_dossier))
end
def fill_individual
find('label', text: 'Monsieur').click
within('.individual-infos') do
fill_in('Prénom', with: 'prenom')
fill_in('Nom', with: 'nom')
end
click_on 'Continuer'
expect(page).to have_current_path(brouillon_dossier_path(user_dossier))
end
end