diff --git a/app/assets/stylesheets/new_design/dossier_show.scss b/app/assets/stylesheets/new_design/dossier_show.scss index def3e15d3..be12db19e 100644 --- a/app/assets/stylesheets/new_design/dossier_show.scss +++ b/app/assets/stylesheets/new_design/dossier_show.scss @@ -38,4 +38,15 @@ .messagerie-explanation { margin-bottom: $default-padding * 2; } + + .latest-message-section { + display: flex; + flex-direction: column; + max-width: 700px; + margin-bottom: $default-padding * 2; + + .button.send { + align-self: flex-end; + } + } } diff --git a/app/assets/stylesheets/new_design/message.scss b/app/assets/stylesheets/new_design/message.scss index 025a7783e..7c87e763e 100644 --- a/app/assets/stylesheets/new_design/message.scss +++ b/app/assets/stylesheets/new_design/message.scss @@ -9,6 +9,10 @@ background: #FFFFFF; border-radius: 3px; + &.inverted-background { + background: $light-grey; + } + .person-icon { margin-right: $default-spacer; } diff --git a/app/assets/stylesheets/new_design/status_overview.scss b/app/assets/stylesheets/new_design/status_overview.scss index 49ad8a55b..55643b1d3 100644 --- a/app/assets/stylesheets/new_design/status_overview.scss +++ b/app/assets/stylesheets/new_design/status_overview.scss @@ -3,6 +3,7 @@ .status-overview { text-align: center; + margin-bottom: $default-padding * 2; } .status-timeline { diff --git a/app/helpers/commentaire_helper.rb b/app/helpers/commentaire_helper.rb index 7702e85c6..f42450024 100644 --- a/app/helpers/commentaire_helper.rb +++ b/app/helpers/commentaire_helper.rb @@ -5,6 +5,14 @@ module CommentaireHelper end end + def commentaire_answer_action(commentaire, connected_user) + if commentaire_is_from_me(commentaire, connected_user) + "Envoyer un message à l’instructeur" + else + "Répondre dans la messagerie" + end + end + def commentaire_is_from_guest(commentaire) commentaire.dossier.invites.map(&:email).include?(commentaire.email) end diff --git a/app/views/new_user/dossiers/show.html.haml b/app/views/new_user/dossiers/show.html.haml index e6e17707c..b94a0686f 100644 --- a/app/views/new_user/dossiers/show.html.haml +++ b/app/views/new_user/dossiers/show.html.haml @@ -5,3 +5,13 @@ .container = render partial: 'new_user/dossiers/show/status_overview', locals: { dossier: @dossier } + + - latest_message = @dossier.commentaires.last + - if latest_message.present? + .latest-message-section + %h3.tab-title Dernier message + + .message.inverted-background + = render partial: "shared/dossiers/messages/message", locals: { commentaire: latest_message, connected_user: current_user, messagerie_seen_at: nil } + + = link_to commentaire_answer_action(latest_message, current_user), messagerie_dossier_url(@dossier, anchor: 'new_commentaire'), class: 'button send' diff --git a/spec/features/new_user/dossier_details_spec.rb b/spec/features/new_user/dossier_details_spec.rb index d6644e634..41575988b 100644 --- a/spec/features/new_user/dossier_details_spec.rb +++ b/spec/features/new_user/dossier_details_spec.rb @@ -4,7 +4,7 @@ describe 'Dossier details:' do tdcs = [create(:type_de_champ, libelle: 'texte obligatoire')] create(:procedure, :published, :for_individual, types_de_champ: tdcs) end - let(:dossier) { create(:dossier, :en_construction, :for_individual, user: user, procedure: simple_procedure) } + let(:dossier) { create(:dossier, :en_construction, :for_individual, :with_commentaires, user: user, procedure: simple_procedure) } before do Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, true) @@ -16,6 +16,7 @@ describe 'Dossier details:' do expect(page).to have_current_path(dossier_path(dossier)) expect(page).to have_content(dossier.id) expect(page).to have_selector('.status-explanation') + expect(page).to have_text(dossier.commentaires.last.body) end scenario 'the user can see and edit dossier before instruction' do diff --git a/spec/helpers/commentaire_helper_spec.rb b/spec/helpers/commentaire_helper_spec.rb index ec1430f22..36d235f42 100644 --- a/spec/helpers/commentaire_helper_spec.rb +++ b/spec/helpers/commentaire_helper_spec.rb @@ -7,16 +7,30 @@ RSpec.describe CommentaireHelper, type: :helper do subject { commentaire_is_from_me_class(commentaire, me) } context "when commentaire is from me" do - let(:me) { "michel@pref.fr" } + let(:me) { User.new(email: "michel@pref.fr") } it { is_expected.to eq("from-me") } end context "when commentaire is not from me" do - let(:me) { "roger@usager.fr" } + let(:me) { User.new(email: "roger@usager.fr") } it { is_expected.to eq nil } end end + describe '.commentaire_answer_action' do + subject { commentaire_answer_action(commentaire, me) } + + context "when commentaire is from me" do + let(:me) { User.new(email: "michel@pref.fr") } + it { is_expected.to include('Envoyer') } + end + + context "when commentaire is not from me" do + let(:me) { User.new(email: "roger@usager.fr") } + it { is_expected.to include('Répondre') } + end + end + describe '.commentaire_is_from_guest' do let(:dossier) { create(:dossier) } let!(:guest) { create(:invite_user, dossier: dossier) } diff --git a/spec/views/new_user/dossiers/show.html.haml_spec.rb b/spec/views/new_user/dossiers/show.html.haml_spec.rb index 303f1f244..977b5677b 100644 --- a/spec/views/new_user/dossiers/show.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'new_user/dossiers/show.html.haml', type: :view do - let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure)) } + let(:dossier) { create(:dossier, :en_construction) } before do sign_in dossier.user @@ -14,4 +14,15 @@ describe 'new_user/dossiers/show.html.haml', type: :view do expect(rendered).to have_text("Dossier nº #{dossier.id}") expect(rendered).to have_selector('.status-overview') end + + context 'with messages' do + let(:first_message) { create(:commentaire, body: 'Premier message') } + let(:last_message) { create(:commentaire, body: 'Second message') } + let(:dossier) { create(:dossier, :en_construction, commentaires: [first_message, last_message]) } + + it 'displays the last message' do + expect(rendered).not_to have_text(first_message.body) + expect(rendered).to have_text(last_message.body) + end + end end