feat(champ_pj): warn administrators about ephemeral template links

Closes #7681
This commit is contained in:
Colin Darie 2022-09-19 18:27:50 +02:00
parent 0f6a611b6f
commit 6a943ad13f
6 changed files with 42 additions and 2 deletions

View file

@ -2,10 +2,11 @@ describe 'shared/attachment/_update.html.haml', type: :view do
let(:champ) { build(:champ_piece_justificative, dossier: create(:dossier)) }
let(:attached_file) { champ.piece_justificative_file }
let(:user_can_destroy) { false }
let(:template) { nil }
subject do
form_for(champ.dossier) do |form|
view.render Attachment::EditComponent.new(form: form, attached_file: attached_file, user_can_destroy: true, direct_upload: true)
view.render Attachment::EditComponent.new(form: form, attached_file: attached_file, user_can_destroy: true, direct_upload: true, template:)
end
end
@ -64,4 +65,26 @@ describe 'shared/attachment/_update.html.haml', type: :view do
is_expected.not_to have_link('Supprimer')
end
end
context 'when champ has a template' do
let(:profil) { :user }
let(:template) { champ.type_de_champ.piece_justificative_template }
before do
allow_any_instance_of(ActionView::Base).to receive(:administrateur_signed_in?).and_return(profil == :administrateur)
end
it 'renders a link to template' do
expect(subject).to have_link('le modèle suivant')
expect(subject).not_to have_text("éphémère")
end
context 'as an administrator' do
let(:profil) { :administrateur }
it 'warn about ephemeral template url' do
expect(subject).to have_link('le modèle suivant')
expect(subject).to have_text("éphémère")
end
end
end
end

View file

@ -1,6 +1,7 @@
describe 'shared/dossiers/edit.html.haml', type: :view do
before do
allow(controller).to receive(:current_user).and_return(dossier.user)
allow(view).to receive(:administrateur_signed_in?).and_return(false)
end
subject { render 'shared/dossiers/edit.html.haml', dossier: dossier, apercu: false }
@ -118,7 +119,9 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
end
context 'when dossier is brouillon' do
before { dossier.champs << champ }
before do
dossier.champs << champ
end
it 'can delete a piece justificative' do
expect(subject).to have_text('Supprimer')