diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index 2efa419cf..341a88da6 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -13,6 +13,10 @@ module NewGestionnaire send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf') end + def apercu_attestation + send_data(dossier.build_attestation.pdf.read, filename: 'apercu_attestation.pdf', disposition: 'inline', type: 'application/pdf') + end + def show @demande_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.demande_seen_at end diff --git a/app/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml b/app/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml index 6196d040a..dcca0fe2b 100644 --- a/app/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml +++ b/app/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml @@ -29,5 +29,7 @@ - else = text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: placeholder, required: true .text-right + - if title == 'Accepter' && dossier.procedure.attestation_template&.activated? + = link_to "Voir l'attestation", apercu_attestation_gestionnaire_dossier_path(dossier.procedure, dossier), target: '_blank', class: 'button', title: "Voir l'attestation qui sera envoyée au demandeur" %span.button{ onclick: 'DS.motivationCancel();' } Annuler = button_tag 'Valider la décision', name: :process_action, value: process_action, class: 'button primary', title: title, data: { confirm: confirm } diff --git a/config/routes.rb b/config/routes.rb index 57ce1673c..570844167 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -316,6 +316,7 @@ Rails.application.routes.draw do resources :dossiers, only: [:show], param: :dossier_id do member do get 'attestation' + get 'apercu_attestation' get 'messagerie' get 'annotations-privees' => 'dossiers#annotations_privees' get 'avis' diff --git a/spec/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml_spec.rb b/spec/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml_spec.rb new file mode 100644 index 000000000..4023b1e11 --- /dev/null +++ b/spec/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml_spec.rb @@ -0,0 +1,25 @@ +describe 'new_gestionnaire/dossiers/state_button_motivation.html.haml', type: :view do + let(:dossier) { create(:dossier, :en_instruction) } + + subject! do + render( + 'new_gestionnaire/dossiers/state_button_motivation.html.haml', + dossier: dossier, + popup_title: 'Accepter le dossier', + placeholder: 'Expliquez au demandeur pourquoi ce dossier est accepté (facultatif)', + popup_class: 'accept', + process_action: 'accepter', + title: 'Accepter', + confirm: "Confirmez-vous l'acceptation ce dossier ?" + ) + end + + context 'with an attestation preview' do + let(:dossier) { create :dossier, :accepte, :with_attestation } + it { expect(rendered).to have_text("Voir l'attestation") } + end + + context 'without an attestation preview' do + it { expect(rendered).not_to have_text("Voir l'attestation") } + end +end