Skip to content

Commit

Permalink
Set the current page as active
Browse files Browse the repository at this point in the history
This only has an affect on pages using the design system (which currently, is just the what's new page).

Adds some tests around the navigation links.
  • Loading branch information
mtaylorgds committed Jul 19, 2023
1 parent 424c651 commit 6ce678b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/helpers/navigation_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module NavigationHelper
def navigation_links_internal
[
{ text: "Manuals", href: manuals_path },
{ text: "What's new", href: whats_new_path },
{ text: "Manuals", href: manuals_path, active: request.path == manuals_path },
{ text: "What's new", href: whats_new_path, active: request.path == whats_new_path },
]
end

Expand Down
42 changes: 42 additions & 0 deletions spec/helpers/navigation_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "spec_helper"
describe NavigationHelper, type: :helper do
describe "#navigation_links_internal" do
it "returns a list of internal links" do
expect(navigation_links_internal).to be_an_instance_of(Array)
end

it "includes a link to manuals" do
expect(navigation_links_internal).to include(a_hash_including(text: "Manuals", href: manuals_path))
end

it "includes a link to what's new" do
expect(navigation_links_internal).to include(a_hash_including(text: "What's new", href: whats_new_path))
end

it "sets the link to the current page as active" do
request.path = manuals_path
expect(navigation_links_internal).to include(a_hash_including(text: "Manuals", active: true))
expect(navigation_links_internal).to include(a_hash_including(text: "What's new", active: false))
end
end

describe "#navigation_links_auth" do
let(:current_user) { User.create!(name: "John Doe") }

it "returns a list of auth links" do
expect(navigation_links_auth).to be_an_instance_of(Array)
end

it "includes a link to the user's profile" do
expect(navigation_links_auth).to include(
a_hash_including(text: "John Doe", href: Plek.external_url_for("signon")),
)
end

it "includes a link to sign out" do
expect(navigation_links_auth).to include(
a_hash_including(text: "Log out", href: gds_sign_out_path),
)
end
end
end

0 comments on commit 6ce678b

Please sign in to comment.