Encourager la création de champs PJ plutôt que de vieilles PJS
This commit is contained in:
parent
ae8c61830a
commit
d1cfe4468d
4 changed files with 102 additions and 65 deletions
|
@ -239,6 +239,10 @@ class Procedure < ApplicationRecord
|
|||
whitelisted_at.present?
|
||||
end
|
||||
|
||||
def has_old_pjs?
|
||||
types_de_piece_justificative.any?
|
||||
end
|
||||
|
||||
def total_dossier
|
||||
self.dossiers.state_not_brouillon.size
|
||||
end
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
.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 à l’usager un fichier type à remplir et renvoyer
|
||||
%li Possibilité pour l’usager 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
|
||||
= render 'form'
|
||||
|
|
|
@ -6,28 +6,31 @@ feature 'add a new type de piece justificative', js: true do
|
|||
before do
|
||||
login_as administrateur, scope: :administrateur
|
||||
end
|
||||
context 'when there is no piece justificative' do
|
||||
context 'when there is an existing piece justificative' do
|
||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
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)
|
||||
end
|
||||
scenario 'displays a form to add 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
|
||||
context 'when user fills field and submit' do
|
||||
let(:libelle) { 'ma piece' }
|
||||
let(:description) { 'ma description' }
|
||||
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_0_description').set(description)
|
||||
page.find_by_id('procedure_types_de_piece_justificative_attributes_1_libelle').set(libelle)
|
||||
page.find_by_id('procedure_types_de_piece_justificative_attributes_1_description').set(description)
|
||||
page.click_on 'Ajouter la pièce'
|
||||
wait_for_ajax
|
||||
end
|
||||
subject do
|
||||
procedure.reload
|
||||
procedure.types_de_piece_justificative.first
|
||||
procedure.types_de_piece_justificative.second
|
||||
end
|
||||
scenario 'creates new type de piece' do
|
||||
expect(subject.libelle).to eq(libelle)
|
||||
|
@ -35,23 +38,23 @@ feature 'add a new type de piece justificative', js: true do
|
|||
end
|
||||
scenario 'displays new created pj' 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(description)
|
||||
end
|
||||
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
|
||||
context 'when user delete pj' 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
|
||||
wait_for_ajax
|
||||
end
|
||||
scenario 'removes pj from page' 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(description)
|
||||
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
|
||||
let(:new_libelle) { 'mon nouveau libelle' }
|
||||
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
|
||||
wait_for_ajax
|
||||
end
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -87,6 +87,13 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
|
|||
procedure.update(service: create(:service))
|
||||
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
|
||||
fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ'
|
||||
click_on 'add_type_de_champ'
|
||||
|
@ -143,4 +150,5 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
|
|||
expect(page).to have_selector('.procedure-lien')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue