Encourager la création de champs PJ plutôt que de vieilles PJS

This commit is contained in:
Frederic Merizen 2018-12-18 17:52:33 +01:00
parent ae8c61830a
commit d1cfe4468d
4 changed files with 102 additions and 65 deletions

View file

@ -239,6 +239,10 @@ class Procedure < ApplicationRecord
whitelisted_at.present? whitelisted_at.present?
end end
def has_old_pjs?
types_de_piece_justificative.any?
end
def total_dossier def total_dossier
self.dossiers.state_not_brouillon.size self.dossiers.state_not_brouillon.size
end end

View file

@ -1,3 +1,25 @@
.row.white-back .row.white-back
.alert.alert-info
.form-group
%p
Pour vos nouveaux besoins de pièces jointes, nous vous invitons à
= link_to(admin_procedure_types_de_champ_path(@procedure)) do
rajouter des champs
\ <em>pièce justificative</em> à votre formulaire.
%p
Ils offrent les avantages suivants :
%ul
%li Pièces justificatives au fil du formulaire, pour un déroulé plus fluide
%li Possibilité de fournir à lusager un fichier type à remplir et renvoyer
%li Possibilité pour lusager de supprimer les documents joints par erreur
%li Support des pièces de grande taille (jusquà 200 Mo par pièce)
%li Pas de limite de soumission simultanée de plusieurs pièces, pour une expérience usager plus confortable
= link_to(admin_procedure_types_de_champ_path(@procedure), class: 'btn btn-success') do
Ajouter un champ PJ
- if @procedure.has_old_pjs?
#piece_justificative_form #piece_justificative_form
= render 'form' = render 'form'

View file

@ -6,28 +6,31 @@ feature 'add a new type de piece justificative', js: true do
before do before do
login_as administrateur, scope: :administrateur login_as administrateur, scope: :administrateur
end end
context 'when there is no piece justificative' do context 'when there is an existing piece justificative' do
let(:procedure) { create(:procedure, administrateur: administrateur) } let(:procedure) { create(:procedure, administrateur: administrateur) }
before do before do
# Create a dummy PJ, because adding PJs is no longer allowed on procedures that
# do not already have one
procedure.types_de_piece_justificative.create(libelle: "dummy PJ")
visit admin_procedure_pieces_justificatives_path(procedure) visit admin_procedure_pieces_justificatives_path(procedure)
end end
scenario 'displays a form to add new type de piece justificative' do scenario 'displays a form to add new type de piece justificative' do
within '#new_type_de_piece_justificative' do within '#new_type_de_piece_justificative' do
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_0_libelle') expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_1_libelle')
end end
end end
context 'when user fills field and submit' do context 'when user fills field and submit' do
let(:libelle) { 'ma piece' } let(:libelle) { 'ma piece' }
let(:description) { 'ma description' } let(:description) { 'ma description' }
before do before do
page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set(libelle) page.find_by_id('procedure_types_de_piece_justificative_attributes_1_libelle').set(libelle)
page.find_by_id('procedure_types_de_piece_justificative_attributes_0_description').set(description) page.find_by_id('procedure_types_de_piece_justificative_attributes_1_description').set(description)
page.click_on 'Ajouter la pièce' page.click_on 'Ajouter la pièce'
wait_for_ajax wait_for_ajax
end end
subject do subject do
procedure.reload procedure.reload
procedure.types_de_piece_justificative.first procedure.types_de_piece_justificative.second
end end
scenario 'creates new type de piece' do scenario 'creates new type de piece' do
expect(subject.libelle).to eq(libelle) expect(subject.libelle).to eq(libelle)
@ -35,23 +38,23 @@ feature 'add a new type de piece justificative', js: true do
end end
scenario 'displays new created pj' do scenario 'displays new created pj' do
within '#liste_piece_justificative' do within '#liste_piece_justificative' do
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_0_libelle') expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_1_libelle')
expect(page.body).to match(libelle) expect(page.body).to match(libelle)
expect(page.body).to match(description) expect(page.body).to match(description)
end end
within '#new_type_de_piece_justificative' do within '#new_type_de_piece_justificative' do
expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_1_libelle') expect(page).to have_css('#procedure_types_de_piece_justificative_attributes_2_libelle')
end end
end end
context 'when user delete pj' do context 'when user delete pj' do
before do before do
pj = procedure.types_de_piece_justificative.first pj = procedure.types_de_piece_justificative.second
page.find_by_id("delete_type_de_piece_justificative_#{pj.id}").click page.find_by_id("delete_type_de_piece_justificative_#{pj.id}").click
wait_for_ajax wait_for_ajax
end end
scenario 'removes pj from page' do scenario 'removes pj from page' do
within '#liste_piece_justificative' do within '#liste_piece_justificative' do
expect(page).not_to have_css('#procedure_types_de_piece_justificative_attributes_0_libelle') expect(page).not_to have_css('#procedure_types_de_piece_justificative_attributes_1_libelle')
expect(page.body).not_to match(libelle) expect(page.body).not_to match(libelle)
expect(page.body).not_to match(description) expect(page.body).not_to match(description)
end end
@ -60,12 +63,12 @@ feature 'add a new type de piece justificative', js: true do
context 'when user change existing type de pj' do context 'when user change existing type de pj' do
let(:new_libelle) { 'mon nouveau libelle' } let(:new_libelle) { 'mon nouveau libelle' }
before do before do
page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set(new_libelle) page.find_by_id('procedure_types_de_piece_justificative_attributes_1_libelle').set(new_libelle)
page.find_by_id('save').click page.find_by_id('save').click
wait_for_ajax wait_for_ajax
end end
scenario 'saves change in database' do scenario 'saves change in database' do
pj = procedure.types_de_piece_justificative.first pj = procedure.types_de_piece_justificative.second
expect(pj.libelle).to eq(new_libelle) expect(pj.libelle).to eq(new_libelle)
end end
end end

View file

@ -87,6 +87,13 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
procedure.update(service: create(:service)) procedure.update(service: create(:service))
end end
context 'With old PJ' do
before do
# Create a dummy PJ, because adding PJs is no longer allowed on procedures that
# do not already have one
Procedure.last.types_de_piece_justificative.create(libelle: "dummy PJ")
end
scenario 'Add champ, add file, visualize them in procedure preview' do scenario 'Add champ, add file, visualize them in procedure preview' do
fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ' fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ'
click_on 'add_type_de_champ' click_on 'add_type_de_champ'
@ -144,3 +151,4 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
end end
end end
end end
end