Skip to content

Commit

Permalink
[Issue #2440] Update Header.tsx for index link (#2838)
Browse files Browse the repository at this point in the history
## Summary
Fixes #2440

### Time to review: __5 mins__

## Changes proposed
Add link to site name in the header. Removes link if you are on the
homepage.
  • Loading branch information
acouch authored Nov 18, 2024
1 parent 473ef79 commit d212acc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion frontend/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ const Header = ({ logoPath, locale }: Props) => {
setIsMobileNavExpanded(!isMobileNavExpanded);
};

const title =
usePathname() === "/" ? t("title") : <Link href="/">{t("title")}</Link>;

return (
<>
<div
Expand Down Expand Up @@ -140,7 +143,7 @@ const Header = ({ logoPath, locale }: Props) => {
/>
</span>
)}
<span className="font-sans-lg flex-fill">{t("title")}</span>
<span className="font-sans-lg flex-fill">{title}</span>
</div>
</Title>
<NavMenuButton
Expand Down
17 changes: 17 additions & 0 deletions frontend/tests/components/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,21 @@ describe("Header", () => {
expect(searchLink).toBeInTheDocument();
expect(searchLink).toHaveAttribute("href", "/search?refresh=true");
});

it("displays a home link if not on home page", () => {
render(<Header />);

const homeLink = screen.getByRole("link", { name: "Simpler.Grants.gov" });
expect(homeLink).toBeInTheDocument();
expect(homeLink).toHaveAttribute("href", "/");
});

it("display text without a home link if on home page", () => {
mockedPath = "/";
render(<Header />);

const homeText = screen.getByText("Simpler.Grants.gov");
expect(homeText).toBeInTheDocument();
expect(homeText).not.toHaveAttribute("href", "/");
});
});

0 comments on commit d212acc

Please sign in to comment.