feat(profile): keep procedure id context between admin & instructeur profile

This commit is contained in:
Colin Darie 2024-11-19 14:50:19 +01:00
parent e459f68ddb
commit c541ed7c93
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
3 changed files with 38 additions and 2 deletions

View file

@ -21,4 +21,22 @@ class AccountDropdownComponent < ViewComponent::Base
def show_profile_badge?
nav_bar_profile != :guest
end
def instructeur_path
if controller_name == "procedures" && params[:id].present?
instructeur_procedure_path(params[:id])
elsif params[:procedure_id].present?
instructeur_procedure_path(params[:procedure_id])
else
instructeur_procedures_path
end
end
def admin_path
if params[:procedure_id].present?
admin_procedure_path(params[:procedure_id])
else
admin_procedures_path
end
end
end

View file

@ -23,7 +23,7 @@
= t('.go_user')
- if instructeur_signed_in? && nav_bar_profile != :instructeur
%li
= link_to instructeur_procedures_path, class: "fr-nav__link" do
= link_to instructeur_path, class: "fr-nav__link" do
%span.fr-icon-refresh-line.fr-icon--sm
= t('.go_instructor')
- if expert_signed_in? && nav_bar_profile != :expert
@ -33,7 +33,7 @@
= t('.go_expert')
- if administrateur_signed_in? && nav_bar_profile != :administrateur
%li
= link_to admin_procedures_path, class: "fr-nav__link" do
= link_to admin_path, class: "fr-nav__link" do
%span.fr-icon-refresh-line.fr-icon--sm
= t('.go_admin')
- if gestionnaire_signed_in? && nav_bar_profile != :gestionnaire

View file

@ -55,4 +55,22 @@ describe AccountDropdownComponent, type: :component do
end
end
end
context 'when in procedures controller' do
before do
allow_any_instance_of(ApplicationController).to receive(:instructeur_signed_in?).and_return(true)
allow_any_instance_of(ApplicationController).to receive(:controller_name).and_return('procedures')
end
context 'with procedure id' do
before do
allow_any_instance_of(ApplicationController).to receive(:params)
.and_return({ id: '123' })
end
it 'links to specific procedure for instructor' do
expect(subject.to_html).to include('/procedures/123')
end
end
end
end