From 549b17f75e75998ee7f32d63a1e2e103a6f3a1bc Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 13 Mar 2019 15:48:38 +0000 Subject: [PATCH] help: add a custom help dropdown in dossier context --- .../stylesheets/new_design/help_dropdown.scss | 51 +++++++++++ .../new_user/dossiers_controller.rb | 5 ++ app/views/layouts/_new_header.haml | 8 +- .../new_user/_dossier_help_dropdown.html.haml | 42 ++++++++++ .../new_user/dossiers_controller_spec.rb | 26 ++++++ spec/features/help_spec.rb | 84 +++++++++++++++++++ .../new_gestionnaire/gestionnaire_spec.rb | 2 +- spec/views/layouts/_new_header_spec.rb | 4 + 8 files changed, 219 insertions(+), 3 deletions(-) create mode 100644 app/assets/stylesheets/new_design/help_dropdown.scss create mode 100644 app/views/new_user/_dossier_help_dropdown.html.haml create mode 100644 spec/features/help_spec.rb diff --git a/app/assets/stylesheets/new_design/help_dropdown.scss b/app/assets/stylesheets/new_design/help_dropdown.scss new file mode 100644 index 000000000..01d8bd70c --- /dev/null +++ b/app/assets/stylesheets/new_design/help_dropdown.scss @@ -0,0 +1,51 @@ +@import "colors"; +@import "constants"; + +.help-dropdown { + .dropdown-content { + width: 340px; + } + + .dropdown-description { + font-size: 14px; + } +} + +h4.help-dropdown-title { + font-size: 16px; + color: $blue; +} + +.dropdown-items li.help-dropdown-service { + cursor: default; + + &:hover { + background: inherit; + } + + a { + display: inline; + color: $blue; + } +} + +.help-dropdown-service-action { + margin-top: $default-padding; + margin-bottom: $default-spacer; +} + +.help-dropdown-service-item { + margin-top: $default-spacer; + line-height: 18px; + + .icon { + vertical-align: middle; + margin-right: 5px; + + &.clock { + filter: contrast(0) brightness(120%); + vertical-align: -4px; + } + } +} + diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index b4bb54a99..44091e710 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -240,6 +240,11 @@ module NewUser flash.notice = 'La pièce jointe a bien été supprimée.' end + def dossier_for_help + dossier_id = params[:id] || params[:dossier_id] + @dossier || (dossier_id.present? && Dossier.find_by(id: dossier_id.to_i)) + end + private def store_user_location! diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 81d141c51..6782ee596 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -1,5 +1,6 @@ -/ We can't use &. because the controller may not implement #nav_bar_profile +-# We can't use &. because the controller may not implement #nav_bar_profile - nav_bar_profile = controller.try(:nav_bar_profile) +- dossier = controller.try(:dossier_for_help) .new-header{ class: current_page?(root_path) ? nil : "new-header-with-border" } .header-inner-content @@ -95,4 +96,7 @@ %li .header-help - = link_to 'Aide', FAQ_URL, class: "button primary", target: "_blank", rel: "noopener" + - if nav_bar_profile == :user && dossier.present? + = render partial: 'new_user/dossier_help_dropdown', locals: { dossier: dossier } + - else + = link_to 'Aide', FAQ_URL, class: "button primary" diff --git a/app/views/new_user/_dossier_help_dropdown.html.haml b/app/views/new_user/_dossier_help_dropdown.html.haml new file mode 100644 index 000000000..275b7e1ac --- /dev/null +++ b/app/views/new_user/_dossier_help_dropdown.html.haml @@ -0,0 +1,42 @@ +.dropdown.help-dropdown + .button.primary.dropdown-button Aide + .dropdown-content.fade-in-down + %ul.dropdown-items + + - title = dossier.brouillon? ? "Besoin d’aide pour remplir votre dossier ?" : "Une question sur votre dossier ?" + + - if dossier.messagerie_available? + -# Contact the administration using the messagerie + %li + = link_to messagerie_dossier_path(dossier) do + %span.icon.mail + .dropdown-description + %h4.help-dropdown-title= title + %p Envoyez directement un message à l’instructeur. + + - elsif dossier.procedure.service.present? + - service = dossier.procedure.service + -# Contact the administration using email or phone + %li.help-dropdown-service + %span.icon.person + .dropdown-description + %h4.help-dropdown-title= title + .help-dropdown-service-action + %p Contactez directement l’administration : + %p.help-dropdown-service-item + %span.icon.small.mail + = link_to service.email, "mailto:#{service.email}" + %p.help-dropdown-service-item + %span.icon.small.phone + = link_to service.telephone, "tel:#{service.telephone}" + %p.help-dropdown-service-item + %span.icon.small.clock + = service.horaires + + -# Use the help website + %li + = link_to FAQ_URL, target: "_blank", rel: "noopener" do + %span.icon.help + .dropdown-description + %h4.help-dropdown-title Un problème avec le site ? + %p Trouvez votre réponse dans l’aide en ligne. diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index a981b85b9..6d133d62b 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -952,4 +952,30 @@ describe NewUser::DossiersController, type: :controller do end end end + + describe "#dossier_for_help" do + before do + sign_in(user) + controller.params[:dossier_id] = dossier_id.to_s + end + + subject { controller.dossier_for_help } + + context 'when the id matches an existing dossier' do + let(:dossier) { create(:dossier) } + let(:dossier_id) { dossier.id } + + it { is_expected.to eq dossier } + end + + context 'when the id doesn’t match an existing dossier' do + let(:dossier_id) { 9999999 } + it { is_expected.to be nil } + end + + context 'when the id is empty' do + let(:dossier_id) { nil } + it { is_expected.to be_falsy } + end + end end diff --git a/spec/features/help_spec.rb b/spec/features/help_spec.rb new file mode 100644 index 000000000..b44fb6270 --- /dev/null +++ b/spec/features/help_spec.rb @@ -0,0 +1,84 @@ +require 'spec_helper' + +feature 'Getting help:' do + scenario 'a Help button is visible on public pages' do + visit '/' + within('.new-header') do + expect(page).to have_help_button + end + end + + context 'as a signed-in user' do + let(:user) { create(:user) } + let(:procedure) { create(:procedure, :with_service) } + + before do + login_as user, scope: :user + end + + scenario 'a Help button is visible on signed-in pages' do + visit dossiers_path + within('.new-header') do + expect(page).to have_help_button + end + end + + context 'on a page related to a draft dossier' do + let(:dossier) { create(:dossier, user: user, procedure: procedure) } + + scenario 'a Help menu provides administration contacts and a link to the FAQ' do + visit dossier_path(dossier) + + within('.new-header') do + expect(page).to have_help_menu + end + + within('.help-dropdown') do + expect(page).to have_content(dossier.procedure.service.email) + expect(page).to have_content(dossier.procedure.service.telephone) + expect(page).to have_link(nil, href: FAQ_URL) + end + end + end + + context 'on a page related to a submitted dossier' do + let(:dossier) { create(:dossier, :en_construction, user: user, procedure: procedure) } + + scenario 'a Help menu provides links to the Messagerie and to the FAQ' do + visit dossier_path(dossier) + + within('.new-header') do + expect(page).to have_help_menu + end + + within('.help-dropdown') do + expect(page).to have_link(nil, href: messagerie_dossier_path(dossier)) + expect(page).to have_link(nil, href: FAQ_URL) + end + end + end + end + + context 'as a gestionnaire' do + let(:gestionnaire) { create(:gestionnaire) } + + before do + login_as gestionnaire, scope: :gestionnaire + end + + scenario 'a Help button is visible on signed-in pages' do + visit gestionnaire_procedures_path + within('.new-header') do + expect(page).to have_help_button + end + end + end + + def have_help_button + have_link('Aide', href: FAQ_URL) + end + + def have_help_menu + have_selector('.help-dropdown') + end +end diff --git a/spec/features/new_gestionnaire/gestionnaire_spec.rb b/spec/features/new_gestionnaire/gestionnaire_spec.rb index e19676b0d..45b740660 100644 --- a/spec/features/new_gestionnaire/gestionnaire_spec.rb +++ b/spec/features/new_gestionnaire/gestionnaire_spec.rb @@ -54,7 +54,7 @@ feature 'The gestionnaire part' do click_on 'En instruction' - within('.dropdown-items') do + within('.state-button') do click_on 'Accepter' end diff --git a/spec/views/layouts/_new_header_spec.rb b/spec/views/layouts/_new_header_spec.rb index 17980f07e..373a14586 100644 --- a/spec/views/layouts/_new_header_spec.rb +++ b/spec/views/layouts/_new_header_spec.rb @@ -16,6 +16,10 @@ describe 'layouts/_new_header.html.haml', type: :view do it { is_expected.to have_css("a.header-logo[href=\"#{dossiers_path}\"]") } it { is_expected.to have_link("Dossiers", href: dossiers_path) } + + it 'displays the Help button' do + expect(subject).to have_link("Aide", href: FAQ_URL) + end end context 'when rendering for gestionnaire' do