2018-06-21 16:17:59 +02:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
feature 'linked dropdown lists' do
|
|
|
|
|
let(:password) { 'secret_password' }
|
|
|
|
|
let!(:user) { create(:user, password: password) }
|
|
|
|
|
|
|
|
|
|
let(:list_items) do
|
|
|
|
|
<<~END_OF_LIST
|
2018-06-27 14:31:34 +02:00
|
|
|
|
--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_OF_LIST
|
|
|
|
|
end
|
|
|
|
|
let(:drop_down_list) { create(:drop_down_list, value: list_items) }
|
|
|
|
|
let(:type_de_champ) { create(:type_de_champ_linked_drop_down_list, libelle: 'linked dropdown', drop_down_list: drop_down_list) }
|
|
|
|
|
|
|
|
|
|
let!(:procedure) do
|
|
|
|
|
p = create(:procedure, :published, :for_individual)
|
|
|
|
|
p.types_de_champ << type_de_champ
|
|
|
|
|
p
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:user_dossier) { user.dossiers.first }
|
|
|
|
|
|
2018-06-27 14:31:34 +02:00
|
|
|
|
scenario 'change primary value, secondary options are updated', js: true do
|
2018-06-21 16:17:59 +02:00
|
|
|
|
log_in(user.email, password, procedure)
|
|
|
|
|
|
|
|
|
|
fill_individual
|
|
|
|
|
|
2018-06-27 14:31:34 +02:00
|
|
|
|
# Select a primary value
|
|
|
|
|
select('Primary 2', from: primary_id_for('linked dropdown'))
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
2018-06-27 14:31:34 +02:00
|
|
|
|
# Secondary menu reflects chosen primary value
|
|
|
|
|
expect(page).to have_select(secondary_id_for('linked dropdown'), options: ['', 'Secondary 2.1', 'Secondary 2.2', 'Secondary 2.3'])
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
2018-06-27 14:31:34 +02:00
|
|
|
|
# Select another primary value
|
|
|
|
|
select('Primary 1', from: primary_id_for('linked dropdown'))
|
2018-06-21 16:17:59 +02:00
|
|
|
|
|
2018-06-27 14:31:34 +02:00
|
|
|
|
# Secondary menu gets updated
|
|
|
|
|
expect(page).to have_select(secondary_id_for('linked dropdown'), options: ['', 'Secondary 1.1', 'Secondary 1.2'])
|
2018-06-21 16:17:59 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content("Données d'identité")
|
2018-06-21 16:17:59 +02:00
|
|
|
|
expect(page).to have_current_path(identite_dossier_path(user_dossier))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def fill_individual
|
|
|
|
|
fill_in('individual_prenom', with: 'prenom')
|
|
|
|
|
fill_in('individual_nom', with: 'nom')
|
|
|
|
|
click_on 'Continuer'
|
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
|
|
|
|
|
|
2018-06-27 14:31:34 +02:00
|
|
|
|
def primary_id_for(libelle)
|
2018-06-21 16:17:59 +02:00
|
|
|
|
find(:xpath, ".//label[contains(text()[normalize-space()], '#{libelle}')]")[:for]
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-27 14:31:34 +02:00
|
|
|
|
def secondary_id_for(libelle)
|
|
|
|
|
primary_id = primary_id_for(libelle)
|
|
|
|
|
link = find("\##{primary_id}")['data-primary-id']
|
|
|
|
|
find("[data-secondary-id=\"#{link}\"]")['id']
|
2018-06-21 16:17:59 +02:00
|
|
|
|
end
|
|
|
|
|
end
|