diff --git a/app/assets/stylesheets/new_design/procedure_context.scss b/app/assets/stylesheets/new_design/procedure_context.scss index f0772825f..714097652 100644 --- a/app/assets/stylesheets/new_design/procedure_context.scss +++ b/app/assets/stylesheets/new_design/procedure_context.scss @@ -34,7 +34,7 @@ $procedure-context-breakpoint: $two-columns-breakpoint; } .procedure-description { - font-size: 14px; + font-size: 16px; p { margin-bottom: 2 * $default-spacer; 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/controllers/support_controller.rb b/app/controllers/support_controller.rb index 034ba0a0e..b907e20a5 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/support_controller.rb @@ -60,11 +60,11 @@ class SupportController < ApplicationController end def create_commentaire - params = { + attributes = { file: params[:file], body: "[#{params[:subject]}]

#{params[:text]}" } - commentaire = CommentaireService.build_with_email(email, dossier, params) + commentaire = CommentaireService.build_with_email(email, dossier, attributes) commentaire.save! 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/controllers/support_controller_spec.rb b/spec/controllers/support_controller_spec.rb index 4852a3b4b..4ae584139 100644 --- a/spec/controllers/support_controller_spec.rb +++ b/spec/controllers/support_controller_spec.rb @@ -7,6 +7,7 @@ describe SupportController, type: :controller do before do sign_in user end + let(:user) { create(:user) } it 'should not have email field' do @@ -51,55 +52,67 @@ describe SupportController, type: :controller do end describe "send form" do - it 'should create conversation' do - expect(subject).not_to receive(:create_commentaire) - allow(subject).to receive(:create_conversation).and_return(true) + subject do + post :create, params: { subject: 'bonjour', text: 'un message' } + end - post :create, params: { - subject: 'bonjour', - text: 'un message' - } + it 'creates a conversation on HelpScout' do + expect_any_instance_of(Helpscout::FormAdapter).to receive(:send_form).and_return(true) + + expect { subject }.to change(Commentaire, :count).by(0) expect(flash[:notice]).to match('Votre message a été envoyé.') expect(response).to redirect_to root_path(formulaire_contact_general_submitted: true) end - context "with dossier" do - let(:user) { dossier.user } + context 'when a drafted dossier is mentionned' do let(:dossier) { create(:dossier) } + let(:user) { dossier.user } - it 'should create conversation' do - expect(subject).not_to receive(:create_commentaire) - allow(subject).to receive(:create_conversation).and_return(true) - + subject do post :create, params: { dossier_id: dossier.id, type: Helpscout::FormAdapter::TYPE_INSTRUCTION, subject: 'bonjour', text: 'un message' } + end + + it 'creates a conversation on HelpScout' do + expect_any_instance_of(Helpscout::FormAdapter).to receive(:send_form).and_return(true) + + expect { subject }.to change(Commentaire, :count).by(0) expect(flash[:notice]).to match('Votre message a été envoyé.') expect(response).to redirect_to root_path(formulaire_contact_general_submitted: true) end + end - context "en_construction" do - let(:dossier) { create(:dossier, :en_construction) } + context 'when a submitted dossier is mentionned' do + let(:dossier) { create(:dossier, :en_construction) } + let(:user) { dossier.user } - it 'should create commentaire' do - allow(subject).to receive(:create_commentaire).and_return(true) - expect(subject).not_to receive(:create_conversation) + subject do + post :create, params: { + dossier_id: dossier.id, + type: Helpscout::FormAdapter::TYPE_INSTRUCTION, + subject: 'bonjour', + text: 'un message' + } + end - post :create, params: { - dossier_id: dossier.id, - type: Helpscout::FormAdapter::TYPE_INSTRUCTION, - subject: 'bonjour', - text: 'un message' - } + it 'posts the message to the dossier messagerie' do + expect_any_instance_of(Helpscout::FormAdapter).not_to receive(:send_form) - expect(flash[:notice]).to match('Votre message a été envoyé sur la messagerie de votre dossier.') - expect(response).to redirect_to messagerie_dossier_path(dossier) - end + expect { subject }.to change(Commentaire, :count).by(1) + + expect(Commentaire.last.email).to eq(user.email) + expect(Commentaire.last.dossier).to eq(dossier) + expect(Commentaire.last.body).to include('[bonjour]') + expect(Commentaire.last.body).to include('un message') + + expect(flash[:notice]).to match('Votre message a été envoyé sur la messagerie de votre dossier.') + expect(response).to redirect_to messagerie_dossier_path(dossier) end end end 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