From 5737ab2f2de9a5bf9a2de8bf9095f939c719c555 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 9 May 2022 14:45:30 +0100 Subject: [PATCH] Works but helper is hard to test --- app/helpers/navigation_items_helper.rb | 10 ++++++---- app/views/layouts/application.html.erb | 2 +- spec/requests/users_controller_spec.rb | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index afc2bc0d3..8af63cd4c 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -1,17 +1,17 @@ module NavigationItemsHelper NavigationItem = Struct.new(:text, :href, :current, :classes) - def primary_items(current_user) + def primary_items(current_user, user) if current_user.support? [ NavigationItem.new("Organisations", organisations_path, organisation_current?), - NavigationItem.new("Users", users_path, users_current?), + NavigationItem.new("Users", users_path, users_current?(current_user, user)), NavigationItem.new("Logs", case_logs_path, logs_current?), ] else [ NavigationItem.new("Logs", case_logs_path, logs_current?), - NavigationItem.new("Users", users_organisation_path(current_user.organisation), users_current?), + NavigationItem.new("Users", users_organisation_path(current_user.organisation), users_current?(current_user, user)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", organisation_current?), ] end @@ -31,7 +31,9 @@ private current?(controller, %w[case_logs form]) end - def users_current? + def users_current?(current_user, user) + return false if current_user == user + current?(controller, %w[users]) || current_action?(controller, "users") end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 335cc0ff3..95dd2ac81 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -66,7 +66,7 @@ <% if !current_user.nil? %> <%= render PrimaryNavigationComponent.new( - items: primary_items(current_user), + items: primary_items(current_user, @user), ) %> <% end %> diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 2c2902094..cab9a81d6 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -357,6 +357,10 @@ RSpec.describe UsersController, type: :request do expect(page).to have_link("Change", text: "are you a data protection officer?") expect(page).to have_link("Change", text: "are you a key contact?") end + + it "does not highlight the users navigation tab" do + expect(page).not_to have_css('[aria-current="page"]', text: "Users") + end end context "when the current user does not match the user ID" do