From 158d6e1ae60eb27e141271e17024b0b1a915c0f2 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 4 Apr 2019 08:13:24 +0000 Subject: [PATCH] avis: format newlines in avis Fix #3738 --- app/assets/stylesheets/new_design/avis.scss | 4 ++++ .../gestionnaires/shared/avis/_list.html.haml | 3 ++- spec/factories/avis.rb | 4 ++++ .../shared/avis/list.html.haml_spec.rb | 20 +++++++++++++------ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/new_design/avis.scss b/app/assets/stylesheets/new_design/avis.scss index 0217f3d76..42e7c354d 100644 --- a/app/assets/stylesheets/new_design/avis.scss +++ b/app/assets/stylesheets/new_design/avis.scss @@ -105,6 +105,10 @@ margin-top: $default-padding; } + .answer-body p:not(:last-of-type) { + margin-bottom: $default-padding; + } + .avis-icon { margin-right: $default-spacer; } diff --git a/app/views/gestionnaires/shared/avis/_list.html.haml b/app/views/gestionnaires/shared/avis/_list.html.haml index 23acc5a0b..c5837aac5 100644 --- a/app/views/gestionnaires/shared/avis/_list.html.haml +++ b/app/views/gestionnaires/shared/avis/_list.html.haml @@ -29,4 +29,5 @@ - else %span.waiting En attente de réponse = render partial: 'shared/piece_jointe/pj_link', locals: { object: avis, pj: avis.piece_justificative_file } - %p= avis.answer + .answer-body + = simple_format(avis.answer) diff --git a/spec/factories/avis.rb b/spec/factories/avis.rb index 97abb989b..b7f4f556e 100644 --- a/spec/factories/avis.rb +++ b/spec/factories/avis.rb @@ -19,5 +19,9 @@ FactoryBot.define do avis.claimant = create :gestionnaire end end + + trait :with_answer do + answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." } + end end end diff --git a/spec/views/gestionnaire/shared/avis/list.html.haml_spec.rb b/spec/views/gestionnaire/shared/avis/list.html.haml_spec.rb index 1f8797785..d8abdcbe8 100644 --- a/spec/views/gestionnaire/shared/avis/list.html.haml_spec.rb +++ b/spec/views/gestionnaire/shared/avis/list.html.haml_spec.rb @@ -1,3 +1,5 @@ +require 'spec_helper' + describe 'gestionnaires/shared/avis/_list.html.haml', type: :view do before { view.extend DossierHelper } @@ -5,16 +7,22 @@ describe 'gestionnaires/shared/avis/_list.html.haml', type: :view do let(:gestionnaire) { create(:gestionnaire) } let(:avis) { [create(:avis, claimant: gestionnaire)] } + let(:seen_at) { avis.first.created_at + 1.hour } - context "with a seen_at after avis created_at" do - let(:seen_at) { avis.first.created_at + 1.hour } + it { is_expected.to have_text(avis.first.introduction) } + it { is_expected.not_to have_css(".highlighted") } - it { is_expected.not_to have_css(".highlighted") } - end - - context "with a seen_at after avis created_at" do + context 'with a seen_at before avis created_at' do let(:seen_at) { avis.first.created_at - 1.hour } it { is_expected.to have_css(".highlighted") } end + + context 'with an answer' do + let(:avis) { [create(:avis, :with_answer, claimant: gestionnaire)] } + + it 'renders the answer formatted with newlines' do + expect(subject).to include(simple_format(avis.first.answer)) + end + end end