Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default function Navbar() {
<div
id={MOBILE_NAVIGATION_ID}
data-nojs-hide
className="sm:hidden px-4 pb-4 flex flex-col items-center space-y-4 text-sm font-medium bg-black/90 backdrop-blur-sm text-white"
className="sm:hidden px-4 pb-4 flex flex-col items-center space-y-4 text-sm font-medium text-white"
>
{navigationLinks.map((link) => (
<Link
Expand Down Expand Up @@ -219,7 +219,7 @@ export default function Navbar() {

<div
data-nojs-mobile-nav
className="hidden px-4 pb-4 flex-col items-center gap-4 text-sm font-medium bg-black/90 backdrop-blur-sm text-white"
className="hidden px-4 pb-4 flex-col items-center gap-4 text-sm font-medium text-white"
>
<div className="flex flex-wrap items-center justify-center gap-x-5 gap-y-3">
{navigationLinks.map((link) => (
Expand Down
82 changes: 82 additions & 0 deletions src/test/Navbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,65 @@ describe("Navbar mobile menu", () => {
expect(document.getElementById("mobile-navigation-panel")).not.toBeInTheDocument();
expect(localStorage.getItem("language")).toBe("en");
});

it.each([
{
language: "es",
expectedLabels: [
"Sobre mí",
"Por qué elegirme",
"Servicios",
"Portfolio",
"Contacto",
"FAQ",
],
servicesHref: "/servicios",
},
{
language: "en",
expectedLabels: [
"About me",
"Why choose me",
"Services",
"Portfolio",
"Contact",
"FAQ",
],
servicesHref: "/en/services",
},
] as const)(
"keeps $language desktop, mobile, and no-JavaScript navigation in parity",
async ({ language, expectedLabels, servicesHref }) => {
const user = userEvent.setup();
renderNavbar({ initialEntry: language === "es" ? "/" : "/en", language });

const desktop = getRequiredElement<HTMLElement>("[data-navbar-desktop]");
const trigger = screen.getByRole("button", {
name: language === "es" ? "Abrir menú" : "Open menu",
});
const fallback = getRequiredElement<HTMLElement>("[data-nojs-mobile-nav]");
const fallbackLinks = fallback.firstElementChild?.querySelectorAll("a");

await user.click(trigger);

const panel = getRequiredElement<HTMLElement>("#mobile-navigation-panel");
const desktopLinks = [...desktop.children].filter(
(element): element is HTMLAnchorElement =>
element instanceof HTMLAnchorElement,
);
const mobileLinks = [...panel.children].filter(
(element): element is HTMLAnchorElement =>
element instanceof HTMLAnchorElement,
);
const noJavaScriptLinks = [...(fallbackLinks ?? [])];

for (const links of [desktopLinks, mobileLinks, noJavaScriptLinks]) {
expect(links.map((link) => link.textContent)).toEqual(expectedLabels);
expect(links.filter((link) => link.getAttribute("href") === servicesHref))
.toHaveLength(1);
}
},
);
});

describe("Navbar color tokens", () => {
Expand Down Expand Up @@ -156,6 +215,29 @@ describe("Navbar color tokens", () => {
expect(spanishButton).toHaveClass("text-white", "hover:text-primary");
expect(englishButton).toHaveClass("text-primary", "hover:text-primary");
});

it("keeps one approved translucent surface around the mobile panels", async () => {
const user = userEvent.setup();
renderNavbar();
const navbar = getRequiredElement<HTMLElement>("nav[data-nojs-navbar]");
const trigger = screen.getByRole("button", { name: "Abrir menú" });
const fallback = getRequiredElement<HTMLElement>("[data-nojs-mobile-nav]");

expect(navbar).toHaveClass(
"bg-black/70",
"backdrop-blur-xl",
"backdrop-saturate-150",
);
expect(fallback.parentElement).toBe(navbar);
expect(fallback).not.toHaveClass("bg-black/90", "backdrop-blur-sm");

await user.click(trigger);

const panel = getRequiredElement<HTMLElement>("#mobile-navigation-panel");
expect(panel.parentElement).toBe(navbar);
expect(panel).not.toHaveClass("bg-black/90", "backdrop-blur-sm");
expect(navbar.querySelectorAll('[class*="backdrop-blur"]')).toHaveLength(0);
});
});

describe("Navbar no-JavaScript fallback", () => {
Expand Down
Loading