refactor(combobox): fix specs
This commit is contained in:
parent
8d6dc625f3
commit
9f9243499c
13 changed files with 70 additions and 123 deletions
|
@ -26,7 +26,7 @@ describe Administrateurs::ExpertsProceduresController, type: :controller do
|
|||
subject { post :create, params: params }
|
||||
|
||||
context 'when inviting multiple valid experts' do
|
||||
let(:params) { { procedure_id: procedure.id, emails: [expert.email, "new@expert.fr"].to_json } }
|
||||
let(:params) { { procedure_id: procedure.id, emails: [expert.email, "new@expert.fr"] } }
|
||||
|
||||
it 'creates experts' do
|
||||
subject
|
||||
|
@ -38,7 +38,7 @@ describe Administrateurs::ExpertsProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when inviting expert using an email with typos' do
|
||||
let(:params) { { procedure_id: procedure.id, emails: ['martin@oraneg.fr'].to_json } }
|
||||
let(:params) { { procedure_id: procedure.id, emails: ['martin@oraneg.fr'] } }
|
||||
render_views
|
||||
it 'warns' do
|
||||
subject
|
||||
|
|
|
@ -332,14 +332,14 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
describe '#add_instructeur_procedure_non_routee' do
|
||||
# faire la meme chose sur une procedure non routee
|
||||
let(:procedure_non_routee) { create(:procedure, administrateur: admin) }
|
||||
let(:emails) { ['instructeur_3@ministere_a.gouv.fr', 'instructeur_4@ministere_b.gouv.fr'].to_json }
|
||||
let(:emails) { ['instructeur_3@ministere_a.gouv.fr', 'instructeur_4@ministere_b.gouv.fr'] }
|
||||
let(:manager) { false }
|
||||
before {
|
||||
procedure_non_routee.administrateurs_procedures.where(administrateur: admin).update_all(manager:)
|
||||
}
|
||||
subject { post :add_instructeur, params: { emails: emails, procedure_id: procedure_non_routee.id, id: procedure_non_routee.defaut_groupe_instructeur.id } }
|
||||
context 'when all emails are valid' do
|
||||
let(:emails) { ['test@b.gouv.fr', 'test2@b.gouv.fr'].to_json }
|
||||
let(:emails) { ['test@b.gouv.fr', 'test2@b.gouv.fr'] }
|
||||
it do
|
||||
expect(subject).to redirect_to admin_procedure_groupe_instructeurs_path(procedure_non_routee)
|
||||
expect(subject.request.flash[:alert]).to be_nil
|
||||
|
@ -348,7 +348,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when there is at least one bad email' do
|
||||
let(:emails) { ['badmail', 'instructeur2@gmail.com'].to_json }
|
||||
let(:emails) { ['badmail', 'instructeur2@gmail.com'] }
|
||||
it do
|
||||
expect(subject).to redirect_to admin_procedure_groupe_instructeurs_path(procedure_non_routee)
|
||||
expect(subject.request.flash[:alert]).to be_present
|
||||
|
@ -359,7 +359,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
context 'when the admin wants to assign an instructor who is already assigned on this procedure' do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
before { procedure_non_routee.groupe_instructeurs.first.add_instructeurs(emails: [instructeur.user.email]) }
|
||||
let(:emails) { [instructeur.email].to_json }
|
||||
let(:emails) { [instructeur.email] }
|
||||
it { expect(subject).to redirect_to admin_procedure_groupe_instructeurs_path(procedure_non_routee) }
|
||||
end
|
||||
|
||||
|
@ -376,7 +376,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
params: {
|
||||
procedure_id: procedure.id,
|
||||
id: gi_1_2.id,
|
||||
emails: new_instructeur_emails.to_json
|
||||
emails: new_instructeur_emails
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
||||
let(:zone) { create(:zone) }
|
||||
let(:zone_ids) { [zone.id] }
|
||||
let(:tags) { "[\"planete\",\"environnement\"]" }
|
||||
let(:tags) { ["planete", "environnement"] }
|
||||
|
||||
describe '#apercu' do
|
||||
subject { get :apercu, params: { id: procedure.id } }
|
||||
|
|
|
@ -367,7 +367,7 @@ describe Experts::AvisController, type: :controller do
|
|||
let(:previous_avis_confidentiel) { false }
|
||||
let(:previous_revoked_at) { nil }
|
||||
let!(:previous_avis) { create(:avis, dossier:, claimant:, experts_procedure:, confidentiel: previous_avis_confidentiel, revoked_at: previous_revoked_at) }
|
||||
let(:emails) { '["a@b.com"]' }
|
||||
let(:emails) { ["a@b.com"] }
|
||||
let(:introduction) { 'introduction' }
|
||||
let(:created_avis) { Avis.last }
|
||||
let!(:old_avis_count) { Avis.count }
|
||||
|
@ -394,7 +394,7 @@ describe Experts::AvisController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when an invalid email' do
|
||||
let(:emails) { "[\"toto.fr\"]" }
|
||||
let(:emails) { ["toto.fr"] }
|
||||
|
||||
it do
|
||||
expect(response).to render_template :instruction
|
||||
|
@ -414,7 +414,7 @@ describe Experts::AvisController, type: :controller do
|
|||
end
|
||||
|
||||
context 'ask review with attachment' do
|
||||
let(:emails) { "[\"toto@totomail.com\"]" }
|
||||
let(:emails) { ["toto@totomail.com"] }
|
||||
|
||||
it do
|
||||
expect(created_avis.introduction_file).to be_attached
|
||||
|
@ -425,7 +425,7 @@ describe Experts::AvisController, type: :controller do
|
|||
end
|
||||
|
||||
context 'with multiple emails' do
|
||||
let(:emails) { "[\"toto.fr\",\"titi@titimail.com\"]" }
|
||||
let(:emails) { ["toto.fr", "titi@titimail.com"] }
|
||||
|
||||
it do
|
||||
expect(response).to render_template :instruction
|
||||
|
|
|
@ -28,7 +28,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
post(
|
||||
:send_to_instructeurs,
|
||||
params: {
|
||||
recipients: [recipient.id].to_json,
|
||||
recipients: [recipient.id],
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
}
|
||||
end
|
||||
|
||||
let(:emails) { "[\"email@a.com\"]" }
|
||||
let(:emails) { ["email@a.com"] }
|
||||
|
||||
context "notifications updates" do
|
||||
context 'when an instructeur follows the dossier' do
|
||||
|
@ -811,7 +811,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
it { expect(response).to redirect_to(avis_instructeur_dossier_path(dossier.procedure, dossier)) }
|
||||
|
||||
context "with an invalid email" do
|
||||
let(:emails) { "[\"emaila.com\"]" }
|
||||
let(:emails) { ["emaila.com"] }
|
||||
|
||||
before { subject }
|
||||
|
||||
|
@ -822,7 +822,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context "with no email" do
|
||||
let(:emails) { "" }
|
||||
let(:emails) { [] }
|
||||
|
||||
before { subject }
|
||||
|
||||
|
@ -833,7 +833,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'with multiple emails' do
|
||||
let(:emails) { "[\"toto.fr\",\"titi@titimail.com\"]" }
|
||||
let(:emails) { ["toto.fr", "titi@titimail.com"] }
|
||||
|
||||
before { subject }
|
||||
|
||||
|
@ -845,7 +845,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when the expert do not want to receive notification' do
|
||||
let(:emails) { "[\"email@a.com\"]" }
|
||||
let(:emails) { ["email@a.com"] }
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure, notify_on_new_avis: false) }
|
||||
|
||||
before { subject }
|
||||
|
|
|
@ -22,21 +22,19 @@ RSpec.describe Champs::AnnuaireEducationChamp do
|
|||
it_behaves_like "a data updater (without updating the value)", ''
|
||||
end
|
||||
|
||||
context 'when data is inconsistent' do
|
||||
let(:data) { { 'yo' => 'lo' } }
|
||||
it_behaves_like "a data updater (without updating the value)", { 'yo' => 'lo' }
|
||||
end
|
||||
|
||||
context 'when data is consistent' do
|
||||
let(:data) {
|
||||
{
|
||||
'nom_etablissement': "karrigel an ankou",
|
||||
'nom_etablissement' => "karrigel an ankou",
|
||||
'nom_commune' => 'kumun',
|
||||
'identifiant_de_l_etablissement' => '666667'
|
||||
}.with_indifferent_access
|
||||
}
|
||||
}
|
||||
it_behaves_like "a data updater (without updating the value)", {
|
||||
'nom_etablissement' => "karrigel an ankou",
|
||||
'nom_commune' => 'kumun',
|
||||
'identifiant_de_l_etablissement' => '666667'
|
||||
}
|
||||
it { expect { subject }.to change { champ.reload.data }.to(data) }
|
||||
it { expect { subject }.to change { champ.reload.value }.to('karrigel an ankou, kumun (666667)') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -106,25 +106,10 @@ module SystemHelpers
|
|||
end
|
||||
end
|
||||
|
||||
def select_combobox(libelle, fill_with, value, check: true)
|
||||
fill_in libelle, with: fill_with
|
||||
find('li[role="option"][data-reach-combobox-option]', text: value, wait: 5).click
|
||||
if check
|
||||
check_selected_value(libelle, with: value)
|
||||
end
|
||||
end
|
||||
|
||||
def check_selected_value(libelle, with:)
|
||||
field = find_hidden_field_for(libelle)
|
||||
value = field.value.starts_with?('[') ? JSON.parse(field.value) : field.value
|
||||
if value.is_a?(Array)
|
||||
if with.is_a?(Array)
|
||||
expect(value.sort).to eq(with.sort)
|
||||
else
|
||||
expect(value).to include(with)
|
||||
end
|
||||
else
|
||||
expect(value).to eq(with)
|
||||
def select_combobox(libelle, value, custom_value: false)
|
||||
fill_in libelle, with: custom_value ? "#{value}," : value
|
||||
if !custom_value
|
||||
find_field(libelle).send_keys(:down, :enter)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ describe 'Administrateurs can edit procedures', js: true do
|
|||
procedure.update!(tags: ['social'])
|
||||
|
||||
visit edit_admin_procedure_path(procedure)
|
||||
select_combobox('procedure_tags_combo', 'planete', 'planete', check: false)
|
||||
select_combobox('procedure_tags_combo', 'planete', custom_value: true)
|
||||
click_on 'Enregistrer'
|
||||
|
||||
expect(procedure.reload.tags).to eq(['social', 'planete'])
|
||||
|
|
|
@ -29,7 +29,8 @@ describe 'Inviting an expert:', js: true do
|
|||
within('.fr-sidemenu') { click_on 'Demander un avis' }
|
||||
expect(page).to have_current_path(avis_new_instructeur_dossier_path(procedure, dossier))
|
||||
|
||||
page.execute_script("document.querySelector('#avis_emails').value = '[\"#{expert.email}\",\"#{expert2.email}\"]'")
|
||||
fill_in 'Emails', with: "#{expert.email},"
|
||||
fill_in 'Emails', with: expert2.email
|
||||
fill_in 'avis_introduction', with: 'Bonjour, merci de me donner votre avis sur ce dossier.'
|
||||
check 'avis_invite_linked_dossiers'
|
||||
page.select 'confidentiel', from: 'avis_confidentiel'
|
||||
|
@ -109,7 +110,7 @@ describe 'Inviting an expert:', js: true do
|
|||
within('.fr-sidemenu') { click_on 'Demander un avis' }
|
||||
expect(page).to have_current_path(avis_new_instructeur_dossier_path(procedure, dossier))
|
||||
|
||||
fill_in 'Emails', with: "#{expert.email}; #{expert2.email}"
|
||||
select_combobox 'Emails', expert.email
|
||||
fill_in 'avis_introduction', with: 'Bonjour, merci de me donner votre avis sur ce dossier.'
|
||||
check 'avis_invite_linked_dossiers'
|
||||
page.select 'confidentiel', from: 'avis_confidentiel'
|
||||
|
|
|
@ -160,13 +160,10 @@ describe 'Instructing a dossier:', js: true do
|
|||
within('.fr-sidemenu') { click_on 'Demander un avis' }
|
||||
expect(page).to have_current_path(avis_new_instructeur_dossier_path(procedure, dossier))
|
||||
|
||||
expert_email_formated = "[\"expert@tps.com\"]"
|
||||
expert_email = 'expert@tps.com'
|
||||
ask_confidential_avis(expert_email_formated, 'a good introduction')
|
||||
ask_confidential_avis(expert_email, 'a good introduction')
|
||||
|
||||
expert_email_formated = "[\"#{instructeur2.email}\"]"
|
||||
expert_email = instructeur2.email
|
||||
ask_confidential_avis(expert_email_formated, 'a good introduction')
|
||||
ask_confidential_avis(instructeur2.email, 'a good introduction')
|
||||
|
||||
click_on 'Personnes impliquées'
|
||||
expect(page).to have_text(expert_email)
|
||||
|
@ -189,8 +186,8 @@ describe 'Instructing a dossier:', js: true do
|
|||
|
||||
click_on 'Personnes impliquées'
|
||||
|
||||
select_combobox('Emails', instructeur_2.email, instructeur_2.email, check: false)
|
||||
select_combobox('Emails', instructeur_3.email, instructeur_3.email, check: false)
|
||||
select_combobox('Emails', instructeur_2.email)
|
||||
select_combobox('Emails', instructeur_3.email)
|
||||
|
||||
click_on 'Envoyer'
|
||||
|
||||
|
@ -287,7 +284,7 @@ describe 'Instructing a dossier:', js: true do
|
|||
end
|
||||
|
||||
def ask_confidential_avis(to, introduction)
|
||||
page.execute_script("document.querySelector('#avis_emails').value = '#{to}'")
|
||||
fill_in 'avis_emails', with: to
|
||||
fill_in 'avis_introduction', with: introduction
|
||||
select 'confidentiel', from: 'avis_confidentiel'
|
||||
within('form#new_avis') { click_on 'Demander un avis' }
|
||||
|
|
|
@ -88,33 +88,13 @@ describe "procedure filters" do
|
|||
|
||||
scenario "should be able to user custom fiters", js: true do
|
||||
# use date filter
|
||||
click_on 'Sélectionner un filtre'
|
||||
wait_until { all("#search-filter").size == 1 }
|
||||
find('#search-filter', wait: 5).click
|
||||
find('.fr-menu__item', text: "En construction le", wait: 5).click
|
||||
find("input#value[type=date]", visible: true)
|
||||
fill_in "Valeur", with: "10/10/2010"
|
||||
click_button "Ajouter le filtre"
|
||||
expect(page).to have_no_css("#search-filter", visible: true)
|
||||
add_filter("En construction le", "10/10/2010", type: :date)
|
||||
|
||||
# use statut dropdown filter
|
||||
click_on 'Sélectionner un filtre'
|
||||
wait_until { all("#search-filter").size == 1 }
|
||||
find('#search-filter', wait: 5).click
|
||||
find('.fr-menu__item', text: "Statut", wait: 5).click
|
||||
find("select#value", visible: false)
|
||||
select 'En construction', from: "Valeur"
|
||||
click_button "Ajouter le filtre"
|
||||
expect(page).to have_no_css("#search-filter", visible: true)
|
||||
add_filter('Statut', 'En construction', type: :enum)
|
||||
|
||||
# use choice dropdown filter
|
||||
click_on 'Sélectionner un filtre'
|
||||
wait_until { all("#search-filter").size == 1 }
|
||||
find('#search-filter', wait: 5).click
|
||||
find('.fr-menu__item', text: "Choix unique", wait: 5).click
|
||||
find("select#value", visible: false)
|
||||
select 'val1', from: "Valeur"
|
||||
click_button "Ajouter le filtre"
|
||||
add_filter('Choix unique', 'val1', type: :enum)
|
||||
end
|
||||
|
||||
describe 'with a vcr cached cassette' do
|
||||
|
@ -124,14 +104,7 @@ describe "procedure filters" do
|
|||
departement_champ.reload
|
||||
champ_select_value = "#{departement_champ.external_id} – #{departement_champ.value}"
|
||||
|
||||
click_on 'Sélectionner un filtre'
|
||||
wait_until { all("#search-filter").size == 1 }
|
||||
find('#search-filter', wait: 5).click
|
||||
find('.fr-menu__item', text: departement_champ.libelle, wait: 5).click
|
||||
find("select#value", visible: true)
|
||||
select champ_select_value, from: "Valeur"
|
||||
click_button "Ajouter le filtre"
|
||||
find("select#value", visible: false) # w8 for filter to be applied
|
||||
add_filter(departement_champ.libelle, champ_select_value, type: :enum)
|
||||
expect(page).to have_link(new_unfollow_dossier.id.to_s)
|
||||
end
|
||||
|
||||
|
@ -140,14 +113,7 @@ describe "procedure filters" do
|
|||
region_champ.update!(value: 'Bretagne', external_id: '53')
|
||||
region_champ.reload
|
||||
|
||||
click_on 'Sélectionner un filtre'
|
||||
wait_until { all("#search-filter").size == 1 }
|
||||
find('#search-filter', wait: 5).click
|
||||
find('.fr-menu__item', text: region_champ.libelle, wait: 5).click
|
||||
find("select#value", visible: true)
|
||||
select region_champ.value, from: "Valeur"
|
||||
click_button "Ajouter le filtre"
|
||||
find("select#value", visible: false) # w8 for filter to be applied
|
||||
add_filter(region_champ.libelle, region_champ.value, type: :enum)
|
||||
expect(page).to have_link(new_unfollow_dossier.id.to_s)
|
||||
end
|
||||
end
|
||||
|
@ -155,7 +121,7 @@ describe "procedure filters" do
|
|||
scenario "should be able to add and remove two filters for the same field", js: true do
|
||||
add_filter(type_de_champ.libelle, champ.value)
|
||||
add_filter(type_de_champ.libelle, champ_2.value)
|
||||
add_enum_filter('Groupe instructeur', procedure.groupe_instructeurs.first.label)
|
||||
add_filter('Groupe instructeur', procedure.groupe_instructeurs.first.label, type: :enum)
|
||||
|
||||
within ".dossiers-table" do
|
||||
expect(page).to have_link(new_unfollow_dossier.id.to_s, exact: true)
|
||||
|
@ -185,40 +151,40 @@ describe "procedure filters" do
|
|||
end
|
||||
end
|
||||
|
||||
def add_filter(column_name, filter_value, type: :text)
|
||||
click_on 'Sélectionner un filtre'
|
||||
wait_until { all("#search-filter").size == 1 }
|
||||
find('#search-filter + button', wait: 5).click
|
||||
find('.fr-menu__item', text: column_name, wait: 5).click
|
||||
case type
|
||||
when :text
|
||||
fill_in "Valeur", with: filter_value
|
||||
when :date
|
||||
find("input#value[type=date]", visible: true)
|
||||
fill_in "Valeur", with: filter_value
|
||||
when :enum
|
||||
find("select#value", visible: false)
|
||||
select filter_value, from: "Valeur"
|
||||
end
|
||||
click_button "Ajouter le filtre"
|
||||
expect(page).to have_no_css("#search-filter", visible: true)
|
||||
end
|
||||
|
||||
def remove_filter(filter_value)
|
||||
click_link text: filter_value
|
||||
end
|
||||
|
||||
def add_filter(column_name, filter_value)
|
||||
click_on 'Sélectionner un filtre'
|
||||
wait_until { all("#search-filter").size == 1 }
|
||||
find('#search-filter', wait: 5).click
|
||||
find('.fr-menu__item', text: column_name, wait: 5).click
|
||||
fill_in "Valeur", with: filter_value
|
||||
click_button "Ajouter le filtre"
|
||||
expect(page).to have_no_css("#search-filter", visible: true)
|
||||
end
|
||||
|
||||
def add_enum_filter(column_name, filter_value)
|
||||
click_on 'Sélectionner un filtre'
|
||||
wait_until { all("#search-filter").size == 1 }
|
||||
find('#search-filter', wait: 5).click
|
||||
find('.fr-menu__item', text: column_name, wait: 5).click
|
||||
select filter_value, from: "Valeur"
|
||||
click_button "Ajouter le filtre"
|
||||
expect(page).to have_no_css("#search-filter", visible: true)
|
||||
end
|
||||
|
||||
def add_column(column_name)
|
||||
click_on 'Personnaliser'
|
||||
select_combobox('Colonne à afficher', column_name, column_name, check: false)
|
||||
select_combobox('Colonne à afficher', column_name)
|
||||
click_button "Enregistrer"
|
||||
end
|
||||
|
||||
def remove_column(column_name)
|
||||
click_on 'Personnaliser'
|
||||
click_button column_name
|
||||
find("body").native.send_key("Escape")
|
||||
within '.fr-tag-list' do
|
||||
find('.fr-tag', text: column_name).find('button').click
|
||||
end
|
||||
click_button "Enregistrer"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,11 +38,11 @@ describe 'The user' do
|
|||
select('02 – Aisne', from: form_id_for('departements'))
|
||||
|
||||
fill_in('communes', with: '60400')
|
||||
find('li', text: 'Brétigny (60400)').click
|
||||
find('.fr-menu__item', text: 'Brétigny (60400)').click
|
||||
wait_until { champ_value_for('communes') == "Brétigny" }
|
||||
|
||||
fill_in('address', with: '78 Rue du Grés 30310 Vergè')
|
||||
find('li', text: '78 Rue du Grés 30310 Vergèze').click
|
||||
find('.fr-menu__item', text: '78 Rue du Grés 30310 Vergèze').click
|
||||
wait_until { champ_value_for('address') == '78 Rue du Grés 30310 Vergèze' }
|
||||
wait_until { champ_for('address').full_address? }
|
||||
expect(champ_for('address').departement_code_and_name).to eq('30 – Gard')
|
||||
|
|
|
@ -13,7 +13,7 @@ describe 'instructeurs/dossiers/envoyer_dossier_block', type: :view do
|
|||
let(:instructeur) { create(:instructeur, email: 'yop@totomail.fr') }
|
||||
let(:potential_recipients) { [instructeur] }
|
||||
|
||||
it { is_expected.to match(/data-react-props.*#{instructeur.email}/) }
|
||||
it { is_expected.to match(/props.*#{instructeur.email}/) }
|
||||
it { is_expected.to have_css(".fr-btn") }
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue