2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-10-26 11:44:53 +02:00
|
|
|
|
describe 'linked dropdown lists' do
|
2023-03-03 14:16:15 +01:00
|
|
|
|
let(:password) { SECURE_PASSWORD }
|
2018-06-21 16:17:59 +02:00
|
|
|
|
let!(:user) { create(:user, password: password) }
|
|
|
|
|
|
2022-08-04 11:39:07 +02:00
|
|
|
|
let(:options) do
|
|
|
|
|
[
|
|
|
|
|
'--Primary 1--',
|
|
|
|
|
'Secondary 1.1',
|
|
|
|
|
'Secondary 1.2',
|
|
|
|
|
'--Primary 2--',
|
|
|
|
|
'Secondary 2.1',
|
|
|
|
|
'Secondary 2.2',
|
|
|
|
|
'Secondary 2.3'
|
|
|
|
|
]
|
2018-06-21 16:17:59 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-08-04 11:39:07 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :linked_drop_down_list, libelle: 'linked dropdown', options: options, mandatory: mandatory }]) }
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
|
|
|
|
let(:user_dossier) { user.dossiers.first }
|
2022-07-08 16:28:55 +02:00
|
|
|
|
context 'not mandatory' do
|
|
|
|
|
let(:mandatory) { false }
|
2023-11-06 15:15:51 +01:00
|
|
|
|
scenario 'change primary value, secondary options are updated', js: true do
|
2022-07-08 16:28:55 +02:00
|
|
|
|
log_in(user.email, password, procedure)
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
2022-07-08 16:28:55 +02:00
|
|
|
|
fill_individual
|
|
|
|
|
expect(page).to have_select("linked dropdown", options: ['', 'Primary 1', 'Primary 2'])
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
2022-07-08 16:28:55 +02:00
|
|
|
|
# Select a primary value
|
|
|
|
|
select('Primary 2', from: 'linked dropdown')
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
2022-07-08 16:28:55 +02:00
|
|
|
|
# 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'])
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
2022-07-08 16:28:55 +02:00
|
|
|
|
# Select another primary value
|
|
|
|
|
select('Primary 1', from: 'linked dropdown')
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
2022-07-08 16:28:55 +02:00
|
|
|
|
# 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
|
2018-06-21 16:17:59 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-07-08 16:28:55 +02:00
|
|
|
|
context 'mandatory' do
|
|
|
|
|
let(:mandatory) { true }
|
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
|
scenario 'change primary value, secondary options are updated', js: true do
|
2022-07-08 16:28:55 +02:00
|
|
|
|
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
|
2022-07-08 16:44:21 +02:00
|
|
|
|
|
2018-06-21 16:17:59 +02:00
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def log_in(email, password, procedure)
|
2018-10-25 17:40:23 +02:00
|
|
|
|
visit "/commencer/#{procedure.path}"
|
2019-01-16 11:57:58 +01:00
|
|
|
|
click_on 'J’ai déjà un compte'
|
|
|
|
|
|
2018-06-21 16:17:59 +02:00
|
|
|
|
expect(page).to have_current_path(new_user_session_path)
|
|
|
|
|
|
2019-01-16 16:16:15 +01:00
|
|
|
|
sign_in_with(email, password)
|
2019-01-16 11:57:58 +01:00
|
|
|
|
|
2019-01-16 16:16:15 +01:00
|
|
|
|
expect(page).to have_current_path(commencer_path(path: procedure.path))
|
|
|
|
|
click_on 'Commencer la démarche'
|
|
|
|
|
|
2023-11-23 16:38:01 +01:00
|
|
|
|
expect(page).to have_content("Votre identité")
|
2018-06-21 16:17:59 +02:00
|
|
|
|
expect(page).to have_current_path(identite_dossier_path(user_dossier))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def fill_individual
|
2023-09-05 14:42:56 +02:00
|
|
|
|
find('label', text: 'Monsieur').click
|
2023-11-28 12:43:43 +01:00
|
|
|
|
within('.individual-infos') do
|
|
|
|
|
fill_in('Prénom', with: 'prenom')
|
|
|
|
|
fill_in('Nom', with: 'nom')
|
|
|
|
|
end
|
2024-04-12 17:59:50 +02:00
|
|
|
|
within "#identite-form" do
|
|
|
|
|
click_on 'Continuer'
|
|
|
|
|
end
|
2018-09-06 09:09:23 +02:00
|
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(user_dossier))
|
2018-06-21 16:17:59 +02:00
|
|
|
|
end
|
|
|
|
|
end
|