specs: refactor procedure_creation_spec.rb

- Improve wording of specs description
- Remove publication test (duplicate of procedure_publish_spec.rb)
This commit is contained in:
Pierre de La Morinerie 2021-11-23 14:12:27 +01:00
parent 8e69a9883b
commit 93124195fc

View file

@ -1,71 +1,38 @@
require 'system/administrateurs/procedure_spec_helper'
describe 'As an administrateur I wanna create a new procedure', js: true do
describe 'Creating a new procedure', js: true do
include ProcedureSpecHelper
let(:administrateur) { create(:administrateur, :with_procedure) }
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur.user, scope: :user
visit root_path
end
context 'Right after sign_in I shall see all procedure states links' do
scenario 'Finding draft procedures' do
page.all('.tabs li a')[1].click
expect(page).to have_current_path(admin_procedures_path(statut: 'brouillons'))
end
scenario 'an admin can create a new procedure from scratch' do
expect(page).to have_selector('#new-procedure')
find('#new-procedure').click
scenario 'Finding active procedures' do
page.all('.tabs li a').first.click
expect(page).to have_current_path(admin_procedures_path(statut: 'publiees'))
end
expect(page).to have_current_path(new_from_existing_admin_procedures_path)
click_on 'Créer une nouvelle démarche de zéro'
expect(find('#procedure_for_individual_true')).to be_checked
expect(find('#procedure_for_individual_false')).not_to be_checked
fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3'
click_on 'Créer la démarche'
scenario 'Finding archived procedures' do
page.all('.tabs li a').last.click
expect(page).to have_current_path(admin_procedures_path(statut: 'archivees'))
end
expect(page).to have_text('Libelle doit être rempli')
fill_in_dummy_procedure_details
click_on 'Créer la démarche'
expect(page).to have_current_path(champs_admin_procedure_path(Procedure.last))
end
context 'Creating a new procedure' do
context "when publish_draft enabled" do
scenario 'Finding save button for new procedure, libelle, description and cadre_juridique required' do
expect(page).to have_selector('#new-procedure')
find('#new-procedure').click
context 'with an empty procedure' do
let(:procedure) { create(:procedure, :with_service, administrateur: administrateur) }
expect(page).to have_current_path(new_from_existing_admin_procedures_path)
click_on 'Créer une nouvelle démarche de zéro'
expect(find('#procedure_for_individual_true')).to be_checked
expect(find('#procedure_for_individual_false')).not_to be_checked
fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3'
click_on 'Créer la démarche'
expect(page).to have_text('Libelle doit être rempli')
fill_in_dummy_procedure_details
click_on 'Créer la démarche'
expect(page).to have_current_path(champs_admin_procedure_path(Procedure.last))
end
end
end
context 'Editing a new procedure' do
before 'Create procedure' do
expect(page).to have_selector('#new-procedure')
find('#new-procedure').click
expect(page).to have_current_path(new_from_existing_admin_procedures_path)
click_on 'Créer une nouvelle démarche de zéro'
fill_in_dummy_procedure_details
click_on 'Créer la démarche'
procedure = Procedure.last
procedure.update(service: create(:service))
end
scenario 'Add champ, add file, visualize them in procedure preview' do
page.refresh
expect(page).to have_current_path(champs_admin_procedure_path(Procedure.last))
scenario 'an admin can add types de champs' do
visit champs_admin_procedure_path(procedure)
add_champ(remove_flash_message: true)
fill_in 'champ-0-libelle', with: 'libelle de champ'
@ -83,29 +50,5 @@ describe 'As an administrateur I wanna create a new procedure', js: true do
expect(page).to have_field('libelle de champ')
end
end
scenario 'After adding champ and file, make publication' do
page.refresh
add_champ(remove_flash_message: true)
fill_in 'champ-0-libelle', with: 'libelle de champ'
blur
expect(page).to have_content('Formulaire enregistré')
click_on Procedure.last.libelle
expect(page).to have_current_path(admin_procedure_path(Procedure.last))
find('#publish-procedure-link').click
expect(page).to have_content('en test')
# Only check the path even though the link is the complete URL
# (Capybara runs the app on an arbitrary host/port.)
expect(page).to have_link(nil, href: /#{commencer_test_path(Procedure.last.path)}/)
expect(page).to have_selector('#procedure_path', visible: true)
expect(find_field('procedure_path').value).to eq 'libelle-de-la-procedure'
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'publish'
expect(page).to have_text('Démarche publiée')
end
end
end