From 4bd020fa169bf9fe6abc4130e3b04fcfc860c0e5 Mon Sep 17 00:00:00 2001 From: Marcel Raddatz Date: Thu, 2 Apr 2026 14:01:26 +0200 Subject: [PATCH] test(nav): add parameterized active-state tests for all routes Proves active state logic generalizes beyond /planner by testing all 4 mobile nav routes with writable page store. Co-Authored-By: Claude Sonnet 4.6 --- .../src/lib/nav/MobileTabBar.routes.test.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 frontend/src/lib/nav/MobileTabBar.routes.test.ts diff --git a/frontend/src/lib/nav/MobileTabBar.routes.test.ts b/frontend/src/lib/nav/MobileTabBar.routes.test.ts new file mode 100644 index 0000000..ef30c4d --- /dev/null +++ b/frontend/src/lib/nav/MobileTabBar.routes.test.ts @@ -0,0 +1,37 @@ +import { describe, it, expect, vi } from 'vitest'; +import { render, screen } from '@testing-library/svelte'; + +const { pageStore } = vi.hoisted(() => { + const { writable } = require('svelte/store'); + const pageStore = writable({ url: new URL('http://localhost/planner') }); + return { pageStore }; +}); + +vi.mock('$app/stores', () => ({ + page: pageStore +})); + +import MobileTabBar from './MobileTabBar.svelte'; + +describe('MobileTabBar active state per route', () => { + it.each([ + ['/planner', 'Planer'], + ['/recipes', 'Rezepte'], + ['/shopping', 'Einkauf'], + ['/settings', 'Einstellungen'] + ])('on %s, %s is active and others are not', (route, expectedActiveLabel) => { + pageStore.set({ url: new URL(`http://localhost${route}`) }); + const { unmount } = render(MobileTabBar); + + const activeLink = screen.getByRole('link', { name: expectedActiveLabel }); + expect(activeLink).toHaveAttribute('aria-current', 'page'); + + const allLinks = screen.getAllByRole('link'); + const inactiveLinks = allLinks.filter((link) => link.textContent?.trim() !== expectedActiveLabel); + for (const link of inactiveLinks) { + expect(link).not.toHaveAttribute('aria-current'); + } + + unmount(); + }); +});