Browse Source

moved toggle to PrimaryNavigationComponent

pull/648/head
JG 3 years ago
parent
commit
60fe6ac849
  1. 1
      app/components/primary_navigation_component.rb
  2. 14
      spec/components/primary_navigation_component_spec.rb

1
app/components/primary_navigation_component.rb

@ -3,6 +3,7 @@ class PrimaryNavigationComponent < ViewComponent::Base
def initialize(items:) def initialize(items:)
@items = items @items = items
Rails.env.production? ? @items = @items.reject { |nav_item| nav_item.text.include?("Supported housing") } : @items
super super
end end

14
spec/components/primary_navigation_component_spec.rb

@ -6,6 +6,7 @@ RSpec.describe PrimaryNavigationComponent, type: :component do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs ", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs ", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false),
] ]
end end
@ -24,6 +25,7 @@ RSpec.describe PrimaryNavigationComponent, type: :component do
expect(navigation_panel).to be_highlighted_item(items[0], "/something-else") expect(navigation_panel).to be_highlighted_item(items[0], "/something-else")
expect(navigation_panel).not_to be_highlighted_item(items[1], "/something-else") expect(navigation_panel).not_to be_highlighted_item(items[1], "/something-else")
expect(navigation_panel).not_to be_highlighted_item(items[2], "/something-else") expect(navigation_panel).not_to be_highlighted_item(items[2], "/something-else")
expect(navigation_panel).not_to be_highlighted_item(items[3], "/something-else")
end end
end end
@ -34,6 +36,18 @@ RSpec.describe PrimaryNavigationComponent, type: :component do
expect(result.text).to include("Organisations") expect(result.text).to include("Organisations")
expect(result.text).to include("Users") expect(result.text).to include("Users")
expect(result.text).to include("Logs") expect(result.text).to include("Logs")
expect(result.text).to include("Supported housing")
end
end
context "when production environment" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "doesn't render supported housing" do
result = render_inline(described_class.new(items:))
expect(result.text).not_to include("Supported housing")
end end
end end
end end

Loading…
Cancel
Save