2021-11-25 16:26:55 +01:00
|
|
|
|
require 'system/administrateurs/procedure_spec_helper'
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
describe 'Publishing a procedure', js: true do
|
2020-03-13 15:32:30 +01:00
|
|
|
|
include ProcedureSpecHelper
|
|
|
|
|
|
|
|
|
|
let(:administrateur) { create(:administrateur) }
|
|
|
|
|
let(:instructeurs) { [administrateur.user.instructeur] }
|
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure_with_dossiers,
|
|
|
|
|
:with_path,
|
|
|
|
|
:with_type_de_champ,
|
|
|
|
|
:with_service,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
login_as administrateur.user, scope: :user
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
context 'when using a deprecated back-office URL' do
|
|
|
|
|
scenario 'the admin is redirected to the draft procedure' do
|
2020-09-17 13:53:48 +02:00
|
|
|
|
visit admin_procedures_draft_path
|
|
|
|
|
expect(page).to have_current_path(admin_procedures_path(statut: "brouillons"))
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
scenario 'the admin is redirected to the archived procedures' do
|
2020-09-17 13:53:48 +02:00
|
|
|
|
visit admin_procedures_archived_path
|
|
|
|
|
expect(page).to have_current_path(admin_procedures_path(statut: "archivees"))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
context 'when a procedure isn’t published yet' do
|
2021-11-24 11:09:58 +01:00
|
|
|
|
before do
|
2020-09-08 12:35:44 +02:00
|
|
|
|
visit admin_procedures_path(statut: "brouillons")
|
2020-03-13 15:32:30 +01:00
|
|
|
|
click_on procedure.libelle
|
2020-07-15 10:48:11 +02:00
|
|
|
|
find('#publish-procedure-link').click
|
2021-11-24 11:09:58 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'an admin can publish it' do
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(find_field('procedure_path').value).to eq procedure.path
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
|
|
|
|
click_on 'Publier'
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
|
|
|
|
expect(page).to have_text('Démarche publiée')
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(page).to have_selector('#preview-procedure')
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|
2021-11-24 11:09:58 +01:00
|
|
|
|
|
|
|
|
|
context 'when the procedure has invalid champs' do
|
2022-01-26 17:52:32 +01:00
|
|
|
|
let(:empty_repetition) { build(:type_de_champ_repetition, types_de_champ: [], libelle: 'Enfants') }
|
2022-01-26 17:52:54 +01:00
|
|
|
|
let(:empty_drop_down) { build(:type_de_champ_drop_down_list, :without_selectable_values, libelle: 'Civilité') }
|
|
|
|
|
|
2021-11-24 11:09:58 +01:00
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure,
|
|
|
|
|
:with_path,
|
|
|
|
|
:with_service,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur,
|
2022-01-26 17:52:54 +01:00
|
|
|
|
types_de_champ: [empty_repetition],
|
|
|
|
|
types_de_champ_private: [empty_drop_down])
|
2021-11-24 11:09:58 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'an error message prevents the publication' do
|
|
|
|
|
expect(page).to have_content('Des problèmes empêchent la publication de la démarche')
|
2022-01-26 17:52:32 +01:00
|
|
|
|
expect(page).to have_content("Le champ « Enfants » doit comporter au moins un champ répétable")
|
2022-01-26 17:52:54 +01:00
|
|
|
|
expect(page).to have_content("L’annotation privée « Civilité » doit comporter au moins un choix sélectionnable")
|
2021-11-24 11:09:58 +01:00
|
|
|
|
|
|
|
|
|
expect(find_field('procedure_path').value).to eq procedure.path
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_button('Publier', disabled: true)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
context 'when a procedure is closed' do
|
2020-03-13 15:32:30 +01:00
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure_with_dossiers,
|
|
|
|
|
:closed,
|
|
|
|
|
:with_path,
|
|
|
|
|
:with_type_de_champ,
|
|
|
|
|
:with_service,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur)
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
scenario 'an admin can publish it again' do
|
2020-09-08 12:35:44 +02:00
|
|
|
|
visit admin_procedures_path(statut: "archivees")
|
2020-03-13 15:32:30 +01:00
|
|
|
|
click_on procedure.libelle
|
2020-07-15 10:48:11 +02:00
|
|
|
|
find('#publish-procedure-link').click
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(find_field('procedure_path').value).to eq procedure.path
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
|
|
|
|
click_on 'publish'
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
|
|
|
|
expect(page).to have_text('Démarche publiée')
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(page).to have_selector('#preview-procedure')
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
context 'when a procedure is de-published' do
|
2020-03-13 15:32:30 +01:00
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure_with_dossiers,
|
|
|
|
|
:unpublished,
|
|
|
|
|
:with_path,
|
|
|
|
|
:with_type_de_champ,
|
|
|
|
|
:with_service,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur)
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
scenario 'an admin can publish it again' do
|
2020-09-08 12:35:44 +02:00
|
|
|
|
visit admin_procedures_path(statut: "archivees")
|
2020-03-13 15:32:30 +01:00
|
|
|
|
click_on procedure.libelle
|
2020-07-15 10:48:11 +02:00
|
|
|
|
find('#publish-procedure-link').click
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(find_field('procedure_path').value).to eq procedure.path
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
|
|
|
|
click_on 'Publier'
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
|
|
|
|
expect(page).to have_text('Démarche publiée')
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(page).to have_selector('#preview-procedure')
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2022-04-25 14:28:52 +02:00
|
|
|
|
|
|
|
|
|
context 'when a procedure has dubious champs' do
|
|
|
|
|
let(:dubious_champs) do
|
|
|
|
|
[
|
|
|
|
|
build(:type_de_champ_text, libelle: 'NIR'),
|
|
|
|
|
build(:type_de_champ_text, libelle: 'carte bancaire')
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
let(:not_dubious_champs) do
|
|
|
|
|
[build(:type_de_champ_text, libelle: 'Prénom')]
|
|
|
|
|
end
|
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure,
|
|
|
|
|
:with_service,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur,
|
|
|
|
|
types_de_champ: not_dubious_champs + dubious_champs)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'an admin can publish it, but a warning appears' do
|
|
|
|
|
visit admin_procedures_path(statut: "brouillons")
|
|
|
|
|
click_on procedure.libelle
|
|
|
|
|
find('#publish-procedure-link').click
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content("Attention, certains champs ne peuvent être demandé par l'administration.")
|
|
|
|
|
expect(page).to have_selector(".dubious-champs", count: dubious_champs.size)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|