From fc572dc9943df8430058d0ab3f9e36e84472ffb1 Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <davidsneighbourdev+gh@gmail.com>
Date: Thu, 19 Nov 2026 08:19:55 +0000
Subject: [PATCH] test(e2e): cover the menu button, hook slot, and navigation classes

---
 tests/fixtures/site/layouts/_partials/hooks/navigation-start.html |    5 +
 tests/e2e/navigation.spec.ts                                      |  100 ++++++++++++++++++++++++++++++++
 tests/e2e/accessibility.spec.ts                                   |   14 ++++
 tests/fixtures/site/hugo.toml                                     |    4 +
 4 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/tests/e2e/accessibility.spec.ts b/tests/e2e/accessibility.spec.ts
index a167a23..7dc4b0d 100644
--- a/tests/e2e/accessibility.spec.ts
+++ b/tests/e2e/accessibility.spec.ts
@@ -80,3 +80,17 @@
     });
   }
 }
+
+test("header with the open menu and an open submenu at 375px has no automatically detectable a11y violations", async ({
+  page,
+}) => {
+  await page.setViewportSize({ width: 375, height: 800 });
+  await page.goto("/");
+  await page.getByRole("button", { name: "Menu", exact: true }).click();
+  await page.getByRole("button", { name: "Topics" }).click();
+  const results = await new AxeBuilder({ page })
+    .include("header")
+    .withTags(TAGS)
+    .analyze();
+  expect(results.violations).toEqual([]);
+});
diff --git a/tests/e2e/navigation.spec.ts b/tests/e2e/navigation.spec.ts
index 6ea0cf2..eb41f84 100644
--- a/tests/e2e/navigation.spec.ts
+++ b/tests/e2e/navigation.spec.ts
@@ -18,6 +18,9 @@
   nav(page).getByRole("button", { name: "Topics" });
 const postsSubmenu = (page: Page) => page.locator("#ananke-submenu-0");
 const topicsSubmenu = (page: Page) => page.locator("#ananke-submenu-1");
