2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
describe 'dropdown list with other option activated', js: true do
|
2023-03-03 14:16:15 +01:00
|
|
|
let(:password) { SECURE_PASSWORD }
|
2021-10-22 14:46:53 +02:00
|
|
|
let!(:user) { create(:user, password: password) }
|
|
|
|
|
2022-08-04 11:39:07 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :drop_down_list, libelle: 'simple dropdown other', options: options + [:other] }]) }
|
2021-10-22 14:46:53 +02:00
|
|
|
|
|
|
|
let(:user_dossier) { user.dossiers.first }
|
|
|
|
|
|
|
|
before do
|
|
|
|
login_as(user, scope: :user)
|
2022-06-01 16:56:48 +02:00
|
|
|
visit "/commencer/#{procedure.path}?locale=fr"
|
2021-10-22 14:46:53 +02:00
|
|
|
click_on 'Commencer la démarche'
|
|
|
|
end
|
2022-06-01 16:56:48 +02:00
|
|
|
context 'with radios' do
|
2022-08-04 11:39:07 +02:00
|
|
|
let(:options) do
|
|
|
|
[
|
|
|
|
'--Primary 1--',
|
|
|
|
'Secondary 1.1',
|
|
|
|
'Secondary 1.2'
|
|
|
|
]
|
2022-06-01 16:56:48 +02:00
|
|
|
end
|
|
|
|
|
2024-09-10 23:53:04 +02:00
|
|
|
scenario 'Select other option and the other input hidden must appear' do
|
2022-06-01 16:56:48 +02:00
|
|
|
fill_individual
|
|
|
|
|
2024-11-14 16:53:35 +01:00
|
|
|
choose I18n.t('shared.champs.drop_down_list.other'), allow_label_click: true
|
2022-06-01 16:56:48 +02:00
|
|
|
expect(page).to have_selector('.drop_down_other', visible: true)
|
|
|
|
end
|
2023-01-24 14:27:53 +01:00
|
|
|
|
2024-09-10 23:53:04 +02:00
|
|
|
scenario "Getting back from other save the new option" do
|
2023-01-24 14:27:53 +01:00
|
|
|
fill_individual
|
|
|
|
|
2024-11-14 16:53:35 +01:00
|
|
|
choose I18n.t('shared.champs.drop_down_list.other'), allow_label_click: true
|
2024-04-20 03:33:46 +02:00
|
|
|
fill_in(I18n.t('shared.champs.drop_down_list.other_label'), with: "My choice")
|
2023-01-24 14:27:53 +01:00
|
|
|
|
2024-09-27 15:37:11 +02:00
|
|
|
wait_until { user_dossier.reload.project_champs_public.first.value == "My choice" }
|
|
|
|
expect(user_dossier.project_champs_public.first.value).to eq("My choice")
|
2023-01-24 14:27:53 +01:00
|
|
|
|
2024-11-14 16:53:35 +01:00
|
|
|
choose "Secondary 1.1", allow_label_click: true
|
2023-01-24 14:27:53 +01:00
|
|
|
|
2024-09-27 15:37:11 +02:00
|
|
|
wait_until { user_dossier.reload.project_champs_public.first.value == "Secondary 1.1" }
|
|
|
|
expect(user_dossier.project_champs_public.first.value).to eq("Secondary 1.1")
|
2023-01-24 14:27:53 +01:00
|
|
|
end
|
2022-06-01 16:56:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with select' do
|
2022-08-04 11:39:07 +02:00
|
|
|
let(:options) do
|
|
|
|
[
|
|
|
|
'--Primary 1--',
|
|
|
|
'Secondary 1.1',
|
|
|
|
'Secondary 1.2',
|
|
|
|
'Secondary 1.3',
|
|
|
|
'Secondary 1.4',
|
|
|
|
'Secondary 1.5',
|
|
|
|
'Secondary 1.6'
|
|
|
|
]
|
2022-06-01 16:56:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'with a select and other, selecting a value save it (avoid hidden other_value to be sent)' do
|
|
|
|
fill_individual
|
2021-10-22 14:46:53 +02:00
|
|
|
|
2023-03-30 00:24:11 +02:00
|
|
|
expect(page).not_to have_selector(".drop_down_other input")
|
2024-04-20 03:33:46 +02:00
|
|
|
select(I18n.t('shared.champs.drop_down_list.other'))
|
2022-06-01 16:56:48 +02:00
|
|
|
find(".drop_down_other input", visible: true)
|
2021-10-22 14:46:53 +02:00
|
|
|
|
2022-06-01 16:56:48 +02:00
|
|
|
select("Secondary 1.2")
|
|
|
|
expect(page).to have_selector(".autosave-status.succeeded", visible: true)
|
2022-07-12 11:41:38 +02:00
|
|
|
|
2024-09-27 15:37:11 +02:00
|
|
|
wait_until { user_dossier.reload.project_champs_public.first.value == "Secondary 1.2" }
|
|
|
|
expect(user_dossier.project_champs_public.first.value).to eq("Secondary 1.2")
|
2022-06-01 16:56:48 +02:00
|
|
|
end
|
2021-10-22 14:46:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
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
|
2021-10-22 14:46:53 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(user_dossier))
|
|
|
|
end
|
|
|
|
end
|