From 38eb60f2ac9c18e295536ea83fa405bbf28559c9 Mon Sep 17 00:00:00 2001 From: Judith Date: Wed, 27 May 2020 11:25:43 +0200 Subject: [PATCH] views: display auto-archive date on procedure description --- .../new_design/procedure_context.scss | 23 +++++++++++++++++ app/helpers/procedure_helper.rb | 4 +++ .../shared/_procedure_description.html.haml | 9 +++++++ spec/helpers/procedure_helper_spec.rb | 10 ++++++++ .../_procedure_description.html.haml_spec.rb | 25 +++++++++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 spec/helpers/procedure_helper_spec.rb create mode 100644 spec/views/shared/_procedure_description.html.haml_spec.rb diff --git a/app/assets/stylesheets/new_design/procedure_context.scss b/app/assets/stylesheets/new_design/procedure_context.scss index 54df80fd2..7154cc30b 100644 --- a/app/assets/stylesheets/new_design/procedure_context.scss +++ b/app/assets/stylesheets/new_design/procedure_context.scss @@ -37,6 +37,29 @@ $procedure-description-line-height: 22px; } } + .procedure-auto-archive { + cursor: pointer; + + margin-bottom: 32px; + + p { + padding-top: 8px; + font-size: 16px; + } + + summary { + font-size: 20px; + + &:-webkit-details-marker { + display: none; + } + } + } + + .procedure-auto-archive-title { + border-bottom: 1px dotted $blue; + } + .procedure-description { font-size: 16px; diff --git a/app/helpers/procedure_helper.rb b/app/helpers/procedure_helper.rb index a6bb001de..17a757d93 100644 --- a/app/helpers/procedure_helper.rb +++ b/app/helpers/procedure_helper.rb @@ -38,5 +38,9 @@ module ProcedureHelper } end + def show_auto_archive(procedure) + I18n.l(procedure.auto_archive_on - 1.day, format: '%-d %B %Y') + end + private end diff --git a/app/views/shared/_procedure_description.html.haml b/app/views/shared/_procedure_description.html.haml index 7f8de4547..ba241bda0 100644 --- a/app/views/shared/_procedure_description.html.haml +++ b/app/views/shared/_procedure_description.html.haml @@ -7,6 +7,15 @@ = image_tag("flag_of_europe.svg", id: 'euro_flag', class: (!procedure.euro_flag ? "hidden" : "")) %h1.procedure-title = procedure.libelle + +- if procedure.auto_archive_on + %details.procedure-auto-archive + %summary + %span.icon.clock + + %span.procedure-auto-archive-title Date limite : #{show_auto_archive(procedure)} + %p Vous pouvez déposer vos dossiers jusqu'au #{show_auto_archive(procedure)} à 23 h 59 (heure de #{Rails.application.config.time_zone}). + .procedure-description .procedure-description-body.read-more-enabled.read-more-collapsed = h string_to_html(procedure.description) diff --git a/spec/helpers/procedure_helper_spec.rb b/spec/helpers/procedure_helper_spec.rb new file mode 100644 index 000000000..43476eeae --- /dev/null +++ b/spec/helpers/procedure_helper_spec.rb @@ -0,0 +1,10 @@ +RSpec.describe ProcedureHelper, type: :helper do + let(:auto_archive_date) { Time.zone.local(2020, 8, 2, 12, 00) } + let(:procedure) { create(:procedure, auto_archive_on: auto_archive_date) } + + subject { show_auto_archive(procedure) } + + it "displays the day before the auto archive date (to account for the '23h59' ending time)" do + expect(subject).to eq "1 août 2020" + end +end diff --git a/spec/views/shared/_procedure_description.html.haml_spec.rb b/spec/views/shared/_procedure_description.html.haml_spec.rb new file mode 100644 index 000000000..85005909b --- /dev/null +++ b/spec/views/shared/_procedure_description.html.haml_spec.rb @@ -0,0 +1,25 @@ +describe 'shared/_procedure_description.html.haml', type: :view do + let(:procedure) { create(:procedure, :published, :with_service) } + + subject { render partial: 'shared/procedure_description', locals: { procedure: procedure } } + + it 'renders the view' do + subject + expect(rendered).to have_selector('.procedure-logos') + expect(rendered).to have_text(procedure.libelle) + expect(rendered).to have_text(procedure.description) + end + + it 'does not show empty date limite' do + subject + expect(rendered).not_to have_text('Date limite') + end + + context 'when the procedure has an auto_archive date' do + let(:procedure) { create(:procedure, :published, :with_service, :with_auto_archive) } + it 'shows the auto_archive_on' do + subject + expect(rendered).to have_text('Date limite') + end + end +end