Files
mealprep/frontend/src/lib/nav/nav.test.ts
Marcel Raddatz bd8e901685 fix(nav): use segment-boundary route matching to prevent false positives
Extracts isActiveRoute() into shared nav module. Matches exact path
or path + '/' prefix, preventing /settings from matching /settings-advanced.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 14:00:18 +02:00

61 lines
1.9 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { mobileNavItems, desktopNavSections, isActiveRoute } from './nav';
describe('nav config', () => {
describe('mobileNavItems', () => {
it('has exactly 4 items', () => {
expect(mobileNavItems).toHaveLength(4);
});
it('contains Planner, Recipes, Shopping, Settings in order', () => {
const labels = mobileNavItems.map((item) => item.label);
expect(labels).toEqual(['Planer', 'Rezepte', 'Einkauf', 'Einstellungen']);
});
it('each item has href, label, and icon', () => {
for (const item of mobileNavItems) {
expect(item).toHaveProperty('href');
expect(item).toHaveProperty('label');
expect(item).toHaveProperty('icon');
expect(item.href).toMatch(/^\//);
}
});
});
describe('desktopNavSections', () => {
it('has 2 sections: Plan and Household', () => {
expect(desktopNavSections).toHaveLength(2);
expect(desktopNavSections[0].title).toBe('Plan');
expect(desktopNavSections[1].title).toBe('Haushalt');
});
it('Plan section has Planner, Recipes, Shopping', () => {
const labels = desktopNavSections[0].items.map((item) => item.label);
expect(labels).toEqual(['Planer', 'Rezepte', 'Einkauf']);
});
it('Household section has Members, Settings', () => {
const labels = desktopNavSections[1].items.map((item) => item.label);
expect(labels).toEqual(['Mitglieder', 'Einstellungen']);
});
});
describe('isActiveRoute', () => {
it('matches exact route', () => {
expect(isActiveRoute('/planner', '/planner')).toBe(true);
});
it('matches sub-route', () => {
expect(isActiveRoute('/planner', '/planner/week')).toBe(true);
});
it('does not match route with similar prefix', () => {
expect(isActiveRoute('/settings', '/settings-advanced')).toBe(false);
});
it('does not match unrelated route', () => {
expect(isActiveRoute('/planner', '/recipes')).toBe(false);
});
});
});