diff --git a/app/components/primary_navigation_component.html.erb b/app/components/primary_navigation_component.html.erb new file mode 100644 index 000000000..a0750d712 --- /dev/null +++ b/app/components/primary_navigation_component.html.erb @@ -0,0 +1,17 @@ + diff --git a/app/components/primary_navigation_component.rb b/app/components/primary_navigation_component.rb new file mode 100644 index 000000000..33f5a9529 --- /dev/null +++ b/app/components/primary_navigation_component.rb @@ -0,0 +1,8 @@ +class PrimaryNavigationComponent < ViewComponent::Base + attr_reader :items + + def initialize(items:) + @items = items + super + end +end diff --git a/app/views/layouts/_primary_navigation.html.erb b/app/views/layouts/_primary_navigation.html.erb deleted file mode 100644 index 0fd8529bd..000000000 --- a/app/views/layouts/_primary_navigation.html.erb +++ /dev/null @@ -1,18 +0,0 @@ - \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9cc24270d..ca0af4254 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -76,7 +76,7 @@ { name: "About your organisation", url: "/organisations/#{current_user.organisation.id}" }, ] %> <% end %> - <%= render partial: "layouts/primary_navigation", locals: {items: items} %> + <%= render PrimaryNavigationComponent.new(items:) %> <% end %>
diff --git a/spec/components/primary_navigation_component_spec.rb b/spec/components/primary_navigation_component_spec.rb new file mode 100644 index 000000000..c088df1e7 --- /dev/null +++ b/spec/components/primary_navigation_component_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe PrimaryNavigationComponent, type: :component do + let(:items) do + [{ name: "Organisations", url: "#", current: true }, + { name: "Users", url: "#" }, + { name: "Logs ", url: "#" }] + end + + context "when the item is 'current' in nav tabs" do + it "then that tab appears as selected" do + result = render_inline(described_class.new(items:)) + + expect(result.css('.app-primary-navigation__link[aria-current="page"]').text).to include("Organisations") + end + end + + context "when rendering tabs" do + it "all of the nav tabs specified in the items hash are passed to it" do + result = render_inline(described_class.new(items:)) + + expect(result.text).to include("Organisations") + expect(result.text).to include("Users") + expect(result.text).to include("Logs") + end + end +end