demarches-normaliennes/spec/system/administrateurs/procedure_publish_spec.rb

122 lines
3.8 KiB
Ruby
Raw Normal View History

require 'system/administrateurs/procedure_spec_helper'
describe 'Publishing a procedure', js: true do
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
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
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
context 'when a procedure isnt published yet' do
before do
visit admin_procedures_path(statut: "brouillons")
click_on procedure.libelle
find('#publish-procedure-link').click
end
scenario 'an admin can publish it' do
expect(find_field('procedure_path').value).to eq procedure.path
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'Publier'
expect(page).to have_text('Démarche publiée')
expect(page).to have_selector('#preview-procedure')
end
context 'when the procedure has invalid champs' do
let(:empty_repetition) { build(:type_de_champ_repetition, types_de_champ: []) }
let!(:procedure) do
create(:procedure,
:with_path,
:with_service,
instructeurs: instructeurs,
administrateur: administrateur,
types_de_champ: [empty_repetition])
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')
expect(page).to have_content("Le bloc répétable « #{empty_repetition.libelle} » doit comporter au moins un champ")
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
end
context 'when a procedure is closed' do
let!(:procedure) do
create(:procedure_with_dossiers,
:closed,
:with_path,
:with_type_de_champ,
:with_service,
instructeurs: instructeurs,
administrateur: administrateur)
end
scenario 'an admin can publish it again' do
visit admin_procedures_path(statut: "archivees")
click_on procedure.libelle
find('#publish-procedure-link').click
expect(find_field('procedure_path').value).to eq procedure.path
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'publish'
expect(page).to have_text('Démarche publiée')
expect(page).to have_selector('#preview-procedure')
end
end
context 'when a procedure is de-published' do
let!(:procedure) do
create(:procedure_with_dossiers,
:unpublished,
:with_path,
:with_type_de_champ,
:with_service,
instructeurs: instructeurs,
administrateur: administrateur)
end
scenario 'an admin can publish it again' do
visit admin_procedures_path(statut: "archivees")
click_on procedure.libelle
find('#publish-procedure-link').click
expect(find_field('procedure_path').value).to eq procedure.path
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'Publier'
expect(page).to have_text('Démarche publiée')
expect(page).to have_selector('#preview-procedure')
end
end
end