fix(recherche): respects nav bar profile context

This commit is contained in:
Colin Darie 2024-09-11 15:13:16 +02:00
parent 0309e0f6b2
commit 16e1daac9b
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
4 changed files with 52 additions and 8 deletions

View file

@ -9,6 +9,18 @@ class RechercheController < ApplicationController
{ "table" => 'procedure', "column" => 'procedure_id' } { "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 def index
@search_terms = search_terms @search_terms = search_terms
@dossiers_count = 0 @dossiers_count = 0

View file

@ -61,13 +61,13 @@
%li= render partial: 'layouts/locale_dropdown' %li= render partial: 'layouts/locale_dropdown'
- if params[:controller] == 'recherche'
= render partial: 'layouts/search_dossiers_form'
- if is_instructeur_context - 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 partial: 'layouts/search_dossiers_form'
= render SwitchDomainBannerComponent.new(user: current_user) = render SwitchDomainBannerComponent.new(user: current_user)

View file

@ -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]) %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 #search-473.fr-search-bar.fr-search-bar--lg
= form_tag recherche_index_path, method: :get, :role => "search", class: "flex width-100" do = 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' = 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" = text_field_tag "q", "#{@search_terms if @search_terms.present?}", placeholder: t('views.users.dossiers.search.search_file'), class: "fr-input"
%button.fr-btn %button.fr-btn

View file

@ -201,12 +201,43 @@ describe RechercheController, type: :controller do
context 'with no query param it does not crash' do context 'with no query param it does not crash' do
subject { get :index, params: {} } subject { get :index, params: {} }
it { is_expected.to have_http_status(200) }
it 'returns 0 dossier' do it 'returns 0 dossier' do
subject expect(subject).to have_http_status(200)
expect(assigns(:projected_dossiers).count).to eq(0) expect(assigns(:projected_dossiers).count).to eq(0)
end end
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
end end