Browse Source

moved toggle to a different place

pull/648/head
JG 3 years ago
parent
commit
7cae12b36c
  1. 12
      app/helpers/navigation_items_helper.rb
  2. 41
      spec/helpers/navigation_items_helper_spec.rb

12
app/helpers/navigation_items_helper.rb

@ -2,15 +2,21 @@ module NavigationItemsHelper
NavigationItem = Struct.new(:text, :href, :current, :classes) NavigationItem = Struct.new(:text, :href, :current, :classes)
def primary_items(path, current_user) def primary_items(path, current_user)
nav_items = []
if current_user.support? if current_user.support?
nav_items = [ [
NavigationItem.new("Organisations", organisations_path, organisations_current?(path)), NavigationItem.new("Organisations", organisations_path, organisations_current?(path)),
NavigationItem.new("Users", "/users", users_current?(path)), NavigationItem.new("Users", "/users", users_current?(path)),
NavigationItem.new("Logs", case_logs_path, logs_current?(path)), NavigationItem.new("Logs", case_logs_path, logs_current?(path)),
NavigationItem.new("Supported housing", "/supported-housing", supported_housing_current?(path)), NavigationItem.new("Supported housing", "/supported-housing", supported_housing_current?(path)),
] ]
elsif current_user.data_coordinator?
Rails.env.production? ? nav_items[0...-1] : nav_items [
NavigationItem.new("Logs", case_logs_path, logs_current?(path)),
NavigationItem.new("Supported housing", "/supported-housing", supported_housing_current?(path)),
NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)),
NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)),
]
else else
[ [
NavigationItem.new("Logs", case_logs_path, logs_current?(path)), NavigationItem.new("Logs", case_logs_path, logs_current?(path)),

41
spec/helpers/navigation_items_helper_spec.rb

@ -7,47 +7,6 @@ RSpec.describe NavigationItemsHelper do
let(:organisation_path) { "/organisations/#{current_user.organisation.id}" } let(:organisation_path) { "/organisations/#{current_user.organisation.id}" }
describe "#primary items" do describe "#primary items" do
context "when production environment" do
let(:expected_navigation_items) do
[
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", true),
NavigationItemsHelper::NavigationItem.new("Users", users_path, false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
]
end
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "data coordinator user can't see the link to supported housing" do
expect(primary_items("/logs", current_user)).to eq(expected_navigation_items)
end
context "data provider user" do
let(:current_user) { FactoryBot.create(:user) }
it "data provider user can't see the link to supported housing" do
expect(primary_items("/logs", current_user)).to eq(expected_navigation_items)
end
end
context "support user" do
let(:expected_navigation_items) do
[
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", true),
]
end
let(:current_user) { FactoryBot.create(:user, :support) }
it "support user can't see the link to supported housing" do
expect(primary_items("/logs", current_user)).to eq(expected_navigation_items)
end
end
end
context "when the user is a data coordinator" do context "when the user is a data coordinator" do
context "when the user is on the logs page" do context "when the user is on the logs page" do
let(:expected_navigation_items) do let(:expected_navigation_items) do

Loading…
Cancel
Save