diff --git a/app/components/account_dropdown_component.rb b/app/components/account_dropdown_component.rb index 9c99f1ab5..0556acca3 100644 --- a/app/components/account_dropdown_component.rb +++ b/app/components/account_dropdown_component.rb @@ -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 diff --git a/app/components/account_dropdown_component/account_dropdown_component.html.haml b/app/components/account_dropdown_component/account_dropdown_component.html.haml index 71f71ea17..a8ee015c8 100644 --- a/app/components/account_dropdown_component/account_dropdown_component.html.haml +++ b/app/components/account_dropdown_component/account_dropdown_component.html.haml @@ -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 diff --git a/spec/components/account_dropdown_component_spec.rb b/spec/components/account_dropdown_component_spec.rb index bd3ef8862..786154ea5 100644 --- a/spec/components/account_dropdown_component_spec.rb +++ b/spec/components/account_dropdown_component_spec.rb @@ -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