diff --git a/app/controllers/recherche_controller.rb b/app/controllers/recherche_controller.rb index 73b9df448..98d684792 100644 --- a/app/controllers/recherche_controller.rb +++ b/app/controllers/recherche_controller.rb @@ -9,6 +9,18 @@ class RechercheController < ApplicationController { "table" => 'procedure', "column" => 'procedure_id' } ] + def nav_bar_profile + return super if request.blank? # Controller introspection does not contains params/request, see NavBarProfileConcern + + context_params = params[:context]&.to_sym + case context_params + when :instructeur, :expert + context_params + else + :user + end + end + def index @search_terms = search_terms @dossiers_count = 0 diff --git a/app/views/layouts/_header.haml b/app/views/layouts/_header.haml index 3bc89efd5..6b1e1ab47 100644 --- a/app/views/layouts/_header.haml +++ b/app/views/layouts/_header.haml @@ -61,13 +61,13 @@ %li= render partial: 'layouts/locale_dropdown' - - if params[:controller] == 'recherche' - = render partial: 'layouts/search_dossiers_form' - - if is_instructeur_context - = render partial: 'layouts/search_dossiers_form' + = render partial: 'layouts/search_dossiers_form', locals: { context: :instructeur } - - if is_expert_context + - elsif is_expert_context + = render partial: 'layouts/search_dossiers_form', locals: { context: :expert } + + - elsif params[:controller] == 'recherche' = render partial: 'layouts/search_dossiers_form' = render SwitchDomainBannerComponent.new(user: current_user) diff --git a/app/views/layouts/_search_dossiers_form.html.haml b/app/views/layouts/_search_dossiers_form.html.haml index 959616163..3ae8dc46d 100644 --- a/app/views/layouts/_search_dossiers_form.html.haml +++ b/app/views/layouts/_search_dossiers_form.html.haml @@ -3,6 +3,7 @@ %button.fr-btn--close.fr-btn{ "aria-controls" => "search-modal", :title => t('close_modal', scope: [:layouts, :header]) }= t('close_modal', scope: [:layouts, :header]) #search-473.fr-search-bar.fr-search-bar--lg = form_tag recherche_index_path, method: :get, :role => "search", class: "flex width-100" do + = hidden_field_tag :context, local_assigns[:context] = label_tag "q", t('views.users.dossiers.search.search_file'), class: 'sr-only' = text_field_tag "q", "#{@search_terms if @search_terms.present?}", placeholder: t('views.users.dossiers.search.search_file'), class: "fr-input" %button.fr-btn diff --git a/spec/controllers/recherche_controller_spec.rb b/spec/controllers/recherche_controller_spec.rb index feceb68d1..0c155fa48 100644 --- a/spec/controllers/recherche_controller_spec.rb +++ b/spec/controllers/recherche_controller_spec.rb @@ -201,12 +201,43 @@ describe RechercheController, type: :controller do context 'with no query param it does not crash' do subject { get :index, params: {} } - it { is_expected.to have_http_status(200) } - it 'returns 0 dossier' do - subject + expect(subject).to have_http_status(200) expect(assigns(:projected_dossiers).count).to eq(0) end end + + context 'nav bar profile in user context' do + subject { get(:index, params: {}).body } + render_views + + it 'define user nav' do + expect(subject).to include "Mes dossiers" + expect(subject).to include "usager" + end + end + + context 'nav bar profile in instructeur context' do + subject { get(:index, params: { context: :instructeur }).body } + render_views + + it 'define instructeur nav' do + expect(subject).to include "Démarches" + expect(subject).to include "instructeur" + expect(subject).not_to include "Mes dossiers" + end + end + + context 'nav bar profile in expert context' do + before { user.create_expert } + subject { get(:index, params: { context: :expert }).body } + render_views + + it 'define expert nav' do + expect(subject).to include "Avis" + expect(subject).to include "expert" + expect(subject).not_to include "Mes dossiers" + end + end end end