+const menuButton = (page: Page) =>
+  nav(page).getByRole("button", { name: "Menu", exact: true });
+const panel = (page: Page) => page.locator("#ananke-nav-panel");
 
 test.describe("header submenus", () => {
   test("toggle buttons are revealed and submenus start closed", async ({
@@ -185,13 +188,15 @@
   });
 });
 
-for (const width of [320, 375, 768, 1280]) {
+for (const width of [320, 375, 768, 1024, 1280]) {
   for (const path of ["/", "/featured/"]) {
     test(`submenus stay in the viewport and above the header at ${width}px on ${path}`, async ({
       page,
     }) => {
       await page.setViewportSize({ width, height: 800 });
       await page.goto(path);
+      // Below 60em (960px) the menu is behind the menu button.
+      if (width < 960) await menuButton(page).click();
       for (const [toggle, submenu] of [
         [postsToggle(page), postsSubmenu(page)],
         [topicsToggle(page), topicsSubmenu(page)],
@@ -218,6 +223,93 @@
   }
 }
 
+test.describe("menu button below the large breakpoint", () => {
+  test.use({ viewport: { width: 375, height: 800 } });
+
+  test("collapses the menu behind the button", async ({ page }) => {
+    await page.goto("/");
+    await expect(menuButton(page)).toBeVisible();
+    await expect(menuButton(page)).toHaveAttribute("aria-expanded", "false");
+    await expect(menuButton(page)).toHaveAttribute(
+      "aria-controls",
+      "ananke-nav-panel",
+    );
+    await expect(panel(page)).toBeHidden();
+    // The brand link and the search slot stay visible.
+    await expect(
+      nav(page).getByRole("link", { name: "Ananke Test Fixture" }),
+    ).toBeVisible();
+    await expect(page.getByRole("searchbox", { name: "Search" })).toBeVisible();
+  });
+
+  test("opens and closes the menu", async ({ page }) => {
+    await page.goto("/");
+    await menuButton(page).click();
+    await expect(menuButton(page)).toHaveAttribute("aria-expanded", "true");
+    await expect(panel(page)).toBeVisible();
+    await expect(nav(page).getByRole("link", { name: "About" })).toBeVisible();
+    // Submenus open inline inside the panel.
+    await topicsToggle(page).click();
+    await expect(
+      topicsSubmenu(page).getByRole("link", { name: "Categories" }),
+    ).toBeVisible();
+    await menuButton(page).click();
+    await expect(menuButton(page)).toHaveAttribute("aria-expanded", "false");
+    await expect(panel(page)).toBeHidden();
+  });
+
+  test("closes on Escape and returns focus to the button", async ({ page }) => {
+    await page.goto("/");
+    await menuButton(page).focus();
+    await page.keyboard.press("Enter");
+    await expect(panel(page)).toBeVisible();
+    await page.keyboard.press("Tab");
+    await page.keyboard.press("Escape");
+    await expect(panel(page)).toBeHidden();
+    await expect(menuButton(page)).toBeFocused();
+  });
+
+  test("gives touch targets of at least 44px to submenu buttons", async ({
+    page,
+  }) => {
+    await page.goto("/");
+    await menuButton(page).click();
+    for (const toggle of [postsToggle(page), topicsToggle(page)]) {
+      const box = await toggle.boundingBox();
+      expect(box?.height ?? 0).toBeGreaterThanOrEqual(44);
+    }
+  });
+});
+
+test.describe("menu button on large screens", () => {
+  test("is hidden and the menu is visible", async ({ page }) => {
+    await page.goto("/");
+    await expect(menuButton(page)).toBeHidden();
+    await expect(panel(page)).toBeVisible();
+  });
+});
+
+test.describe("customisation", () => {
+  test("uses classes from [params.ananke.navigation.classes]", async ({
+    page,
+  }) => {
+    await page.goto("/");
+    // The fixture replaces the classes of the menu button.
+    await expect(page.locator(".ananke-nav-toggle")).toHaveClass(
+      /\bfixture-menu-button\b/,
+    );
+    // Other elements keep their default Tachyons classes.
+    await expect(page.locator(".ananke-nav-brand")).toHaveClass(/\bf3\b/);
+  });
+
+  test("renders the navigation-start hook in the slot", async ({ page }) => {
+    await page.goto("/");
+    await expect(
+      page.locator(".ananke-nav-slot").getByRole("search"),
+    ).toBeVisible();
+  });
+});
+
 test.describe("without JavaScript (progressive enhancement)", () => {
   test.use({ javaScriptEnabled: false });
 
@@ -241,9 +333,13 @@
     await expect(page.locator(".ananke-submenu-label")).toBeVisible();
   });
 
-  test("keeps child links reachable at a narrow width", async ({ page }) => {
+  test("keeps the menu and child links reachable at a narrow width", async ({
+    page,
+  }) => {
     await page.setViewportSize({ width: 320, height: 800 });
     await page.goto("/");
+    await expect(page.locator(".ananke-nav-toggle")).toBeHidden();
+    await expect(panel(page)).toBeVisible();
     const alpha = nav(page).getByRole("link", { name: "Alpha" });
     await expect(alpha).toBeVisible();
     const box = await alpha.boundingBox();
diff --git a/tests/fixtures/site/hugo.toml b/tests/fixtures/site/hugo.toml
index 09d5ed8..b44fd54 100644
--- a/tests/fixtures/site/hugo.toml
+++ b/tests/fixtures/site/hugo.toml
@@ -15,6 +15,10 @@
 show_categories = true
 copy_code = true
 
+# Replace the default classes of one navigation element (tests/e2e/navigation.spec.ts).
+[params.ananke.navigation.classes]
+toggle = "f5 white-90 hover-white fixture-menu-button"
+
 # Main menu with submenus (tests/e2e/navigation.spec.ts):
 #   Posts  - parent with its own page; children from config and front matter
 #   Topics - parent without a URL; Tags has a third-level child
diff --git a/tests/fixtures/site/layouts/_partials/hooks/navigation-start.html b/tests/fixtures/site/layouts/_partials/hooks/navigation-start.html
new file mode 100644
index 0000000..f327fb7
--- /dev/null
+++ b/tests/fixtures/site/layouts/_partials/hooks/navigation-start.html
@@ -0,0 +1,5 @@
+{{- /* Test fixture: a search form in the navigation-start hook slot. */ -}}
+<form class="fixture-search" role="search" action="{{ "posts/" | relURL }}">
+  <label class="clip" for="fixture-search-input">Search</label>
+  <input id="fixture-search-input" class="input-reset w-100 f6 pv2 ph3 br2 ba b--white-30 bg-white-10 white" type="search" name="q" placeholder="Search">
+</form>

--
Gitblit v1.10.0