2021-10-26 11:44:53 +02:00
|
|
|
|
describe 'The routing', js: true do
|
2019-10-24 15:53:59 +02:00
|
|
|
|
let(:password) { 'a very complicated password' }
|
|
|
|
|
let(:procedure) { create(:procedure, :with_type_de_champ, :with_service, :for_individual) }
|
2019-10-18 09:38:50 +02:00
|
|
|
|
let(:administrateur) { create(:administrateur, procedures: [procedure]) }
|
2019-10-24 15:53:59 +02:00
|
|
|
|
let(:scientifique_user) { create(:user, password: password) }
|
|
|
|
|
let(:litteraire_user) { create(:user, password: password) }
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
2019-11-14 15:12:25 +01:00
|
|
|
|
before do
|
2021-09-15 13:35:48 +02:00
|
|
|
|
procedure.update(routing_enabled: true)
|
2019-11-14 15:12:25 +01:00
|
|
|
|
procedure.defaut_groupe_instructeur.instructeurs << administrateur.instructeur
|
|
|
|
|
end
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
|
|
|
|
scenario 'works' do
|
|
|
|
|
login_as administrateur.user, scope: :user
|
|
|
|
|
visit admin_procedure_path(procedure.id)
|
2020-07-15 10:48:11 +02:00
|
|
|
|
find('#groupe-instructeurs').click
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
2022-10-17 11:01:55 +02:00
|
|
|
|
# add littéraire groupe
|
|
|
|
|
fill_in 'Ajouter un nom de groupe', with: 'littéraire'
|
|
|
|
|
click_on 'Ajouter le groupe'
|
|
|
|
|
expect(page).to have_text('Le groupe d’instructeurs « littéraire » a été créé et le routage a été activé.')
|
2019-11-14 15:12:25 +01:00
|
|
|
|
|
2019-10-18 09:38:50 +02:00
|
|
|
|
# add victor to littéraire groupe
|
2022-01-05 11:46:49 +01:00
|
|
|
|
fill_in 'Emails', with: 'victor@inst.com'
|
2019-10-18 09:38:50 +02:00
|
|
|
|
perform_enqueued_jobs { click_on 'Affecter' }
|
2022-10-17 11:01:55 +02:00
|
|
|
|
expect(page).to have_text("L’instructeur victor@inst.com a été affecté")
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
2019-11-21 18:29:11 +01:00
|
|
|
|
victor = User.find_by(email: 'victor@inst.com').instructeur
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
2020-02-26 23:37:42 +01:00
|
|
|
|
# add superwoman to littéraire groupe
|
2022-01-05 11:46:49 +01:00
|
|
|
|
fill_in 'Emails', with: 'superwoman@inst.com'
|
2020-02-26 23:37:42 +01:00
|
|
|
|
perform_enqueued_jobs { click_on 'Affecter' }
|
2022-10-17 11:01:55 +02:00
|
|
|
|
expect(page).to have_text("L’instructeur superwoman@inst.com a été affecté")
|
2020-02-26 23:37:42 +01:00
|
|
|
|
|
|
|
|
|
superwoman = User.find_by(email: 'superwoman@inst.com').instructeur
|
|
|
|
|
|
2022-10-17 11:01:55 +02:00
|
|
|
|
# rename routing criteria to spécialité
|
|
|
|
|
click_on 'Groupes d’instructeurs'
|
|
|
|
|
fill_in 'Libellé de la liste de groupes', with: 'spécialité'
|
|
|
|
|
click_on 'Renommer'
|
|
|
|
|
expect(page).to have_text('Le libellé est maintenant « spécialité ».')
|
|
|
|
|
expect(page).to have_field('Libellé de la liste de groupes', with: 'spécialité')
|
|
|
|
|
|
2022-06-20 16:14:27 +02:00
|
|
|
|
# add inactive groupe
|
2022-10-17 11:01:55 +02:00
|
|
|
|
fill_in 'Ajouter un nom de groupe', with: 'non visible car inactif'
|
2022-06-20 16:14:27 +02:00
|
|
|
|
click_on 'Ajouter le groupe'
|
|
|
|
|
check "Groupe inactif"
|
2022-10-17 11:01:55 +02:00
|
|
|
|
click_on 'Modifier'
|
2022-06-20 16:14:27 +02:00
|
|
|
|
|
2019-10-18 09:38:50 +02:00
|
|
|
|
# add scientifique groupe
|
2019-11-21 18:29:11 +01:00
|
|
|
|
click_on 'Groupes d’instructeurs'
|
2022-10-17 11:01:55 +02:00
|
|
|
|
fill_in 'Ajouter un nom de groupe', with: 'scientifique'
|
2019-10-18 09:38:50 +02:00
|
|
|
|
click_on 'Ajouter le groupe'
|
2019-11-21 18:29:11 +01:00
|
|
|
|
expect(page).to have_text('Le groupe d’instructeurs « scientifique » a été créé.')
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
|
|
|
|
# add marie to scientifique groupe
|
2022-01-05 11:46:49 +01:00
|
|
|
|
fill_in 'Emails', with: 'marie@inst.com'
|
2019-10-18 09:38:50 +02:00
|
|
|
|
perform_enqueued_jobs { click_on 'Affecter' }
|
2019-11-21 18:29:11 +01:00
|
|
|
|
expect(page).to have_text("L’instructeur marie@inst.com a été affecté")
|
|
|
|
|
|
2019-10-18 09:38:50 +02:00
|
|
|
|
marie = User.find_by(email: 'marie@inst.com').instructeur
|
|
|
|
|
|
2020-02-26 23:37:42 +01:00
|
|
|
|
# add superwoman to scientifique groupe
|
2022-01-05 11:46:49 +01:00
|
|
|
|
fill_in 'Emails', with: 'superwoman@inst.com'
|
2020-02-26 23:37:42 +01:00
|
|
|
|
perform_enqueued_jobs { click_on 'Affecter' }
|
|
|
|
|
expect(page).to have_text("L’instructeur superwoman@inst.com a été affecté")
|
|
|
|
|
|
2019-10-18 09:38:50 +02:00
|
|
|
|
# publish
|
|
|
|
|
publish_procedure(procedure)
|
2021-10-01 12:57:33 +02:00
|
|
|
|
log_out
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
|
|
|
|
# 2 users fill a dossier in each group
|
|
|
|
|
user_send_dossier(scientifique_user, 'scientifique')
|
|
|
|
|
user_send_dossier(litteraire_user, 'littéraire')
|
|
|
|
|
|
|
|
|
|
# the litteraires instructeurs only manage the litteraires dossiers
|
|
|
|
|
register_instructeur_and_log_in(victor.email)
|
|
|
|
|
click_on procedure.libelle
|
|
|
|
|
expect(page).to have_text(litteraire_user.email)
|
|
|
|
|
expect(page).not_to have_text(scientifique_user.email)
|
|
|
|
|
|
|
|
|
|
# the search only show litteraires dossiers
|
|
|
|
|
fill_in 'q', with: scientifique_user.email
|
2022-08-31 12:44:00 +02:00
|
|
|
|
find('.fr-search-bar .fr-btn').click
|
2019-10-18 09:38:50 +02:00
|
|
|
|
expect(page).to have_text('0 dossier trouvé')
|
|
|
|
|
|
|
|
|
|
fill_in 'q', with: litteraire_user.email
|
2022-08-31 12:44:00 +02:00
|
|
|
|
find('.fr-search-bar .fr-btn').click
|
2019-10-18 09:38:50 +02:00
|
|
|
|
expect(page).to have_text('1 dossier trouvé')
|
|
|
|
|
|
|
|
|
|
## and the result is clickable
|
|
|
|
|
click_on litteraire_user.email
|
|
|
|
|
expect(page).to have_current_path(instructeur_dossier_path(procedure, litteraire_user.dossiers.first))
|
|
|
|
|
|
2019-10-24 15:53:59 +02:00
|
|
|
|
# follow the dossier
|
|
|
|
|
click_on 'Suivre le dossier'
|
|
|
|
|
|
2019-10-18 09:38:50 +02:00
|
|
|
|
log_out
|
|
|
|
|
|
|
|
|
|
# the scientifiques instructeurs only manage the scientifiques dossiers
|
|
|
|
|
register_instructeur_and_log_in(marie.email)
|
|
|
|
|
click_on procedure.libelle
|
|
|
|
|
expect(page).not_to have_text(litteraire_user.email)
|
|
|
|
|
expect(page).to have_text(scientifique_user.email)
|
2019-10-24 15:53:59 +02:00
|
|
|
|
|
|
|
|
|
# follow the dossier
|
|
|
|
|
click_on scientifique_user.email
|
|
|
|
|
click_on 'Suivre le dossier'
|
|
|
|
|
|
|
|
|
|
log_out
|
|
|
|
|
|
|
|
|
|
# litteraire_user change its dossier
|
2019-11-21 18:29:11 +01:00
|
|
|
|
visit new_user_session_path
|
2019-10-24 15:53:59 +02:00
|
|
|
|
sign_in_with litteraire_user.email, password
|
|
|
|
|
|
2019-11-21 18:29:11 +01:00
|
|
|
|
click_on litteraire_user.dossiers.first.id.to_s
|
2019-10-24 15:53:59 +02:00
|
|
|
|
click_on 'Modifier mon dossier'
|
|
|
|
|
|
2022-11-10 22:21:14 +01:00
|
|
|
|
fill_in litteraire_user.dossiers.first.champs_public.first.libelle, with: 'some value'
|
2022-10-04 12:27:03 +02:00
|
|
|
|
wait_for_autosave(false)
|
|
|
|
|
|
2019-10-24 15:53:59 +02:00
|
|
|
|
log_out
|
|
|
|
|
|
|
|
|
|
# the litteraires instructeurs should have a notification
|
2019-11-21 18:29:11 +01:00
|
|
|
|
visit new_user_session_path
|
2019-10-24 15:53:59 +02:00
|
|
|
|
sign_in_with victor.user.email, password
|
|
|
|
|
|
|
|
|
|
## on the procedures list
|
2019-11-21 18:29:39 +01:00
|
|
|
|
expect(page).to have_current_path(instructeur_procedures_path)
|
|
|
|
|
expect(find('.procedure-stats')).to have_css('span.notifications')
|
2019-10-24 15:53:59 +02:00
|
|
|
|
|
|
|
|
|
## on the dossiers list
|
|
|
|
|
click_on procedure.libelle
|
2019-11-21 18:29:11 +01:00
|
|
|
|
expect(page).to have_current_path(instructeur_procedure_path(procedure))
|
2019-11-21 18:29:39 +01:00
|
|
|
|
expect(find('.tabs')).to have_css('span.notifications')
|
2019-10-24 15:53:59 +02:00
|
|
|
|
|
2019-11-21 18:29:11 +01:00
|
|
|
|
## on the dossier itself
|
2019-10-24 15:53:59 +02:00
|
|
|
|
click_on 'suivi'
|
|
|
|
|
click_on litteraire_user.email
|
2019-11-21 18:29:11 +01:00
|
|
|
|
expect(page).to have_current_path(instructeur_dossier_path(procedure, litteraire_user.dossiers.first))
|
2020-05-07 16:31:36 +02:00
|
|
|
|
expect(page).to have_text('Annotations privées')
|
2019-11-21 18:29:39 +01:00
|
|
|
|
expect(find('.tabs')).to have_css('span.notifications')
|
2019-10-18 09:38:50 +02:00
|
|
|
|
log_out
|
|
|
|
|
|
2019-10-24 15:53:59 +02:00
|
|
|
|
# the scientifiques instructeurs should not have a notification
|
2019-11-21 18:29:11 +01:00
|
|
|
|
visit new_user_session_path
|
|
|
|
|
sign_in_with marie.user.email, password
|
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path(instructeur_procedures_path)
|
|
|
|
|
expect(find('.procedure-stats')).not_to have_css('span.notifications')
|
2019-10-24 15:53:59 +02:00
|
|
|
|
log_out
|
2020-02-26 23:37:42 +01:00
|
|
|
|
|
|
|
|
|
# the instructeurs who belong to scientifique AND litteraire groups manage scientifique and litterraire dossiers
|
|
|
|
|
register_instructeur_and_log_in(superwoman.email)
|
2020-07-07 12:03:32 +02:00
|
|
|
|
visit instructeur_procedure_path(procedure, params: { statut: 'tous' })
|
2020-02-26 23:37:42 +01:00
|
|
|
|
expect(page).to have_text(litteraire_user.email)
|
|
|
|
|
expect(page).to have_text(scientifique_user.email)
|
|
|
|
|
|
|
|
|
|
# follow the dossier
|
|
|
|
|
click_on scientifique_user.email
|
|
|
|
|
click_on 'Suivre le dossier'
|
|
|
|
|
|
2020-07-07 12:03:32 +02:00
|
|
|
|
visit instructeur_procedure_path(procedure, params: { statut: 'tous' })
|
2020-02-26 23:37:42 +01:00
|
|
|
|
click_on litteraire_user.email
|
|
|
|
|
click_on 'Suivre le dossier'
|
|
|
|
|
log_out
|
|
|
|
|
|
|
|
|
|
# scientifique_user updates its group
|
|
|
|
|
user_update_group(scientifique_user, 'littéraire')
|
|
|
|
|
|
|
|
|
|
# the instructeurs who belong to scientifique AND litteraire groups should have a notification
|
|
|
|
|
visit new_user_session_path
|
|
|
|
|
sign_in_with superwoman.user.email, password
|
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path(instructeur_procedures_path)
|
|
|
|
|
expect(find('.procedure-stats')).to have_css('span.notifications')
|
2019-10-18 09:38:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def publish_procedure(procedure)
|
|
|
|
|
click_on procedure.libelle
|
2020-07-15 10:48:11 +02:00
|
|
|
|
find('#publish-procedure-link').click
|
2020-09-08 12:35:44 +02:00
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
|
|
|
|
click_on 'Publier'
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
|
|
|
|
expect(page).to have_text('Démarche publiée')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def user_send_dossier(user, groupe)
|
|
|
|
|
login_as user, scope: :user
|
|
|
|
|
visit commencer_path(path: procedure.reload.path)
|
|
|
|
|
click_on 'Commencer la démarche'
|
|
|
|
|
|
2020-12-08 17:43:50 +01:00
|
|
|
|
choose 'Monsieur'
|
2019-10-18 09:38:50 +02:00
|
|
|
|
fill_in 'individual_nom', with: 'Nom'
|
|
|
|
|
fill_in 'individual_prenom', with: 'Prenom'
|
|
|
|
|
click_button('Continuer')
|
|
|
|
|
|
|
|
|
|
select(groupe, from: 'dossier_groupe_instructeur_id')
|
2022-10-04 12:27:03 +02:00
|
|
|
|
wait_for_autosave
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
|
|
|
|
click_on 'Déposer le dossier'
|
2019-11-21 18:29:11 +01:00
|
|
|
|
expect(page).to have_text('Merci')
|
2019-10-18 09:38:50 +02:00
|
|
|
|
|
|
|
|
|
log_out
|
|
|
|
|
end
|
|
|
|
|
|
2020-02-26 23:37:42 +01:00
|
|
|
|
def user_update_group(user, new_group)
|
|
|
|
|
login_as user, scope: :user
|
|
|
|
|
visit dossiers_path
|
|
|
|
|
click_on user.dossiers.first.id.to_s
|
|
|
|
|
click_on "Modifier mon dossier"
|
2022-06-20 16:14:27 +02:00
|
|
|
|
expect(page).to have_selector("option", text: "scientifique")
|
|
|
|
|
expect(page).not_to have_selector("option", text: "Groupe inactif")
|
2020-02-26 23:37:42 +01:00
|
|
|
|
|
|
|
|
|
select(new_group, from: 'dossier_groupe_instructeur_id')
|
2022-10-04 12:27:03 +02:00
|
|
|
|
wait_for_autosave(false)
|
|
|
|
|
|
2020-02-26 23:37:42 +01:00
|
|
|
|
expect(page).to have_text(new_group)
|
|
|
|
|
|
|
|
|
|
log_out
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-18 09:38:50 +02:00
|
|
|
|
def register_instructeur_and_log_in(email)
|
|
|
|
|
confirmation_email = emails_sent_to(email)
|
2020-09-24 15:09:41 +02:00
|
|
|
|
.find { |m| m.subject == 'Activez votre compte instructeur' }
|
2019-10-18 09:38:50 +02:00
|
|
|
|
token_params = confirmation_email.body.match(/token=[^"]+/)
|
|
|
|
|
|
|
|
|
|
visit "users/activate?#{token_params}"
|
2019-10-24 15:53:59 +02:00
|
|
|
|
fill_in :user_password, with: password
|
2019-10-18 09:38:50 +02:00
|
|
|
|
click_button 'Définir le mot de passe'
|
|
|
|
|
|
2019-11-21 18:29:11 +01:00
|
|
|
|
expect(page).to have_text('Mot de passe enregistré')
|
2019-10-18 09:38:50 +02:00
|
|
|
|
end
|
|
|
|
|
end
|